summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYJIE_1998 <[email protected]>2021-08-04 18:22:04 +0800
committerYJIE_1998 <[email protected]>2021-08-04 18:22:04 +0800
commita403a3ec3bc4125fca940b297d4d2eb0981e183d (patch)
treeef5aa72868a008ba097e392c112b0dfee5b877c8
parentb73ad3cf596c5371c8dca564433d1fccb6c73e13 (diff)
【修改】移植 littlefs 文件系统
-rw-r--r--bsp/stm32/stm32f407-atk-explorer/board/Kconfig11
-rw-r--r--bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c71
-rw-r--r--bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h21
3 files changed, 101 insertions, 2 deletions
diff --git a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig
index d5686bd351..360979256e 100644
--- a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig
+++ b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig
@@ -91,6 +91,17 @@ menu "Onboard Peripheral Drivers"
range 0 24000000
depends on BSP_USING_SDCARD
default 1000000
+
+ config BSP_USING_NOR_MTD_FS
+ bool "Enable LITTLEFS"
+ select RT_USING_DFS
+ select RT_USING_MTD_NOR
+ select BSP_USING_ON_CHIP_FLASH
+ select BSP_USING_SPI_FLASH
+ select BSP_USING_FS
+ select RT_USING_SYSTEM_WORKQUEUE
+ default n
+
endmenu
endmenu
diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c b/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c
index a8b36da2e1..c703645100 100644
--- a/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c
+++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c
@@ -16,6 +16,9 @@
#include <dfs_romfs.h>
#include <dfs_fs.h>
#include <dfs_posix.h>
+#include <fal.h>
+
+#define BSP_USING_NOR_MTD_FS
#if DFS_FILESYSTEMS_MAX < 4
#error "Please define DFS_FILESYSTEMS_MAX more than 4"
@@ -75,11 +78,73 @@ static int onboard_sdcard_mount(void)
}
#endif
+#ifdef BSP_USING_NOR_MTD_FS
+
+#define FS_PARTITION_NAME "filesystem"
+
+static void mtd_mount(void *parameter)
+{
+ struct rt_device *mtd_dev = RT_NULL;
+ fal_init();
+ mtd_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);
+ if (!mtd_dev)
+ {
+ LOG_E("Can't create a mtd device on '%s' partition.", FS_PARTITION_NAME);
+ }
+ while (1)
+ {
+ rt_thread_mdelay(500);
+ if(rt_device_find(FS_PARTITION_NAME) != RT_NULL)
+ {
+ if (dfs_mount(FS_PARTITION_NAME, "/flash", "lfs", 0, 0) == RT_EOK)
+ {
+ LOG_I("mtd nor flash mount to '/flash'");
+ break;
+ }
+ else
+ {
+ LOG_W("mtd nor flash mount to '/flash' failed!");
+ }
+ }
+ }
+}
+
+static int onboard_mtd_mount(void)
+{
+ rt_thread_t tid;
+
+ if (dfs_mount(FS_PARTITION_NAME, "/flash", "lfs", 0, 0) == RT_EOK)
+ {
+ LOG_I("mtd nor flash mount to '/flash'");
+ }
+ else
+ {
+ tid = rt_thread_create("mtd_mount", mtd_mount, RT_NULL,
+ 1024, RT_THREAD_PRIORITY_MAX - 3, 20);
+ if (tid != RT_NULL)
+ {
+ rt_thread_startup(tid);
+ }
+ else
+ {
+ LOG_E("create mtd_mount thread err!");
+ }
+ }
+
+ return RT_EOK;
+}
+#endif
+
+
static const struct romfs_dirent _romfs_root[] =
{
#ifdef BSP_USING_SDCARD
{ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0},
#endif
+#ifdef BSP_USING_NOR_MTD_FS
+ {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0},
+#endif
+
// {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0},
};
@@ -97,7 +162,11 @@ static int filesystem_mount(void)
#ifdef BSP_USING_SDCARD
onboard_sdcard_mount();
#endif
-
+
+#ifdef BSP_USING_NOR_MTD_FS
+ onboard_mtd_mount();
+#endif
+
return RT_EOK;
}
INIT_APP_EXPORT(filesystem_mount);
diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h b/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h
index 995136cd54..de91d8603a 100644
--- a/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h
+++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h
@@ -22,27 +22,46 @@
#define STM32_FLASH_START_ADRESS_64K (STM32_FLASH_START_ADRESS_16K + FLASH_SIZE_GRANULARITY_16K)
#define STM32_FLASH_START_ADRESS_128K (STM32_FLASH_START_ADRESS_64K + FLASH_SIZE_GRANULARITY_64K)
+#ifdef BSP_USING_NOR_MTD_FS
+extern struct fal_flash_dev nor_flash0;
+#else
extern const struct fal_flash_dev stm32_onchip_flash_16k;
extern const struct fal_flash_dev stm32_onchip_flash_64k;
extern const struct fal_flash_dev stm32_onchip_flash_128k;
+#endif
+
/* flash device table */
+#ifdef BSP_USING_NOR_MTD_FS
+#define FAL_FLASH_DEV_TABLE \
+{ \
+ &nor_flash0, \
+}
+#else
#define FAL_FLASH_DEV_TABLE \
{ \
&stm32_onchip_flash_16k, \
&stm32_onchip_flash_64k, \
&stm32_onchip_flash_128k, \
}
+#endif
+
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
+#ifdef BSP_USING_NOR_MTD_FS
+#define FAL_PART_TABLE \
+{ \
+ {FAL_PART_MAGIC_WROD, "filesystem",FAL_USING_NOR_FLASH_DEV_NAME, 0 , 1024 * 1024, 0}, \
+}
+#else
#define FAL_PART_TABLE \
{ \
{FAL_PART_MAGIC_WROD, "bootloader", "onchip_flash_16k", 0 , FLASH_SIZE_GRANULARITY_16K , 0}, \
{FAL_PART_MAGIC_WROD, "param", "onchip_flash_64k", 0 , FLASH_SIZE_GRANULARITY_64K , 0}, \
{FAL_PART_MAGIC_WROD, "app", "onchip_flash_128k", 0 , FLASH_SIZE_GRANULARITY_128K, 0}, \
}
-
+#endif
#endif /* FAL_PART_HAS_TABLE_CFG */
#endif /* _FAL_CFG_H_ */