Skip to content

Commit

Permalink
More bugfixes for the SD card. It was failing to mount with the delay…
Browse files Browse the repository at this point in the history
…s given
  • Loading branch information
danieldegrasse committed Aug 13, 2020
1 parent 37bb1be commit 0d6a0ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
32 changes: 9 additions & 23 deletions sd_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,33 +86,19 @@ bool attempt_sd_mount(void) {
return SD_CARD_MOUNTED;
}
/**
* The power toggle sequence below is required because the MCU will reset
* if the SD card is plugged in while power is supplied to the SD card.
* Therefore, we keep the power to the card disabled until a mount of it
* is requested. The power off here is precautionary, the SD card should
* not be powered at this point.
*
* The SD Card needs to be aware of the SPI signal before it is powered.
* If the SPI bus has not been setup, it will not be and the MCU will
* reset.
*
* Delay for 1000ms to let the SD card see the bus.
* Don't shorten this delay, I tried and the card needs time to *think*
*/
// Power off the SD card by disabling the VCC pin.
GPIO_write(Board_SDCARD_VCC, Board_LED_OFF);
// Power up the SD card
GPIO_write(Board_SDCARD_VCC, Board_LED_ON);
/* Try to mount the SD card. */
SDSPI_Params_init(&sdspi_params);
SDSPI_HANDLE = SDSPI_open(Board_SDSPI0, DRIVE_NUM, &sdspi_params);
if (FIRST_INIT) {
/**
* FIRST_INIT tracks if the SPI Bus has been setup for the SD card.
*
* The SD Card needs to be aware of the SPI signal before it is powered.
* If the SPI bus has not been setup, it will not be and the MCU will
* reset.
*
* Delay for 1000ms to let the SD card see the bus.
* Don't shorten this delay, I tried and the card needs time to *think*
*/
Task_sleep(1000);
FIRST_INIT = false;
}
// Now power up the SD card again.
GPIO_write(Board_SDCARD_VCC, Board_LED_ON);
if (SDSPI_HANDLE == NULL) {
System_abort("Error starting the SD card\n");
} else {
Expand Down
9 changes: 7 additions & 2 deletions uart_logger_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file uart_logger.c
* Implements the task responsible for reading data from a UART, and writing it
* to an SD card log file.
*
*
* Pins Required:
* PC6- UART RX
* PC7- UART TX
Expand Down Expand Up @@ -40,7 +40,7 @@ static UART_Params params;
*/
void uart_logger_prebios(void) {
/*
* UART defaults to text mode, echo back characters, and return from read
* UART defaults to text mode, echo back characters, and return from read
* after newline. Default 8 bits, one stop bit, no parity.
*/
UART_Params_init(&params);
Expand All @@ -66,6 +66,11 @@ void uart_logger_prebios(void) {
*/
void uart_logger_task_entry(UArg arg0, UArg arg1) {
char read_buf[READSIZE];
/**
* Sleep for 100 ms. For some reason, the MCU resets if the SD card is
* powered up too soon.
*/
Task_sleep(100);
/*
* Try to mount the SD card, and if it fails wait for the sd_ready
* condition.
Expand Down

0 comments on commit 0d6a0ac

Please sign in to comment.