From 4fa40bcee57cde746a8ceaebe23fb57816cccaa8 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 18 Aug 2022 21:03:44 -0400 Subject: [PATCH] =?UTF-8?q?[stm32l4-pandora]=20=E6=95=B4=E7=90=86=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=B3=BB=E7=BB=9F=20=E5=A2=9E=E5=8A=A0ROMFS=EF=BC=8CF?= =?UTF-8?q?ATFS=E5=92=8C=E6=9C=AA=E6=9D=A5=E7=9A=84LittleFS=E5=B0=86?= =?UTF-8?q?=E6=8C=82=E8=BD=BD=E5=9C=A8ROMFS=E4=B8=8A=20=E5=88=9D=E6=AD=A5?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0littlefs=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=EF=BC=8C=E5=B0=9A=E6=9C=AA=E5=AE=8C=E5=85=A8=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E4=B8=80=E9=94=AE=E5=8C=96=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/stm32l475-atk-pandora/board/Kconfig | 32 +++++-- .../stm32l475-atk-pandora/board/SConscript | 13 ++- .../board/ports/drv_filesystem.c | 92 +++++++++++++++++++ .../board/ports/drv_qspi_flash.c | 4 +- .../board/ports/drv_sdcard.c | 85 ----------------- 5 files changed, 129 insertions(+), 97 deletions(-) create mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/drv_filesystem.c delete mode 100644 bsp/stm32/stm32l475-atk-pandora/board/ports/drv_sdcard.c diff --git a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig index cda0e0fa9d..703f57a460 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig +++ b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig @@ -103,15 +103,35 @@ menu "Onboard Peripheral Drivers" default y endif - config BSP_USING_SDCARD - bool "Enable SDCARD (spi1)" - select BSP_USING_SPI - select BSP_USING_SPI1 - select RT_USING_SPI_MSD + + + menuconfig BSP_USING_FS + bool "Enable File System" select RT_USING_DFS - select RT_USING_DFS_ELMFAT + select RT_USING_DFS_ROMFS default n + if BSP_USING_FS + config BSP_USING_SDCARD_FATFS + bool "Enable SDCARD (FATFS)" + select BSP_USING_SPI + select BSP_USING_SPI1 + select RT_USING_SPI_MSD + select RT_USING_DFS_ELMFAT + default n + + config BSP_USING_SPI_FLASH_LITTLEFS + bool "Enable SPI-FLASH (LittleFS)" + select RT_USING_MTD_NOR + select BSP_USING_QSPI_FLASH + select RT_USING_FAL + select FAL_USING_AUTO_INIT + select FAL_PART_HAS_TABLE_CFG + select PKG_USING_LITTLEFS + default n + endif + + config BSP_USING_ICM20608 bool "Enable ICM20608 (i2c3)" select BSP_USING_I2C diff --git a/bsp/stm32/stm32l475-atk-pandora/board/SConscript b/bsp/stm32/stm32l475-atk-pandora/board/SConscript index 76d7ff6a42..8131ce76b7 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/SConscript +++ b/bsp/stm32/stm32l475-atk-pandora/board/SConscript @@ -12,14 +12,20 @@ board.c CubeMX_Config/Src/stm32l4xx_hal_msp.c ''') +path = [cwd] +path += [cwd + '/CubeMX_Config/Inc'] + if GetDepend(['BSP_USING_KEY']): src += Glob('ports/drv_key.c') if GetDepend(['BSP_USING_QSPI_FLASH']): src += Glob('ports/drv_qspi_flash.c') -if GetDepend(['BSP_USING_SDCARD']): - src += Glob('ports/drv_sdcard.c') +if GetDepend(['BSP_USING_FS']): + src += Glob('ports/drv_filesystem.c') + if GetDepend(['BSP_USING_SPI_FLASH_LITTLEFS']): + src += Glob('ports/fal/fal_spi_flash_sfud_port.c') + path += [cwd + '/ports/fal'] if GetDepend(['BSP_USING_ICM20608']) or GetDepend(['BSP_USING_AHT10']): src += Glob('ports/sensor_port.c') @@ -34,8 +40,7 @@ if GetDepend(['BSP_USING_AUDIO_RECORD']): if GetDepend(['BSP_USING_STM32_SDIO']): src += Glob('ports/drv_sdio_adapter.c') -path = [cwd] -path += [cwd + '/CubeMX_Config/Inc'] + if GetDepend(['BSP_USING_AUDIO']): path += [cwd + '/ports/audio'] diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_filesystem.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_filesystem.c new file mode 100644 index 0000000000..7f497b5848 --- /dev/null +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_filesystem.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-12-14 balanceTWK add sdcard port file + * 2021-02-26 Meco Man fix a bug that cannot use fatfs in the main thread at starting up + */ + +#include +#include +#include +#include +#include + +#if DFS_FILESYSTEMS_MAX < 4 +#error "Please define DFS_FILESYSTEMS_MAX more than 4" +#endif +#if DFS_FILESYSTEM_TYPES_MAX < 4 +#error "Please define DFS_FILESYSTEM_TYPES_MAX more than 4" +#endif + +#define DBG_TAG "app.filesystem" +#define DBG_LVL DBG_INFO +#include + +#ifdef BSP_USING_SDCARD_FATFS +#include +#include +static int rt_hw_spi1_tfcard(void) +{ + __HAL_RCC_GPIOC_CLK_ENABLE(); + rt_hw_spi_device_attach("spi1", "spi10", GPIOC, GPIO_PIN_3); + return msd_init("sd0", "spi10"); +} +INIT_DEVICE_EXPORT(rt_hw_spi1_tfcard); + +static int onboard_sdcard_mount(void) +{ + if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK) + { + LOG_I("SD card mount to '/sdcard'"); + } + else + { + LOG_E("SD card mount to '/sdcard' failed!"); + } + + return RT_EOK; +} +#endif /* BSP_USING_SDCARD_FATFS */ + + +#ifdef BSP_USING_SPI_FLASH_LITTLEFS + +#endif /* BSP_USING_SPI_FLASH_LITTLEFS */ + +static const struct romfs_dirent _romfs_root[] = +{ +#ifdef BSP_USING_SDCARD_FATFS + {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0}, +#endif + +#ifdef BSP_USING_SPI_FLASH_LITTLEFS + {ROMFS_DIRENT_DIR, "spiflash", RT_NULL, 0}, +#endif +}; + +static const struct romfs_dirent romfs_root = +{ + ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0]) +}; + +static int filesystem_mount(void) +{ + if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) != 0) + { + LOG_E("rom mount to '/' failed!"); + } +#ifdef BSP_USING_SDCARD_FATFS + onboard_sdcard_mount(); +#endif + +#ifdef BSP_USING_SPI_FLASH_LITTLEFS + onboard_spiflash_mount(); +#endif + + return RT_EOK; +} +INIT_APP_EXPORT(filesystem_mount); diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c index f866d2741c..2342b3c669 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c +++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_qspi_flash.c @@ -74,7 +74,7 @@ static int rt_hw_qspi_flash_with_sfud_init(void) } INIT_COMPONENT_EXPORT(rt_hw_qspi_flash_with_sfud_init); -#if defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD) +#if defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD_FATFS) #include #define BLK_DEV_NAME "W25Q128" @@ -106,5 +106,5 @@ int mnt_init(void) } INIT_ENV_EXPORT(mnt_init); -#endif /* defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD) */ +#endif /* defined(RT_USING_DFS_ELMFAT) && !defined(BSP_USING_SDCARD_FATFS) */ #endif /* BSP_USING_QSPI_FLASH */ diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_sdcard.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_sdcard.c deleted file mode 100644 index ba253aacfa..0000000000 --- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_sdcard.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2018-12-14 balanceTWK add sdcard port file - * 2021-02-26 Meco Man fix a bug that cannot use fatfs in the main thread at starting up - */ - -#include - -#ifdef BSP_USING_SDCARD - -#include -#include -#include -#include -#include -#include -#include -#include "drv_spi.h" -#include "spi_msd.h" - -#define DBG_TAG "app.card" -#define DBG_LVL DBG_INFO -#include - -static void sd_mount(void *parameter) -{ - while (1) - { - rt_thread_mdelay(500); - if(rt_device_find("sd0") != RT_NULL) - { - if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK) - { - LOG_I("sd card mount to '/'"); - break; - } - else - { - LOG_W("sd card mount to '/' failed!"); - } - } - } -} - -static int onboard_sdcard_mount(void) -{ - rt_thread_t tid; - - if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK) - { - LOG_I("sd card mount to '/'"); - } - else - { - tid = rt_thread_create("sd_mount", sd_mount, RT_NULL, - 1024, RT_THREAD_PRIORITY_MAX - 2, 20); - if (tid != RT_NULL) - { - rt_thread_startup(tid); - } - else - { - LOG_E("create sd_mount thread err!"); - } - } - - return RT_EOK; -} -INIT_APP_EXPORT(onboard_sdcard_mount); - -static int rt_hw_spi1_tfcard(void) -{ - __HAL_RCC_GPIOC_CLK_ENABLE(); - rt_hw_spi_device_attach("spi1", "spi10", GPIOC, GPIO_PIN_3); - return msd_init("sd0", "spi10"); -} -INIT_DEVICE_EXPORT(rt_hw_spi1_tfcard); - -#endif /* BSP_USING_SDCARD */ -