当前位置:网站首页>RT thread learning notes (VI) -- start the elmfat file system based on SPI flash (Part 1)
RT thread learning notes (VI) -- start the elmfat file system based on SPI flash (Part 1)
2022-07-26 10:43:00 【aping_ cs_ dn】
Software environment :Win7,Keil MDK 4.72a, IAR EWARM 7.2, GCC 4.2,Python 2.7 ,SCons 2.3.2
Hardware environment :Armfly STM32F103ZE-EK v3.0 Development board
Reference article :RT-Thread Programming Guide
[RTthread] The new version RTT Medium SPI Drive frame
Github managed Realtouch In the branch examples Directory spi flash Routine for
stay RT-Thread The default is SD The card is mounted as a file system , You need to add relevant driver files , The operation is as follows :
【1】 Join in SPI Bus driver
stay stm32f107 The branch driver Directory is platform.c Platform initialization file 、rt_stm32f10x_spi.c and rt_stm32f10x_spi.h Two spi Bus driver file , Copy them to stm32f103ze-ek The branch driver in , And will platform.c Rename to rt_spi_flash_device.c give the result as follows :

【2】 Join in SPI Flash Device drivers
stay RT-Thread Official Git There are open source projects in the managed Library realtouch-stm32, stay driver There is... Under the catalog SPI Flash Driver file spi_flash_w25xx.c and spi_flash_w25xx.h Two documents , Copy them to stm32f103ze-ek The branch driver in , give the result as follows :

So here we are stm32f103ze-ek Add... To the branch SPI Flash Related drive .
【3】 take SPI Flash Add files to the project
open KeilMDK, Click on the project management tree on the left driver Branch , Then right click as shown in the figure below "Add Existing Fils to..." Button .

location stm32f103ze-ek/drive Catalog , Select the file just copied above , Here's the picture :

And then click "Add" Button , Finish adding , Click on “close” Button close dialog .
Use the same method in rt-thread-1.2.2\components\drivers\spi Found in the directory spi_core.c,spi_dev.c Two files are added to the project DeviceDrivers In the group , give the result as follows :

【4】 open rtconfig.h The configuration file , Open file DFS System support options , Locate the 83 Near the line , Revised as follows :
/* SECTION: device filesystem */
#define RT_USING_SPI
#define RT_USING_SPI_FLASH
#define RT_USING_DFS
#define RT_USING_DFS_ELMFAT
#define RT_DFS_ELM_WORD_ACCESS
/* Reentrancy (thread safe) of the FatFs module. */
#define RT_DFS_ELM_REENTRANT
/* Number of volumes (logical drives) to be used. */
#define RT_DFS_ELM_DRIVES2
/* #define RT_DFS_ELM_USE_LFN1 */
/* #define RT_DFS_ELM_CODE_PAGE936 */
#define RT_DFS_ELM_MAX_LFN255
/* Maximum sector size to be handled. */
#define RT_DFS_ELM_MAX_SECTOR_SIZE 4096 /*SPI Flash Sector size*/
/* the max number of mounted filesystem */
#define DFS_FILESYSTEMS_MAX2
/* the max number of opened files */
#define DFS_FD_MAX
Save after modification .
【5】 modify application.c
open application.c, Locate the 45 Near the line , Add the following code :
extern void rt_spi_flash_device_init(void);
open application.c, Locate the 101 Near the line , Add the following code :
rt_spi_flash_device_init();
#ifdef RT_USING_FINSH
finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif /* RT_USING_FINSH */
/* Filesystem Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
/* mount SPI flash as root directory */
if (dfs_mount("flash0", "/", "elm", 0, 0) == 0)
{
rt_kprintf("flash0 mount to /.\n");
}
else
rt_kprintf("flash0 mount to / failed.\n");
#endif /* RT_USING_DFS */
... ...
#ifdef RT_USING_RTGUI
{
extern void rt_hw_lcd_init();
extern void rtgui_touch_hw_init(void);
rt_device_t lcd;
/* init lcd */
rt_hw_lcd_init();
#ifdef RTGUI_USING_TOUCHPANEL
/* initilize touch panel */
rtgui_touch_hw_init("spi12");
#endif /* RTGUI_USING_TOUCHPANEL */
/* find lcd device */
lcd = rt_device_find("lcd");
/* set lcd device as rtgui graphic driver */
rtgui_graphic_set_device(lcd);
#ifndef RT_USING_COMPONENTS_INIT
/* init rtgui system server */
rtgui_system_server_init();
#endif /*RT_USING_COMPONENTS_INIT*/
#ifdef RTGUI_USING_CALIBRATION
calibration_set_restore(cali_setup);
calibration_set_after(cali_store);
calibration_init();
#endif /* #ifdef RTGUI_USING_CALIBRATION */
}
#endif /* RT_USING_RTGUI */
#ifdef RT_USING_USB_HOST
/* register stm32 usb host controller driver */
rt_hw_susb_init();
#endif
rt_thread_delay(50);
rt_device_init_all();
}
... ...
Save after modification .
【6】 open rt_spi_flash_device.c, See about spi The underlying initialization code , At this time, refer to the schematic diagram of the development board , You can see STM32F103ZE-EK The development board uses SPI Flash The chip model is SST25VF016B, and CPU The schematic diagram of connecting pins is as follows :

It can be seen that , On the schematic diagram SPI Flash The pins used are PA6(MISO),PA7(MOSI),PA5(SCK), Its The chip selection signal is PB2 Pin , Also use SPI1 Bus is LCD LCD touch screen chip XTP2046, The chip selection signal is PG11, Here's the picture :

Therefore, when we modify the code, we also need to specify it as SPI1, stay rt_spi_flash_device.c It is modified into the following code :
#ifdef RT_USING_SPI
#include "rt_stm32f10x_spi.h"
#include "spi_flash_w25qxx.h"
#endif /* RT_USING_SPI */
/*
* SPI1_MOSI: PA7
* SPI1_MISO: PA6
* SPI1_SCK : PA5
*
* SPI Flash CE: PB2
* Touch Panel CS: PG11
*/
#ifdef RT_USING_SPI
static void rt_hw_spi_init(void)
{
/* register spi bus */
{
static struct stm32_spi_bus stm32_spi;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
stm32_spi_register(SPI1, &stm32_spi, "spi1");
}
/* attach spi flash cs */
#ifdef RT_USING_SPI_FLASH
{
static struct rt_spi_device spi_device;
static struct stm32_spi_cs spi_cs;
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
/* spi11: PB2 */
spi_cs.GPIOx = GPIOB;
spi_cs.GPIO_Pin = GPIO_Pin_2;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = spi_cs.GPIO_Pin;
GPIO_SetBits(spi_cs.GPIOx, spi_cs.GPIO_Pin);
GPIO_Init(spi_cs.GPIOx, &GPIO_InitStructure);
rt_spi_bus_attach_device(&spi_device, "spi11", "spi1",(void*)&spi_cs);
}
#endif /* RT_USING_SPI_FLASH */
#ifdef RTGUI_USING_TOUCHPANEL
/* attach touch panel cs */
{
static struct rt_spi_device spi_device;
static struct stm32_spi_cs spi_cs;
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
/* spi21: PG11 */
spi_cs.GPIOx = GPIOG;
spi_cs.GPIO_Pin = GPIO_Pin_11;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE);
GPIO_InitStructure.GPIO_Pin = spi_cs.GPIO_Pin;
GPIO_SetBits(spi_cs.GPIOx, spi_cs.GPIO_Pin);
GPIO_Init(spi_cs.GPIOx, &GPIO_InitStructure);
rt_spi_bus_attach_device(&spi_device, "spi12", "spi1", (void*)&spi_cs);
}
#endif /* RTGUI_USING_TOUCHPANEL */
}
#endif /* RT_USING_SPI */
void rt_spi_flash_device_init(void)
{
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
w25qxx_init("flash0", "spi11");
#endif /* RT_USING_DFS && RT_USING_DFS_ELMFAT */
}
Save after modification , If all goes well , The compilation should pass , We will study the problem of component initialization in the next article .
边栏推荐
- The problem of large fluctuation of hx711 data
- 从蚂蚁的觅食过程看团队研发(转载)
- [leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]
- 【dectectron2】跟着官方demo一起做
- Sql Server 数据库之初学体验
- Common classes (understand)
- Flutter报错 Incorrect use of ParentDataWidget When the exception was thrown, this was the stack:
- Flutter jni混淆 引入.so文件release包闪退
- 使用定位实现左中右布局,中间内容自适应
- 剑指Offer(五十三):表示数值的字符串
猜你喜欢

Oracle cannot start tnslistener service cannot start

Centos8 (liunx) deploying WTM (asp.net 5) using PgSQL

Successfully transplanted stemwin v5.22 on Shenzhou IV development board

.net5wtm (asp.net core) PgSQL unpacking operation

工厂模式详解
![[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array](/img/9d/5ce5d4144a9edc3891147290e360d8.png)
[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array
![[paper after dinner] deep mining external perfect data for chestx ray disease screening](/img/d6/41c75d292c26b2e7e116767a51eb5e.png)
[paper after dinner] deep mining external perfect data for chestx ray disease screening

第8期:云原生—— 大学生职场小白该如何学
![[leetcode每日一题2021/5/8]1723. 完成所有工作的最短时间](/img/e7/a48bb5b8a86cbc4cd5b37bb16661a8.png)
[leetcode每日一题2021/5/8]1723. 完成所有工作的最短时间

Add touch screen driver for stemwin 5.22 on Shenzhou IV development board
随机推荐
【机器学习小记】【风格迁移】deeplearning.ai course4 4th week programming(tensorflow2)
SAP ABAP 守护进程的实现方式
C语言鹏哥20210812C语言函数
Sql Server 数据库之数据类型
[转]ArcGIS中判断两个Geometry之间的关系
Codepoint 58880 not found in font, aborting. flutter build apk时报错
RT-Thread 学习笔记(一)---配置RT-Thread开发环境
反射机制简述
[machine learning notes] [face recognition] deeplearning ai course4 4th week programming
Uninstall Meizu app store
winpcap 抓包函数pcap_loop(),停止问题
Error[Pe147]: declaration is incompatible with '错误问题
Dry goods likeshop takeout order system is open source, 100% open source, no encryption
Oracle创建索引
Flutter 防止科学计数并去除尾数无效0
剑指Offer(五十三):表示数值的字符串
Redis implementation of distributed lock solution
[leetcode daily question 2021/2/13]448. Find all the missing numbers in the array
在altium designer中禁用USBJATG
【机器学习小记】【搭建循环神经网络及其应用】deeplearning.ai course5 1st week programming(keras)