Skip to content

Commit a403a3e

Browse files
committed
【修改】移植 littlefs 文件系统
1 parent b73ad3c commit a403a3e

File tree

3 files changed

+101
-2
lines changed

3 files changed

+101
-2
lines changed

bsp/stm32/stm32f407-atk-explorer/board/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ menu "Onboard Peripheral Drivers"
9191
range 0 24000000
9292
depends on BSP_USING_SDCARD
9393
default 1000000
94+
95+
config BSP_USING_NOR_MTD_FS
96+
bool "Enable LITTLEFS"
97+
select RT_USING_DFS
98+
select RT_USING_MTD_NOR
99+
select BSP_USING_ON_CHIP_FLASH
100+
select BSP_USING_SPI_FLASH
101+
select BSP_USING_FS
102+
select RT_USING_SYSTEM_WORKQUEUE
103+
default n
104+
94105
endmenu
95106

96107
endmenu

bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#include <dfs_romfs.h>
1717
#include <dfs_fs.h>
1818
#include <dfs_posix.h>
19+
#include <fal.h>
20+
21+
#define BSP_USING_NOR_MTD_FS
1922

2023
#if DFS_FILESYSTEMS_MAX < 4
2124
#error "Please define DFS_FILESYSTEMS_MAX more than 4"
@@ -75,11 +78,73 @@ static int onboard_sdcard_mount(void)
7578
}
7679
#endif
7780

81+
#ifdef BSP_USING_NOR_MTD_FS
82+
83+
#define FS_PARTITION_NAME "filesystem"
84+
85+
static void mtd_mount(void *parameter)
86+
{
87+
struct rt_device *mtd_dev = RT_NULL;
88+
fal_init();
89+
mtd_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);
90+
if (!mtd_dev)
91+
{
92+
LOG_E("Can't create a mtd device on '%s' partition.", FS_PARTITION_NAME);
93+
}
94+
while (1)
95+
{
96+
rt_thread_mdelay(500);
97+
if(rt_device_find(FS_PARTITION_NAME) != RT_NULL)
98+
{
99+
if (dfs_mount(FS_PARTITION_NAME, "/flash", "lfs", 0, 0) == RT_EOK)
100+
{
101+
LOG_I("mtd nor flash mount to '/flash'");
102+
break;
103+
}
104+
else
105+
{
106+
LOG_W("mtd nor flash mount to '/flash' failed!");
107+
}
108+
}
109+
}
110+
}
111+
112+
static int onboard_mtd_mount(void)
113+
{
114+
rt_thread_t tid;
115+
116+
if (dfs_mount(FS_PARTITION_NAME, "/flash", "lfs", 0, 0) == RT_EOK)
117+
{
118+
LOG_I("mtd nor flash mount to '/flash'");
119+
}
120+
else
121+
{
122+
tid = rt_thread_create("mtd_mount", mtd_mount, RT_NULL,
123+
1024, RT_THREAD_PRIORITY_MAX - 3, 20);
124+
if (tid != RT_NULL)
125+
{
126+
rt_thread_startup(tid);
127+
}
128+
else
129+
{
130+
LOG_E("create mtd_mount thread err!");
131+
}
132+
}
133+
134+
return RT_EOK;
135+
}
136+
#endif
137+
138+
78139
static const struct romfs_dirent _romfs_root[] =
79140
{
80141
#ifdef BSP_USING_SDCARD
81142
{ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0},
82143
#endif
144+
#ifdef BSP_USING_NOR_MTD_FS
145+
{ROMFS_DIRENT_DIR, "flash", RT_NULL, 0},
146+
#endif
147+
83148
// {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0},
84149
};
85150

@@ -97,7 +162,11 @@ static int filesystem_mount(void)
97162
#ifdef BSP_USING_SDCARD
98163
onboard_sdcard_mount();
99164
#endif
100-
165+
166+
#ifdef BSP_USING_NOR_MTD_FS
167+
onboard_mtd_mount();
168+
#endif
169+
101170
return RT_EOK;
102171
}
103172
INIT_APP_EXPORT(filesystem_mount);

bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,46 @@
2222
#define STM32_FLASH_START_ADRESS_64K (STM32_FLASH_START_ADRESS_16K + FLASH_SIZE_GRANULARITY_16K)
2323
#define STM32_FLASH_START_ADRESS_128K (STM32_FLASH_START_ADRESS_64K + FLASH_SIZE_GRANULARITY_64K)
2424

25+
#ifdef BSP_USING_NOR_MTD_FS
26+
extern struct fal_flash_dev nor_flash0;
27+
#else
2528
extern const struct fal_flash_dev stm32_onchip_flash_16k;
2629
extern const struct fal_flash_dev stm32_onchip_flash_64k;
2730
extern const struct fal_flash_dev stm32_onchip_flash_128k;
31+
#endif
32+
2833

2934
/* flash device table */
35+
#ifdef BSP_USING_NOR_MTD_FS
36+
#define FAL_FLASH_DEV_TABLE \
37+
{ \
38+
&nor_flash0, \
39+
}
40+
#else
3041
#define FAL_FLASH_DEV_TABLE \
3142
{ \
3243
&stm32_onchip_flash_16k, \
3344
&stm32_onchip_flash_64k, \
3445
&stm32_onchip_flash_128k, \
3546
}
47+
#endif
48+
3649
/* ====================== Partition Configuration ========================== */
3750
#ifdef FAL_PART_HAS_TABLE_CFG
3851

3952
/* partition table */
53+
#ifdef BSP_USING_NOR_MTD_FS
54+
#define FAL_PART_TABLE \
55+
{ \
56+
{FAL_PART_MAGIC_WROD, "filesystem",FAL_USING_NOR_FLASH_DEV_NAME, 0 , 1024 * 1024, 0}, \
57+
}
58+
#else
4059
#define FAL_PART_TABLE \
4160
{ \
4261
{FAL_PART_MAGIC_WROD, "bootloader", "onchip_flash_16k", 0 , FLASH_SIZE_GRANULARITY_16K , 0}, \
4362
{FAL_PART_MAGIC_WROD, "param", "onchip_flash_64k", 0 , FLASH_SIZE_GRANULARITY_64K , 0}, \
4463
{FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0 , FLASH_SIZE_GRANULARITY_128K, 0}, \
4564
}
46-
65+
#endif
4766
#endif /* FAL_PART_HAS_TABLE_CFG */
4867
#endif /* _FAL_CFG_H_ */

0 commit comments

Comments
 (0)