当前位置:网站首页>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 
边栏推荐
- 五、EL 表达式& JSTL 标签库
- NOI openjudge 计算2的N次方
- The second day of June training - string
- 【图像去噪】基于高斯滤波、均值滤波、中值滤波、双边滤波四种滤波实现椒盐噪声图像去噪附matlab代码
- (14) The software version number is displayed in the flash window of blender source code analysis
- Expansion of D @nogc
- 库里扛起了勇士对凯尔特人的第四场
- 报表工具的二次革命
- 六月集训 第二天——字符串
- [image denoising] salt and pepper noise image denoising based on Gaussian filter, mean filter, median filter and bilateral filter with matlab code attached
猜你喜欢
随机推荐
libprint2
leetcode:剑指 Offer 67. 把字符串转换成整数【模拟 + 分割 +讨论】
The fifth day of June training - double pointer
node:打不开/node:已拒绝访问
上位机开发(固件下载软件之需求分析)
Dépannage de l'opération cl210openstack - chapitre expérience
Oracle Database
Go common usage
[Li Kou] curriculum series
企业微信官方 加解密库 PHP7版本报错 mcrypt_module_open 未定义方法 并且被PHP抛弃 解决方法使用 openssl解决
Torch models trained in higher versions report errors in lower versions
NOI openjudge 计算2的N次方
When SQL server2019 is installed, the next step cannot be performed. How to solve this problem?
Zhang Chi: is process a panacea?
[image denoising] image denoising based on nonlocal Euclidean median (nlem) with matlab code
SSM integration
Node. Detailed installation tutorial of CPM and cnpm (including error resolution)
循环链表和双向链表—课上课后练
JDE 对象管理工作平台介绍及 From 的使用
SQL language








