summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-10-20 00:04:27 +0100
committerDamien George <damien.p.george@gmail.com>2014-10-20 00:04:27 +0100
commit072bd07f178998f2c88cd2ceef86dea7902a1764 (patch)
tree841ed6802d8ff7d4bd47a25bd82f3f25f439e741
parent0c3955b5061816da3353df8e45175b0b56624f52 (diff)
downloadmicropython-072bd07f178998f2c88cd2ceef86dea7902a1764.tar.gz
micropython-072bd07f178998f2c88cd2ceef86dea7902a1764.zip
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.
-rw-r--r--stmhal/sdcard.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/stmhal/sdcard.c b/stmhal/sdcard.c
index a628d3e450..63a0bac96e 100644
--- a/stmhal/sdcard.c
+++ b/stmhal/sdcard.c
@@ -105,10 +105,13 @@ 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) {
- goto error;
+ 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