Skip to content

Commit e0e620d

Browse files
Fix: add sdcard detect before mount
Add sdcard detect before mount in case auto mount failed.
1 parent 14e64b3 commit e0e620d

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <dfs_romfs.h>
1616
#include <dfs_fs.h>
1717
#include <dfs_file.h>
18+
#include "drv_sdmmc.h"
1819

1920
#if DFS_FILESYSTEMS_MAX < 4
2021
#error "Please define DFS_FILESYSTEMS_MAX more than 4"
@@ -30,32 +31,27 @@
3031
#ifdef BSP_USING_SDCARD_FATFS
3132
static int onboard_sdcard_mount(void)
3233
{
33-
int retry_count = 0;
34-
const int max_retries = 10;
35-
const int retry_delay = 500;
34+
rt_device_t device;
3635

37-
for (retry_count = 0; retry_count < max_retries; retry_count++)
36+
device = rt_device_find("sd0");
37+
if (device == NULL)
3838
{
39-
if (rt_device_find("sd0") != RT_NULL)
39+
mmcsd_wait_cd_changed(0);
40+
stm32_mmcsd_change();
41+
mmcsd_wait_cd_changed(500);
42+
device = rt_device_find("sd0");
43+
}
44+
if (device != RT_NULL)
45+
{
46+
if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
4047
{
41-
if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
42-
{
43-
LOG_I("SD card mount to '/sdcard'");
44-
return RT_EOK;
45-
}
48+
LOG_I("SD card mount to '/sdcard'");
4649
}
47-
48-
/* retry after delay */
49-
rt_thread_mdelay(retry_delay);
50-
51-
if (retry_count == 0)
50+
else
5251
{
53-
LOG_I("Waiting for SD card initialization...");
52+
LOG_W("SD card mount to '/sdcard' failed!");
5453
}
5554
}
56-
57-
LOG_E("SD card mount to '/sdcard' failed after %d retries!", max_retries);
58-
return -RT_ERROR;
5955
}
6056
#endif /* BSP_USING_SDCARD_FATFS */
6157

0 commit comments

Comments
 (0)