RT-Thread / RT-Thread/rt-thread
After the partition in the external FLASH mounts the FAT file system, a delete folder can be created, but mkfs operations and read/write file operations cannot be performed
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
芯片:STM32F407ZGT6
工具链:arm-none-eabi-gcc
RT-Thread版本:RT-Thread v5.0.1
如题,基本条件和官方例程中一致,W25Q128被切分成了几个区,我目标是将filesystem区挂载为文件为文件系统根目录,挂载成功后能创建删除文件夹,但是无法进行mkfs操作和读写文件操作。
目前可以确认flash无硬件问题,我已测试从flash中读写数据和擦除flash操作。
控制台记录如下:
config如下:
Coder如下:
#include <rtthread.h>
#include <dfs_romfs.h>
#include <dfs_fs.h>
#include <dfs_file.h>
#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 "drv.fsystem"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>
#ifdef BSP_USING_SDCARD_FATFS
static int onboard_sdcard_mount(void)
{
if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
{
LOG_D("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
#include <fal.h>
#define FS_PARTITION_NAME "spiflash0"
static int onboard_spiflash_mount(void)
{
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);
}
if (dfs_mount(FS_PARTITION_NAME, "/spiflash", "lfs", 0, 0) == RT_EOK)
{
LOG_D("spi flash mount to '/spiflash'");
}
else
{
dfs_mkfs("lfs", FS_PARTITION_NAME);
if (dfs_mount(FS_PARTITION_NAME, "/spiflash", "lfs", 0, 0) == RT_EOK)
{
LOG_D("spi flash mount to '/spiflash'");
}
else
{
LOG_E("spi flash failed to mount to '/spiflash'");
}
}
return RT_EOK;
}
#endif /* BSP_USING_SPI_FLASH_LITTLEFS */
#ifdef BSP_USING_SPI_FLASH_FATFS
#include <fal.h>
#define FS_PARTITION_NAME "filesystem"
static int onboard_spiflash_mount(void)
{
struct rt_device *mtd_dev = RT_NULL;
fal_init();
mtd_dev = fal_blk_device_create(FS_PARTITION_NAME);
if (!mtd_dev)
{
LOG_E("Can't create a blk device on '%s' partition.", FS_PARTITION_NAME);
}
if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) == RT_EOK)
{
LOG_D("spi flash mount to '/'.");
}
else
{
dfs_mkfs("elm", FS_PARTITION_NAME);
if (dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) == RT_EOK)
{
LOG_D("spi flash mount to '/'.");
}
else
{
LOG_E("spi flash failed to mount to '/'.");
}
}
return RT_EOK;
}
#endif /* BSP_USING_SPI_FLASH_FATFS */
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
#ifdef BSP_USING_SPI_FLASH_FATFS
{ROMFS_DIRENT_DIR, "spiflash", RT_NULL, 0},
#endif
};
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
#ifdef BSP_USING_SPI_FLASH_FATFS
onboard_spiflash_mount();
#endif
return RT_EOK;
}
// INIT_APP_EXPORT(filesystem_mount);
MSH_CMD_EXPORT(filesystem_mount, filesystem mount);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at onboard_spiflash_mount in the provided code and trace the fal_blk_device_create, dfs_mount, and dfs_mkfs calls for the filesystem partition using the elm driver. Review the attached configuration and console records, then reproduce the FAT filesystem mount, mkfs, and file read/write operations on the STM32F407ZGT6 setup. Done means the reported operations work or the failure is narrowed to a specific component.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100