HAL_ChibiOS: added 3 tries to microSD MMC init

this makes init for MMC/SPI interfaces more reliable
This commit is contained in:
Andrew Tridgell 2018-11-29 19:04:05 +11:00
parent 6a27e8585a
commit 8f51bef0f0
1 changed files with 16 additions and 2 deletions

View File

@ -78,9 +78,23 @@ void sdcard_init()
mmcconfig.hscfg = &highspeed;
mmcconfig.lscfg = &lowspeed;
mmcStart(&MMCD1, &mmcconfig);
/*
try up to 3 times to init microSD interface
*/
const uint8_t tries = 3;
bool start_ok = false;
for (uint8_t i=0; i<tries; i++) {
mmcStart(&MMCD1, &mmcconfig);
if (mmcConnect(&MMCD1) == HAL_FAILED) {
if (mmcConnect(&MMCD1) != HAL_FAILED) {
start_ok = true;
break;
}
mmcStop(&MMCD1);
hal.scheduler->delay(100);
}
if (!start_ok) {
printf("Err: Failed to initialize SDCARD_SPI!\n");
sdcard_running = false;
} else {