当前位置:网站首页>RT thread studio learning (IX) TF Card File System
RT thread studio learning (IX) TF Card File System
2022-06-12 07:03:00 【iqiaoqiao】
RT-Thread Studio Study ( Nine )TF Card file system
brief introduction
This article will be based on STM32F407VET How to introduce the chip RT-Thread Studio Use... In a development environment SD Card driver package .
newly build RT-Thread Project and use external clock
Reference documents for detailed steps 《RT-Thread Studio Learning to use an external clock system 》.
Just because drv_clk.c External functions are used in the file SystemClock_Config, as follows :
void clk_init(char *clk_source, int source_freq, int target_freq)
{
/* * Use SystemClock_Config generated from STM32CubeMX for clock init * system_clock_config(target_freq); */
extern void SystemClock_Config(void);
SystemClock_Config();
}
therefore , There is no need to STM32CubeMX In the project main.c Function of SystemClock_Config() Copy content to RT-Thread Studio In the project drv_clk.c The system clock configuration function in the file system_clock_config.
Set up SDIO The driver framework of
1、STM32CubeMX Set up
stay CubeMX Configure... In the software TF Card pin , Here's the picture 
Can make SDIO,Mode choice SD 4 bits Wide bus, Click again GENERATE CODE The generated code .
2、RT-Thread Studio Set up
Enable the following components :
Make the following settings in the detailed settings :

board.h Enable in file SDIO:
test
modify main.c file , The code is as follows :
/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2021-06-10 RT-Thread first version */
#include <rtthread.h>
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#include <rtdevice.h>
#include <board.h>
#include <stdio.h>
#include <string.h>
#include "dfs_posix.h"
static void sd_init(void)
{
rt_device_t name_sd0_t=RT_NULL;
int count=10;
while(name_sd0_t==RT_NULL) // wait for sd Card registration
{
if((count--)==0)
{
LOG_E("find sd0 failed\r\n");
break;
}
rt_thread_mdelay(500);
name_sd0_t=rt_device_find("sd0");
}
if(name_sd0_t!=RT_NULL) //sd Successfully registered to the system
{
LOG_D("find sd0 success\r\n");
if(dfs_mount("sd0", "/", "elm", 0, 0)==0) // take sd Mount to the root
{
LOG_D("dfs mount sd0 success\r\n");
}
else
{
LOG_E("dfs mount sd0 failed\r\n");
}
}
}
void sd_rw(void)
{
char wbuf[] = "hello world!", rbuf[30] = {
0};
int rsize = 0;
int fd = 0; // File descriptor
// Write data
fd = open("/a.txt", O_WRONLY | O_CREAT); // Open file , If it doesn't exist, create a new one
if(fd>0)
{
write(fd, wbuf, sizeof(wbuf));
close(fd);
rt_kprintf("write success\r\n");
}
// Reading data
fd = open("/a.txt", O_RDONLY); // Open in read-only format
if(fd>0)
{
rsize = read(fd, rbuf, 100);
close(fd);
if(rsize>0)
{
rt_kprintf("READ(%d): %s",rsize,rbuf);
}
}
}
int main(void)
{
int count = 1;
sd_rw();
while (count++)
{
if(count<10)
LOG_D("Hello RT-Thread!");
rt_thread_mdelay(1000);
}
return RT_EOK;
}
INIT_COMPONENT_EXPORT(sd_init);
After compiling and downloading, the result is 
边栏推荐
- 初中学历,从不到3K,到月薪30K+,不设限的人生有多精彩
- Tomato learning notes -vscade configuring makefile (using task.jason and launch.jason)
- 企业微信官方 加解密库 PHP7版本报错 mcrypt_module_open 未定义方法 并且被PHP抛弃 解决方法使用 openssl解决
- (14)Blender源码分析之闪屏窗口显示软件版本号
- 六月集训 第一日——数组
- I met 15 people recently and found that I couldn't answer the basic question of this test
- Curry carries the fourth game of the warriors against the Celtics
- Troubleshooting of cl210openstack operation -- Chapter experiment
- Cron expression and website generation
- (14) The software version number is displayed in the flash window of blender source code analysis
猜你喜欢
随机推荐
【图像去噪】基于非局部欧几里德中值 (NLEM) 实现图像去噪附matlab代码
Oracle Database
六月集训 第五天——双指针
SSM integration
Zhang Chi's class: Notice on the time of CAQ Six Sigma test in 2022
Node. Detailed installation tutorial of CPM and cnpm (including error resolution)
五月集训(第28天)——动态规划
Recommend 17 "wheels" to improve development efficiency
Cron expression and website generation
[image detection] SAR image change detection based on depth difference and pcanet with matlab code
Install MySQL tutorial
leetcode:890. 查找和替换模式【两个dict记录双射(set)】
d的自动无垃集代码.
Codeforces Round #793 (Div. 2) A B C
库里扛起了勇士对凯尔特人的第四场
I met 15 people recently and found that I couldn't answer the basic question of this test
Lambda function perfect use guide
MySQL group query to obtain the latest data date function of each group
libprint2
leetcode:剑指 Offer 63. 股票的最大利润【记录前缀最小和 or 无脑线段树】









