Fix: add sdcard detect before mount

Add sdcard detect before mount in case auto mount failed.
This commit is contained in:
Eric Chan
2026-01-12 13:37:28 +08:00
committed by R b b666
parent 6c2b9a8f20
commit 8dc7db90b2

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2026, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -8,12 +8,14 @@
* 2018-12-13 balanceTWK add sdcard port file
* 2021-05-10 Meco Man fix a bug that cannot use fatfs in the main thread at starting up
* 2021-07-28 Meco Man implement romfs as the root filesystem
* 2026-01-13 LinuxMint-User add sdcard detect before mount in case auto mount failed
*/
#include <rtthread.h>
#include <dfs_romfs.h>
#include <dfs_fs.h>
#include <dfs_file.h>
#include "drv_sdmmc.h"
#if DFS_FILESYSTEMS_MAX < 4
#error "Please define DFS_FILESYSTEMS_MAX more than 4"
@@ -28,6 +30,19 @@
#ifdef BSP_USING_SDCARD_FATFS
static int onboard_sdcard_mount(void)
{
rt_device_t device;
device = rt_device_find("sd0");
if (device == NULL)
{
mmcsd_wait_cd_changed(0);
stm32_mmcsd_change();
mmcsd_wait_cd_changed(rt_tick_from_millisecond(500));
device = rt_device_find("sd0");
}
if (device != RT_NULL)
{
if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
{
@@ -35,9 +50,9 @@ static int onboard_sdcard_mount(void)
}
else
{
LOG_E("SD card mount to '/sdcard' failed!");
LOG_W("SD card mount to '/sdcard' failed!");
}
}
return RT_EOK;
}
#endif /* BSP_USING_SDCARD_FATFS */
@@ -112,3 +127,4 @@ static int filesystem_mount(void)
return RT_EOK;
}
INIT_APP_EXPORT(filesystem_mount);