赞
踩
fal_cfg.h
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
#define FAL_PART_TABLE \
{ \
{FAL_PART_MAGIC_WORD, "wifi_image", NOR_FLASH_DEV_NAME, 0, 512*1024, 0}, \
{FAL_PART_MAGIC_WORD, "bt_image", NOR_FLASH_DEV_NAME, 512*1024, 512*1024, 0}, \
{FAL_PART_MAGIC_WORD, "download", NOR_FLASH_DEV_NAME, 1024*1024, 2*1024*1024, 0}, \
{FAL_PART_MAGIC_WORD, "easyflash", NOR_FLASH_DEV_NAME, 3*1024*1024, 1*1024*1024, 0}, \
{FAL_PART_MAGIC_WORD, "filesystem", NOR_FLASH_DEV_NAME, 4*1024*1024, 12*1024*1024, 0}, \
}
#endif /* FAL_PART_HAS_TABLE_CFG */
filesystem.c
开启了 RT_USING_DFS_ROMFS ,发现是 board\Kconfig
默认配置的,这里去掉这个选项,这样文件系统可以写filesystem.c
,默认lfs(littlefs)文件系统,改为elm(fatfs)文件系统"filesystem"
挂载为文件根目录 /
/* * Copyright (c) 2006-2022, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-12-13 balanceTWK add sdcard port file * 2019-06-11 WillianChan Add SD card hot plug detection */ #include <rtthread.h> #ifdef BSP_USING_FS #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 #include <dfs_fs.h> #ifdef BSP_USING_SDCARD_FS #include <board.h> #include "drv_sdio.h" #endif #ifdef BSP_USING_SPI_FLASH_FS #include "fal.h" #endif #define DBG_TAG "app.filesystem" #define DBG_LVL DBG_INFO #include <rtdbg.h> #ifdef RT_USING_DFS_ROMFS /* 默认不使用 ROMFS */ #include "dfs_romfs.h" static const struct romfs_dirent _romfs_root[] = { {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0}, {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0} }; const struct romfs_dirent romfs_root = { ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root) / sizeof(_romfs_root[0]) }; #endif #ifdef BSP_USING_SDCARD_FS /* SD Card hot plug detection pin */ #define SD_CHECK_PIN GET_PIN(D, 5) static void _sdcard_mount(void) { rt_device_t device; device = rt_device_find("sd0"); if (device == NULL) { mmcsd_wait_cd_changed(0); sdcard_change(); mmcsd_wait_cd_changed(RT_WAITING_FOREVER); device = rt_device_find("sd0"); } if (device != RT_NULL) { if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK) { LOG_I("sd card mount to '/sdcard'"); } else { LOG_W("sd card mount to '/sdcard' failed!"); } } } static void _sdcard_unmount(void) { rt_thread_mdelay(200); dfs_unmount("/sdcard"); LOG_I("Unmount \"/sdcard\""); mmcsd_wait_cd_changed(0); sdcard_change(); mmcsd_wait_cd_changed(RT_WAITING_FOREVER); } static void sd_mount(void *parameter) { rt_uint8_t re_sd_check_pin = 1; rt_thread_mdelay(200); if (rt_pin_read(SD_CHECK_PIN)) { _sdcard_mount(); } while (1) { rt_thread_mdelay(200); if (!re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) != 0) { _sdcard_mount(); } if (re_sd_check_pin && (re_sd_check_pin = rt_pin_read(SD_CHECK_PIN)) == 0) { _sdcard_unmount(); } } } #endif /* BSP_USING_SDCARD_FS */ #define BLK_DEV_NAME "filesystem" int mnt_spi_flash_init(void) /* 外部SPI Flash 分区挂载 */ { rt_thread_delay(RT_TICK_PER_SECOND); fal_blk_device_create(BLK_DEV_NAME); if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0) { rt_kprintf(BLK_DEV_NAME" mount to '/'\n"); } else { if(dfs_mkfs("elm", BLK_DEV_NAME) == 0) { if (dfs_mount(BLK_DEV_NAME, "/", "elm", 0, 0) == 0) { rt_kprintf(BLK_DEV_NAME" mount to '/'\n"); } else { rt_kprintf(BLK_DEV_NAME" mount to '/' failed!\n"); } } else { rt_kprintf(BLK_DEV_NAME" mkfs failed!"); } } return 0; } int mount_init(void) { #ifdef RT_USING_DFS_ROMFS /* 默认不使用ROMFS */ if (dfs_mount(RT_NULL, "/", "rom", 0, &(romfs_root)) != 0) { LOG_E("rom mount to '/' failed!"); } #endif #ifdef BSP_USING_SPI_FLASH_FS mnt_spi_flash_init(); /* 挂载 SPI Flash 为 根目录 */ #if 0 /* 以下为 lfs 挂载,注释掉 */ struct rt_device *flash_dev = RT_NULL; #ifndef RT_USING_WIFI fal_init(); #endif flash_dev = fal_mtd_nor_device_create("filesystem"); if (flash_dev) { //mount filesystem if (dfs_mount(flash_dev->parent.name, "/", "elm", 0, 0) != 0) { LOG_W("mount to '/' failed! try to mkfs %s", flash_dev->parent.name); dfs_mkfs("lfs", flash_dev->parent.name); if (dfs_mount(flash_dev->parent.name, "/flash", "lfs", 0, 0) == 0) { LOG_I("mount to '/flash' success!"); } } else { LOG_I("mount to '/flash' success!"); } } else { LOG_E("Can't create block device filesystem or bt_image partition."); } #endif #endif #ifdef BSP_USING_SDCARD_FS rt_thread_t tid; rt_pin_mode(SD_CHECK_PIN, PIN_MODE_INPUT_PULLUP); tid = rt_thread_create("sd_mount", sd_mount, RT_NULL, 2048, RT_THREAD_PRIORITY_MAX - 2, 20); if (tid != RT_NULL) { rt_thread_startup(tid); } else { LOG_E("create sd_mount thread err!"); } #endif return RT_EOK; } INIT_APP_EXPORT(mount_init); #endif /* BSP_USING_FS */
___ ______ _____ ______ _ ______ _____ _____ _____ / _ \ | ___ \|_ _| | ___ \(_) | ___ \/ _ \/ _ \|_ _| / /_\ \| |_/ / | | ______ | |_/ / _ | |_/ /| | | || | | | | | | _ || / | | |______|| __/ | | | ___ \| | | || | | | | | | | | || |\ \ | | | | | | | |_/ /\ \_/ /\ \_/ / | | \_| |_/\_| \_| \_/ \_| |_| \____/ \___/ \___/ \_/ Powered by RT-Thread. [D/drv.sdram] sdram init success, mapped at 0xC0000000, size is 33554432 bytes, data width is 16 \ | / - RT - Thread Operating System / | \ 4.1.0 build Mar 31 2022 23:53:12 2006 - 2022 Copyright by RT-Thread team [I/SFUD] Find a Winbond flash chip. Size is 16777216 bytes. [I/SFUD] norflash0 flash device is initialize success. [I/SFUD] Probe SPI flash norflash0 by SPI device spi10 success. [D/FAL] (fal_flash_init:47) Flash device | norflash0 | addr: 0x00000000 | len: 0x01000000 | blk_size: 0x00001000 |initialized finish. [I/FAL] ==================== FAL partition table ==================== [I/FAL] | name | flash_dev | offset | length | [I/FAL] ------------------------------------------------------------- [I/FAL] | wifi_image | norflash0 | 0x00000000 | 0x00080000 | [I/FAL] | bt_image | norflash0 | 0x00080000 | 0x00080000 | [I/FAL] | download | norflash0 | 0x00100000 | 0x00200000 | [I/FAL] | easyflash | norflash0 | 0x00300000 | 0x00100000 | [I/FAL] | filesystem | norflash0 | 0x00400000 | 0x00c00000 | [I/FAL] ============================================================= [I/FAL] RT-Thread Flash Abstraction Layer initialize success. [I/FAL] The FAL block device (filesystem) created successfully filesystem mount to '/'
sdk-bsp-stm32h750-realthread-artpi\projects\art_pi_bootloader
msh />df
disk free: 11.9 MB [ 3063 block, 4096 bytes per block ]
msh />ls Directory /: msh />mkdir logs msh />cd logs msh /logs>ls Directory /logs: msh /logs>echo aaa log.txt msh /logs>ls Directory /logs: log.txt 3 msh /logs>cat log.txt aaa msh /logs>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。