From c16eaf55de6d6ef193c208a8caa5fed4d93fde76 Mon Sep 17 00:00:00 2001 From: supperthomas <78900636@qq.com> Date: Mon, 13 Jun 2022 21:15:12 +0800 Subject: [PATCH] [bsp/stm32l496_ali] add the on-chip flash (#6061) * [bsp/stm32l496_ali] add the on-chip flash * [bsp/stm32l496_ali]add Kconfig Co-authored-by: Meco Man <920369182@qq.com> --- .../stm32l496-ali-developer/board/Kconfig | 8 +++ .../stm32l496-ali-developer/board/SConscript | 3 ++ .../board/mnt.c} | 20 +++++-- .../board/ports/fal_cfg.h | 4 +- bsp/stm32/stm32l496-st-nucleo/board/Kconfig | 9 +++- .../stm32l496-st-nucleo/board/SConscript | 3 +- bsp/stm32/stm32l496-st-nucleo/board/mnt.c | 52 +++++++++++++++++++ 7 files changed, 88 insertions(+), 11 deletions(-) rename bsp/stm32/{stm32l496-st-nucleo/board/mnt_onchip.c => stm32l496-ali-developer/board/mnt.c} (64%) create mode 100644 bsp/stm32/stm32l496-st-nucleo/board/mnt.c diff --git a/bsp/stm32/stm32l496-ali-developer/board/Kconfig b/bsp/stm32/stm32l496-ali-developer/board/Kconfig index 1e347f4653..0c0c2476fc 100644 --- a/bsp/stm32/stm32l496-ali-developer/board/Kconfig +++ b/bsp/stm32/stm32l496-ali-developer/board/Kconfig @@ -63,6 +63,14 @@ menu "On-chip Peripheral Drivers" config BSP_USING_ON_CHIP_FLASH bool "Enable on-chip FLASH" + select RT_USING_FAL + default n + + config BSP_USING_ON_CHIP_FLASH_FATFS + bool "Enable onchip flash with FatFS" + depends on BSP_USING_ON_CHIP_FLASH + select RT_USING_DFS + select RT_USING_DFS_ELMFAT default n menuconfig BSP_USING_SPI diff --git a/bsp/stm32/stm32l496-ali-developer/board/SConscript b/bsp/stm32/stm32l496-ali-developer/board/SConscript index 19814bd2cc..0c3e228e22 100644 --- a/bsp/stm32/stm32l496-ali-developer/board/SConscript +++ b/bsp/stm32/stm32l496-ali-developer/board/SConscript @@ -18,6 +18,9 @@ if GetDepend(['BSP_USING_SPI_LCD']): if GetDepend(['BSP_USING_SDCARD']): src += Glob('ports/sdcard_port.c') +if GetDepend(['BSP_USING_ON_CHIP_FLASH']): + src += Glob('mnt.c') + path = [cwd] path += [cwd + '/CubeMX_Config/Inc'] path += [cwd + '/ports'] diff --git a/bsp/stm32/stm32l496-st-nucleo/board/mnt_onchip.c b/bsp/stm32/stm32l496-ali-developer/board/mnt.c similarity index 64% rename from bsp/stm32/stm32l496-st-nucleo/board/mnt_onchip.c rename to bsp/stm32/stm32l496-ali-developer/board/mnt.c index 2b47ce748d..a8567e9d27 100644 --- a/bsp/stm32/stm32l496-st-nucleo/board/mnt_onchip.c +++ b/bsp/stm32/stm32l496-ali-developer/board/mnt.c @@ -14,30 +14,40 @@ #include "fal.h" #include +#define DBG_TAG "mnt" +#define DBG_LVL DBG_INFO +#include + #ifdef RT_USING_DFS #include int mnt_init(void) { +#ifdef BSP_USING_ON_CHIP_FLASH fal_init(); #define FS_PARTITION_NAME "flash" struct rt_device *mtd_dev; mtd_dev = fal_blk_device_create(FS_PARTITION_NAME); + if (!mtd_dev) + { + LOG_E("Failed to create device.\n"); + } +#ifdef BSP_USING_ON_CHIP_FLASH_FATFS if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) == 0) { - rt_kprintf("Filesystem initialized!"); + LOG_I("Filesystem initialized!"); } else { dfs_mkfs("elm", FS_PARTITION_NAME); if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) != 0) { - rt_kprintf("Failed to initialize filesystem!"); + LOG_I("Failed to initialize filesystem!"); } } - +#endif /* BSP_USING_ON_CHIP_FLASH_FATFS */ +#endif /* BSP_USING_ON_CHIP_FLASH */ return 0; } INIT_ENV_EXPORT(mnt_init); -#endif - +#endif /* RT_USING_DFS */ diff --git a/bsp/stm32/stm32l496-ali-developer/board/ports/fal_cfg.h b/bsp/stm32/stm32l496-ali-developer/board/ports/fal_cfg.h index a0598e9d83..22da54cee2 100644 --- a/bsp/stm32/stm32l496-ali-developer/board/ports/fal_cfg.h +++ b/bsp/stm32/stm32l496-ali-developer/board/ports/fal_cfg.h @@ -27,8 +27,8 @@ extern const struct fal_flash_dev stm32_onchip_flash; /* partition table */ #define FAL_PART_TABLE \ { \ - {FAL_PART_MAGIC_WROD, "app", "onchip_flash", 0, 496 * 1024, 0}, \ - {FAL_PART_MAGIC_WROD, "param", "onchip_flash", 496* 1024, 16 * 1024, 0}, \ + {FAL_PART_MAGIC_WROD, "app", "onchip_flash", 0, 512 * 1024, 0}, \ + {FAL_PART_MAGIC_WROD, "flash", "onchip_flash", 512* 1024, 512 * 1024, 0}, \ } #endif /* FAL_PART_HAS_TABLE_CFG */ #endif /* _FAL_CFG_H_ */ diff --git a/bsp/stm32/stm32l496-st-nucleo/board/Kconfig b/bsp/stm32/stm32l496-st-nucleo/board/Kconfig index 084e549c37..ba8c43d680 100644 --- a/bsp/stm32/stm32l496-st-nucleo/board/Kconfig +++ b/bsp/stm32/stm32l496-st-nucleo/board/Kconfig @@ -96,10 +96,15 @@ menu "On-chip Peripheral Drivers" endif config BSP_USING_ON_CHIP_FLASH + bool "Enable on-chip FLASH" + select RT_USING_FAL + default n + + config BSP_USING_ON_CHIP_FLASH_FATFS + bool "Enable onchip flash with FatFS" + depends on BSP_USING_ON_CHIP_FLASH select RT_USING_DFS select RT_USING_DFS_ELMFAT - select RT_USING_FAL - bool "Enable on-chip FLASH" default n config BSP_USING_USBD diff --git a/bsp/stm32/stm32l496-st-nucleo/board/SConscript b/bsp/stm32/stm32l496-st-nucleo/board/SConscript index 617f20c65c..cf0e190c8b 100644 --- a/bsp/stm32/stm32l496-st-nucleo/board/SConscript +++ b/bsp/stm32/stm32l496-st-nucleo/board/SConscript @@ -13,8 +13,7 @@ CubeMX_Config/Src/stm32l4xx_hal_msp.c ''') if GetDepend(['BSP_USING_ON_CHIP_FLASH']): - src += Glob('mnt_onchip.c') - + src += Glob('mnt.c') path = [cwd] path += [cwd + '/CubeMX_Config/Inc'] diff --git a/bsp/stm32/stm32l496-st-nucleo/board/mnt.c b/bsp/stm32/stm32l496-st-nucleo/board/mnt.c new file mode 100644 index 0000000000..b3d1c5f8b0 --- /dev/null +++ b/bsp/stm32/stm32l496-st-nucleo/board/mnt.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2006-2022, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2022-06-08 supperthomas first version + */ + +#include +#include + +#include "fal.h" + +#define DBG_TAG "mnt" +#define DBG_LVL DBG_INFO +#include + +#ifdef RT_USING_DFS +#include + +int mnt_init(void) +{ +#ifdef BSP_USING_ON_CHIP_FLASH + fal_init(); +#define FS_PARTITION_NAME "flash" + struct rt_device *mtd_dev; + mtd_dev = fal_blk_device_create(FS_PARTITION_NAME); + if (!mtd_dev) + { + LOG_E("Failed to create device.\n"); + } +#ifdef BSP_USING_ON_CHIP_FLASH_FATFS + if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) == 0) + { + LOG_I("Filesystem initialized!"); + } + else + { + dfs_mkfs("elm", FS_PARTITION_NAME); + if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) != 0) + { + LOG_E("Failed to initialize filesystem!"); + } + } +#endif /* BSP_USING_ON_CHIP_FLASH_FATFS */ +#endif /* BSP_USING_ON_CHIP_FLASH */ + return 0; +} +INIT_ENV_EXPORT(mnt_init); +#endif /* RT_USING_DFS */