Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
RT-Thread Studio
外部flash
文件系统
RT-Thread Studio使用记录(三)flash挂载文件系统
发布于 2021-01-28 23:04:23 浏览:5346
订阅该版
[RT-Thread Studio使用记录(一)点亮led](https://club.rt-thread.org/ask/article/2519.html) [RT-Thread Studio使用记录(二)pwm呼吸灯](https://club.rt-thread.org/ask/article/2520.html) [RT-Thread Studio使用记录(三)flash挂载文件系统](https://club.rt-thread.org/ask/article/2521.html) [RT-Thread Studio使用记录(四)SD-Card 挂载文件系统](https://club.rt-thread.org/ask/article/2526.html) [RT-Thread Studio使用记录(五)USB 虚拟串口](https://club.rt-thread.org/ask/article/2524.html) [RT-Thread Studio使用记录(六)ESP8266网络设备](https://club.rt-thread.org/ask/article/2527.html) [RT-Thread Studio使用记录(七)STemWin](https://club.rt-thread.org/ask/article/2529.html) [RT-Thread Studio使用记录(八)LittlevGL2RTT](https://club.rt-thread.org/ask/article/2530.html) [RT-Thread Studio使用记录(九)LittlevGL2RTT触摸屏](https://club.rt-thread.org/ask/article/2531.html) [RT-Thread Studio使用记录(十)LittlevGL2RTT 贪吃蛇](https://club.rt-thread.org/ask/article/2534.html) [RT-Thread Studio使用记录(十一)LittlevGL2RTT 贪吃蛇+俄罗斯方块](https://club.rt-thread.org/ask/article/2544.html) 本章使用 RT-Thread 的 flash 驱动框架, 在 W25Q64 上挂载 fatfs 文件系统 。 1、打开 RT-Thread Settings, 使能 spi 驱动,保存。 ![rt-setting.png](https://oss-club.rt-thread.org/uploads/20210128/35dcf0a95045a7ccfb25f8111384e28c.png) ![资源管理器.png](https://oss-club.rt-thread.org/uploads/20210128/c802ab3907d22ef0708ad7fdee926e72.png) 2、修改 board.h 添加 BSP_USING_SPI2 的宏定义。 ![board.png](https://oss-club.rt-thread.org/uploads/20210128/2cbd8c8b7e645e74e764d79ed6e79563.png) 3、打开 CubeMX 配置文件,配置 SPI2 选项。由于 CubeMX 默认的 SPI2 引脚为 B10 / C2 / C3,而原理图设计时选用的是 B13 / B14 / B15 ,所以更改 SPI2 的 GPIO 设置,生成代码。配置如下: ![原理图.png](https://oss-club.rt-thread.org/uploads/20210128/2d3cdbce6b121ddc991b234cc33f46bf.png) ![cube-config.png](https://oss-club.rt-thread.org/uploads/20210128/4dcfc317a67d3867ee855281f5989d58.png) 4、打开 SPI 模块使能。此处用的 stm32f4xx_hal_conf.h 文件是在 drivers 文件夹中,不是上一步生成的那个。 ![hal-config.png](https://oss-club.rt-thread.org/uploads/20210128/304c6ce3c0a613cf6cf2029d56703287.png) 5、编译程序并下载,此时 spi 驱动已添加完成。 ![效果1.png](https://oss-club.rt-thread.org/uploads/20210128/1c20ed3c5f844394c865aacff95186e7.png) 6、参考 [spi_flash_init.c](https://github.com/RT-Thread/rt-thread/blob/master/bsp/stm32/stm32f407-atk-explorer/board/ports/spi_flash_init.c),将 flash 挂载到 SPI2 上,命名为 W25Q64,并设置自动初始化。 ``` #include
#include "spi_flash.h" #include "spi_flash_sfud.h" #include "drv_spi.h" #if defined(RT_USING_SFUD) static int rt_hw_spi_flash_init(void) { // __HAL_RCC_GPIOB_CLK_ENABLE(); rt_hw_spi_device_attach("spi2", "spi20", GPIOB, GPIO_PIN_12); if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi20")) { return -RT_ERROR; }; return RT_EOK; } INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init); #endif ``` 7、再次编译下载程序。此时 spi flash 设备已挂载成功,使用 sf 命令简单测试读写功能。 ![串口测试功能.png](https://oss-club.rt-thread.org/uploads/20210128/35a98cd922593234b7c0200503dad651.png) 8、打开 RT-Thread Settings ,启用 设备虚拟文件系统,将 “挂载文件系统的最大数目” 及 “文件系统类型的最大数目” 设置为4,方便后续挂载多个文件设备。启用 elm chan FatFs。使能 “在 Flash 上使能只读文件系统”,可设置多个文件目录用于后续挂载。 ![rt-setting2.png](https://oss-club.rt-thread.org/uploads/20210128/5ec6a7bc1ba1cbc0bc5667a08c911109.png) 9、参考较早版本中的 /bspstm32f429-apollo/applications/application.c ``` /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2009-01-05 Bernard the first version * 2014-04-27 Bernard make code cleanup. */ #include
#include
#include
#include "finsh.h" #include "time.h" #ifdef RT_USING_DFS /* dfs init */ /* dfs filesystem:ELM filesystem init */ #include
/* dfs Filesystem APIs */ #include
#include
#include
#endif #ifdef RT_USING_LWIP #include
#include
#include
#include "drv_eth.h" #endif #ifdef RT_USING_GDB #include
#endif #ifdef PKG_USING_GUIENGINE #include "rtgui_demo.h" #include
#endif void rt_init_thread_entry(void* parameter) { /* initialization RT-Thread Components */ #ifdef RT_USING_COMPONENTS_INIT rt_components_init(); #endif /* GDB STUB */ #ifdef RT_USING_GDB gdb_set_device("uart6"); gdb_start(); #endif #ifdef RT_USING_DFS #ifdef RT_USING_DFS_ELMFAT { static const rt_uint8_t _romfs_root_readme_txt[] = { 0x52,0x54,0x2d,0x54,0x68,0x72,0x65,0x61,0x64,0x0d,0x0a,0x00 }; static const rt_uint8_t _romfs_root_sdcard_aaa_txt[] = { 0x52,0x54,0x2d,0x54,0x68,0x72,0x65,0x61,0x64,0x0d,0x0a,0x00 }; static const struct romfs_dirent _romfs_root_sdcard[] = { {ROMFS_DIRENT_FILE, "aaa.txt", (rt_uint8_t *)_romfs_root_sdcard_aaa_txt, sizeof(_romfs_root_sdcard_aaa_txt)/sizeof(_romfs_root_sdcard_aaa_txt[0])} }; static const rt_uint8_t _romfs_root_spi_bbb_txt[] = { 0x52,0x54,0x2d,0x54,0x68,0x72,0x65,0x61,0x64,0x0d,0x0a,0x00 }; static const struct romfs_dirent _romfs_root_spi[] = { {ROMFS_DIRENT_FILE, "bbb.txt", (rt_uint8_t *)_romfs_root_spi_bbb_txt, sizeof(_romfs_root_spi_bbb_txt)/sizeof(_romfs_root_spi_bbb_txt[0])} }; static const struct romfs_dirent _romfs_root[] = { {ROMFS_DIRENT_FILE, "readme.txt", (rt_uint8_t *)_romfs_root_readme_txt, sizeof(_romfs_root_readme_txt)/sizeof(_romfs_root_readme_txt[0])}, {ROMFS_DIRENT_DIR, "sdcard", (rt_uint8_t *)_romfs_root_sdcard, sizeof(_romfs_root_sdcard)/sizeof(_romfs_root_sdcard[0])}, {ROMFS_DIRENT_DIR, "spi", (rt_uint8_t *)_romfs_root_spi, sizeof(_romfs_root_spi)/sizeof(_romfs_root_spi[0])} }; static const struct romfs_dirent romfs_root = { ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root)/sizeof(_romfs_root[0]) }; if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0) { rt_kprintf("ROM file system initializated!\n"); } } /* mount sd card fat partition 0 as root directory */ if (dfs_mount("W25Q256", "/spi", "elm", 0, 0) == 0) { rt_kprintf("spi flash mount to /spi !\n"); } else { rt_kprintf("spi flash mount to /spi failed!\n"); } /* mount sd card fat partition 0 as root directory */ if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == 0) { rt_kprintf("sd card mount to /sdcard!\n"); } else { rt_kprintf("sd card mount to /sdcard failed!\n"); } #endif /* RT_USING_DFS_ELMFAT */ #endif /* DFS */ #ifdef PKG_USING_GUIENGINE { rt_device_t device; device = rt_device_find("lcd"); /* re-set graphic device */ rtgui_graphic_set_device(device); rt_gui_demo_init(); } #endif } int rt_application_init() { rt_thread_t tid; tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, 2048, RT_THREAD_PRIORITY_MAX/3, 20); if (tid != RT_NULL) rt_thread_startup(tid); return 0; } ``` 制作新的挂载程序,此方法可在 "/" 目录下新建挂载目录,以分别挂载 spi flash 及 SD Card 。 ``` #include
#ifdef RT_USING_DFS #include
#include
int mnt_init(void) { // dfs_mkfs("elm","W25Q64"); //首次挂载前,先格式化 static const rt_uint8_t _romfs_root_readme_txt[] = { 0x52,0x54,0x2d,0x54,0x68,0x72,0x65,0x61,0x64,0x0d,0x0a,0x00 }; static const rt_uint8_t _romfs_root_sdcard_aaa_txt[] = { 0x52,0x54,0x2d,0x54,0x68,0x72,0x65,0x61,0x64,0x0d,0x0a,0x00 }; static const struct romfs_dirent _romfs_root_sdcard[] = { {ROMFS_DIRENT_FILE, "aaa.txt", (rt_uint8_t *)_romfs_root_sdcard_aaa_txt, sizeof(_romfs_root_sdcard_aaa_txt)/sizeof(_romfs_root_sdcard_aaa_txt[0])} }; static const rt_uint8_t _romfs_root_spi_bbb_txt[] = { 0x52,0x54,0x2d,0x54,0x68,0x72,0x65,0x61,0x64,0x0d,0x0a,0x00 }; static const struct romfs_dirent _romfs_root_spi[] = { {ROMFS_DIRENT_FILE, "bbb.txt", (rt_uint8_t *)_romfs_root_spi_bbb_txt, sizeof(_romfs_root_spi_bbb_txt)/sizeof(_romfs_root_spi_bbb_txt[0])} }; static const struct romfs_dirent _romfs_root[] = { {ROMFS_DIRENT_FILE, "readme.txt", (rt_uint8_t *)_romfs_root_readme_txt, sizeof(_romfs_root_readme_txt)/sizeof(_romfs_root_readme_txt[0])}, {ROMFS_DIRENT_DIR, "sdcard", (rt_uint8_t *)_romfs_root_sdcard, sizeof(_romfs_root_sdcard)/sizeof(_romfs_root_sdcard[0])}, {ROMFS_DIRENT_DIR, "spi", (rt_uint8_t *)_romfs_root_spi, sizeof(_romfs_root_spi)/sizeof(_romfs_root_spi[0])} }; static const struct romfs_dirent romfs_root = { ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root)/sizeof(_romfs_root[0]) }; if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) == 0) { rt_kprintf("ROM file system initializated!\n"); } if (dfs_mount("W25Q64", "/spi", "elm", 0, 0) == 0) { rt_kprintf("W25Q64 mount successful!\n"); } else { rt_kprintf("W25Q64 mount failed!\n"); } return 0; } INIT_APP_EXPORT(mnt_init); #endif ``` 10、再次编译下载。此时已完成 spi flash 挂载文件系统的全部流程。 ![效果2.png](https://oss-club.rt-thread.org/uploads/20210128/29eefd33f14d2fa12c17babe4e42a4fb.png)
7
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
mgcheng
这家伙很懒,什么也没写!
文章
12
回答
2
被采纳
0
关注TA
发私信
相关文章
1
rt_thread studio 啥时候能用呢
2
RT_Thread使用反馈帖子
3
RTT studio 下的 AT指令问题。
4
什么时候RTT Sdudio支持Ubuntu,Deepin和UOS操作系统
5
rt thread Studio 关于J-LINK下载问题
6
RT-Thread studio 调试设置问题
7
RTT-Studio 如何设置调试配置参数?
8
rt_thread studio 软件包配置
9
RT-Studio目前只能开发STM32的项目吗?
10
rtt studio 生成hex名字修改
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
PWM
cubemx
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
6
次点赞
YZRD
1
篇文章
2
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部