Skip to content

Commit 072bd07

Browse files
committed
stmhal: Add retry to SD card init.
This fixed an issue with a certain SD card sometimes not initialising first time round. See issue adafruit#822 for related, and thanks to @iabdalkader for the idea.
1 parent 0c3955b commit 072bd07

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

stmhal/sdcard.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ bool sdcard_power_on(void) {
105105
sd_handle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
106106
sd_handle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
107107

108-
// init the SD interface
108+
// init the SD interface, with retry if it's not ready yet
109109
HAL_SD_CardInfoTypedef cardinfo;
110-
if (HAL_SD_Init(&sd_handle, &cardinfo) != SD_OK) {
111-
goto error;
110+
for (int retry = 10; HAL_SD_Init(&sd_handle, &cardinfo) != SD_OK; retry--) {
111+
if (retry == 0) {
112+
goto error;
113+
}
114+
HAL_Delay(50);
112115
}
113116

114117
// configure the SD bus width for wide operation

0 commit comments

Comments
 (0)