Improve SDIO handling

This commit is contained in:
2020-08-17 22:10:04 +02:00
parent 543127b187
commit 4e9b28ce15
5 changed files with 60 additions and 14 deletions

View File

@@ -115,13 +115,20 @@ static inline void setup_shell_uart(struct stm_uart *uart)
static bool mount_sd_card_if_avail(bool mounted)
{
FRESULT res;
static uint8_t inserted_counter = 0;
if (sdio_check_inserted() && mounted) {
memset(fs_ptr, 0, sizeof(FATFS));
sdio_stop_clk();
inserted_counter = 0;
return false;
}
if (!sdio_check_inserted() && !mounted) {
if (!sdio_check_inserted() && inserted_counter < 255)
inserted_counter++;
if (!sdio_check_inserted() && !mounted && inserted_counter > 4) {
inserted_counter = 0;
res = f_mount(fs_ptr, "0:/", 1);
if (res == FR_OK)
return true;