添加sdio驱动
文件系统挂载
This commit is contained in:
1 parent
e1d94985a4
commit
91c4751d7c
12 files changed
+361
-706
No files matched your search
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-07-29 andy the first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include "dfs_fs.h"
|
||||
|
||||
|
||||
#define DBG_TAG "mount_fs"
|
||||
#define DBG_LVL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
|
||||
rt_sem_t mount_sem = RT_NULL;
|
||||
|
||||
void sd_mount(void *parameter)
|
||||
{
|
||||
LOG_I("SD mount thread started, waiting for SD card...");
|
||||
int retry = 0;
|
||||
while (retry<10)
|
||||
{
|
||||
if (rt_device_find("sd") != RT_NULL)
|
||||
{
|
||||
if (dfs_mount("sd", "/", "elm", 0, NULL) == RT_EOK)
|
||||
{
|
||||
LOG_I("SD card mounted to '/' successfully");
|
||||
// 挂载成功,释放信号量
|
||||
if (mount_sem != RT_NULL)
|
||||
{
|
||||
rt_sem_release(mount_sem);
|
||||
}
|
||||
break; // 退出线程循环
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_W("SD card mount failed, retrying...");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_D("SD device 'sd' not found, retrying...");
|
||||
}
|
||||
|
||||
// 避免空转,延时 100ms 再试
|
||||
rt_thread_mdelay(500);
|
||||
retry++;
|
||||
}
|
||||
}
|
||||
|
||||
int stm32_sdcard_mount(void)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
rt_thread_mdelay(1000);
|
||||
// 删除旧的信号量(如果存在)
|
||||
if (mount_sem != RT_NULL)
|
||||
{
|
||||
rt_sem_delete(mount_sem);
|
||||
}
|
||||
|
||||
// 创建计数信号量,初始值为 0
|
||||
mount_sem = rt_sem_create("sd_mount", 0, RT_IPC_FLAG_FIFO);
|
||||
if (mount_sem == RT_NULL)
|
||||
{
|
||||
LOG_E("Failed to create semaphore for SD mount!");
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
tid = rt_thread_create("sd_mount",
|
||||
sd_mount,
|
||||
RT_NULL,
|
||||
1024*6, // 避免溢出
|
||||
RT_THREAD_PRIORITY_MAX - 2,
|
||||
20);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(tid);
|
||||
LOG_I("SD mount thread created and started");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("Failed to create SD mount thread!");
|
||||
rt_sem_delete(mount_sem);
|
||||
mount_sem = RT_NULL;
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
// 使用 INIT_COMPONENTS_INIT 或 INIT_APP_EXPORT 自动启动
|
||||
//INIT_COMPONENTS_INIT(stm32_sdcard_mount); // 在组件初始化阶段运行
|
||||
INIT_APP_EXPORT(stm32_sdcard_mount);
|
||||
@@ -15,8 +15,12 @@
|
||||
#define DBG_LVL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
|
||||
extern rt_sem_t mount_sem; // 引用上面SD挂载线程定义的信号量
|
||||
|
||||
int main(void)
|
||||
{
|
||||
rt_sem_take(mount_sem, rt_tick_from_millisecond(5000)); // 等待挂载完成,最多等待 5 秒
|
||||
rt_thread_mdelay(500);
|
||||
|
||||
thread_RUN_LED();//运行指示灯线程
|
||||
return RT_EOK;
|
||||
|
||||
Reference in new issue
Block a user