Skip to content
Snippets Groups Projects
Commit 072bd07f authored by Damien George's avatar Damien George
Browse files

stmhal: Add retry to SD card init.

This fixed an issue with a certain SD card sometimes not initialising
first time round.  See issue #822 for related, and thanks to
@iabdalkader for the idea.
parent 0c3955b5
No related branches found
No related tags found
No related merge requests found
......@@ -105,11 +105,14 @@ bool sdcard_power_on(void) {
sd_handle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
sd_handle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
// init the SD interface
// init the SD interface, with retry if it's not ready yet
HAL_SD_CardInfoTypedef cardinfo;
if (HAL_SD_Init(&sd_handle, &cardinfo) != SD_OK) {
for (int retry = 10; HAL_SD_Init(&sd_handle, &cardinfo) != SD_OK; retry--) {
if (retry == 0) {
goto error;
}
HAL_Delay(50);
}
// configure the SD bus width for wide operation
if (HAL_SD_WideBusOperation_Config(&sd_handle, SDIO_BUS_WIDE_4B) != SD_OK) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment