From a403a3ec3bc4125fca940b297d4d2eb0981e183d Mon Sep 17 00:00:00 2001 From: YJIE_1998 <1039241323@qq.com> Date: Wed, 4 Aug 2021 18:22:04 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91?= =?UTF-8?q?=E7=A7=BB=E6=A4=8D=20littlefs=20=E6=96=87=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stm32f407-atk-explorer/board/Kconfig | 11 +++ .../board/ports/drv_filesystem.c | 71 ++++++++++++++++++- .../board/ports/fal_cfg.h | 21 +++++- 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 #include #include +#include + +#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_ */ From 74b3bb0af36492715e9c3493aecf1d5fd415494f Mon Sep 17 00:00:00 2001 From: YJIE_1998 <1039241323@qq.com> Date: Wed, 4 Aug 2021 19:21:45 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E3=80=90=E6=B7=BB=E5=8A=A0=E3=80=91?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0dfs=5Fromfs.h=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E6=94=B9=E6=9E=84=E5=BB=BA=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stm32f407-atk-explorer/board/SConscript | 1 + .../board/ports/dfs_romfs.h | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h diff --git a/bsp/stm32/stm32f407-atk-explorer/board/SConscript b/bsp/stm32/stm32f407-atk-explorer/board/SConscript index 64b8ab3f41..4212e953bf 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/SConscript +++ b/bsp/stm32/stm32f407-atk-explorer/board/SConscript @@ -20,6 +20,7 @@ if GetDepend(['BSP_USING_SPI_FLASH']): if GetDepend(['BSP_USING_FS']): src += Glob('ports/drv_filesystem.c') + src += Glob('ports/dfs_romfs.h') if GetDepend(['BSP_USING_SRAM']): src += Glob('ports/drv_sram.c') diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h b/bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h new file mode 100644 index 0000000000..affa4bf993 --- /dev/null +++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019/01/13 Bernard code cleanup + */ + +#ifndef __DFS_ROMFS_H__ +#define __DFS_ROMFS_H__ + +#include + +#define ROMFS_DIRENT_FILE 0x00 +#define ROMFS_DIRENT_DIR 0x01 + +struct romfs_dirent +{ + rt_uint32_t type; /* dirent type */ + + const char *name; /* dirent name */ + const rt_uint8_t *data; /* file date ptr */ + rt_size_t size; /* file size */ +}; + +int dfs_romfs_init(void); +extern const struct romfs_dirent romfs_root; + +#endif From 2ac8bc88643a695542f3bd1e6a1187faf6fe070b Mon Sep 17 00:00:00 2001 From: YJIE_1998 <1039241323@qq.com> Date: Thu, 5 Aug 2021 10:47:34 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=92=8C=E5=AE=8F=E5=91=BD=E5=90=8D,?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=B7=BB=E5=8A=A0=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stm32f407-atk-explorer/board/Kconfig | 6 ++-- .../stm32f407-atk-explorer/board/SConscript | 1 - .../board/ports/dfs_romfs.h | 31 ------------------- .../board/ports/drv_filesystem.c | 27 +++++++--------- .../board/ports/fal_cfg.h | 13 ++++---- 5 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h diff --git a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig index 360979256e..7d6d8cf883 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/Kconfig +++ b/bsp/stm32/stm32f407-atk-explorer/board/Kconfig @@ -92,12 +92,12 @@ menu "Onboard Peripheral Drivers" depends on BSP_USING_SDCARD default 1000000 - config BSP_USING_NOR_MTD_FS + config BSP_USING_SPI_FLASH_LITTLEFS bool "Enable LITTLEFS" select RT_USING_DFS + select RT_USING_DFS_ROMFS select RT_USING_MTD_NOR - select BSP_USING_ON_CHIP_FLASH - select BSP_USING_SPI_FLASH + select BSP_USING_SPI_FLASH select BSP_USING_FS select RT_USING_SYSTEM_WORKQUEUE default n diff --git a/bsp/stm32/stm32f407-atk-explorer/board/SConscript b/bsp/stm32/stm32f407-atk-explorer/board/SConscript index 4212e953bf..64b8ab3f41 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/SConscript +++ b/bsp/stm32/stm32f407-atk-explorer/board/SConscript @@ -20,7 +20,6 @@ if GetDepend(['BSP_USING_SPI_FLASH']): if GetDepend(['BSP_USING_FS']): src += Glob('ports/drv_filesystem.c') - src += Glob('ports/dfs_romfs.h') if GetDepend(['BSP_USING_SRAM']): src += Glob('ports/drv_sram.c') diff --git a/bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h b/bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h deleted file mode 100644 index affa4bf993..0000000000 --- a/bsp/stm32/stm32f407-atk-explorer/board/ports/dfs_romfs.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2019/01/13 Bernard code cleanup - */ - -#ifndef __DFS_ROMFS_H__ -#define __DFS_ROMFS_H__ - -#include - -#define ROMFS_DIRENT_FILE 0x00 -#define ROMFS_DIRENT_DIR 0x01 - -struct romfs_dirent -{ - rt_uint32_t type; /* dirent type */ - - const char *name; /* dirent name */ - const rt_uint8_t *data; /* file date ptr */ - rt_size_t size; /* file size */ -}; - -int dfs_romfs_init(void); -extern const struct romfs_dirent romfs_root; - -#endif 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 c703645100..39bed08eab 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c +++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c @@ -18,8 +18,6 @@ #include #include -#define BSP_USING_NOR_MTD_FS - #if DFS_FILESYSTEMS_MAX < 4 #error "Please define DFS_FILESYSTEMS_MAX more than 4" #endif @@ -78,11 +76,11 @@ static int onboard_sdcard_mount(void) } #endif -#ifdef BSP_USING_NOR_MTD_FS +#ifdef BSP_USING_SPI_FLASH_LITTLEFS #define FS_PARTITION_NAME "filesystem" -static void mtd_mount(void *parameter) +static void spiflash_mount(void *parameter) { struct rt_device *mtd_dev = RT_NULL; fal_init(); @@ -98,28 +96,28 @@ static void mtd_mount(void *parameter) { if (dfs_mount(FS_PARTITION_NAME, "/flash", "lfs", 0, 0) == RT_EOK) { - LOG_I("mtd nor flash mount to '/flash'"); + LOG_I("spi flash mount to '/flash'"); break; } else { - LOG_W("mtd nor flash mount to '/flash' failed!"); + LOG_W("spi flash mount to '/flash' failed!"); } } } } -static int onboard_mtd_mount(void) +static int onboard_spiflash_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'"); + LOG_I("spi flash mount to '/flash'"); } else { - tid = rt_thread_create("mtd_mount", mtd_mount, RT_NULL, + tid = rt_thread_create("spiflash_mount", spiflash_mount, RT_NULL, 1024, RT_THREAD_PRIORITY_MAX - 3, 20); if (tid != RT_NULL) { @@ -127,7 +125,7 @@ static int onboard_mtd_mount(void) } else { - LOG_E("create mtd_mount thread err!"); + LOG_E("create spiflash_mount thread err!"); } } @@ -141,11 +139,10 @@ 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 + +#ifdef BSP_USING_SPI_FLASH_LITTLEFS {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0}, #endif - -// {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0}, }; const struct romfs_dirent romfs_root = @@ -163,8 +160,8 @@ static int filesystem_mount(void) onboard_sdcard_mount(); #endif -#ifdef BSP_USING_NOR_MTD_FS - onboard_mtd_mount(); +#ifdef BSP_USING_SPI_FLASH_LITTLEFS + onboard_spiflash_mount(); #endif return RT_EOK; 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 de91d8603a..0cea945fe5 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h +++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/fal_cfg.h @@ -14,17 +14,16 @@ #include #include +#ifdef BSP_USING_SPI_FLASH_LITTLEFS +extern struct fal_flash_dev nor_flash0; +#else #define FLASH_SIZE_GRANULARITY_16K (4 * 16 * 1024) #define FLASH_SIZE_GRANULARITY_64K (64 * 1024) #define FLASH_SIZE_GRANULARITY_128K (7 * 128 * 1024) - #define STM32_FLASH_START_ADRESS_16K STM32_FLASH_START_ADRESS #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; @@ -32,7 +31,7 @@ extern const struct fal_flash_dev stm32_onchip_flash_128k; /* flash device table */ -#ifdef BSP_USING_NOR_MTD_FS +#ifdef BSP_USING_SPI_FLASH_LITTLEFS #define FAL_FLASH_DEV_TABLE \ { \ &nor_flash0, \ @@ -50,10 +49,10 @@ extern const struct fal_flash_dev stm32_onchip_flash_128k; #ifdef FAL_PART_HAS_TABLE_CFG /* partition table */ -#ifdef BSP_USING_NOR_MTD_FS +#ifdef BSP_USING_SPI_FLASH_LITTLEFS #define FAL_PART_TABLE \ { \ - {FAL_PART_MAGIC_WROD, "filesystem",FAL_USING_NOR_FLASH_DEV_NAME, 0 , 1024 * 1024, 0}, \ + {FAL_PART_MAGIC_WROD, "filesystem",FAL_USING_NOR_FLASH_DEV_NAME, 0 , 16 * 1024 * 1024, 0}, \ } #else #define FAL_PART_TABLE \ From addfbefeeb329e0d4d777d474f1dfcddc2e777ed Mon Sep 17 00:00:00 2001 From: YJIE_1998 <1039241323@qq.com> Date: Thu, 5 Aug 2021 18:31:06 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20drv=5Ffilesystem.c=20=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?ci=20=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 39bed08eab..07e6140722 100644 --- a/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c +++ b/bsp/stm32/stm32f407-atk-explorer/board/ports/drv_filesystem.c @@ -159,11 +159,11 @@ static int filesystem_mount(void) #ifdef BSP_USING_SDCARD onboard_sdcard_mount(); #endif - + #ifdef BSP_USING_SPI_FLASH_LITTLEFS onboard_spiflash_mount(); #endif - + return RT_EOK; } INIT_APP_EXPORT(filesystem_mount);