RT-Thread--片上 flash挂载 littlefs 文件系统

片上 flash挂载 littlefs 文件系统

平台 stm32l475-atk-pandora

使能片上 flash

RT-Thread--片上 flash挂载 littlefs 文件系统_第1张图片

使能 fal 软件包

RT-Thread--片上 flash挂载 littlefs 文件系统_第2张图片

使能 mtd

RT-Thread--片上 flash挂载 littlefs 文件系统_第3张图片

打开文件系统

RT-Thread--片上 flash挂载 littlefs 文件系统_第4张图片

使能 littlefs

RT-Thread--片上 flash挂载 littlefs 文件系统_第5张图片

fal_cfg.h


/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-04-28     tyustli      the first version
 */

#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_

#include 
#include 

extern const struct fal_flash_dev stm32_onchip_flash;

/* flash device table */
#define FAL_FLASH_DEV_TABLE                                          \
{                                                                    \
    &stm32_onchip_flash,                                             \
}
/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */
#define FAL_PART_TABLE                                                                                              \
{                                                                                                                   \
    {FAL_PART_MAGIC_WROD,        "app", "onchip_flash",                                    0,       128 * 1024, 0}, \
    {FAL_PART_MAGIC_WROD,      "filesystem", "onchip_flash",                      128 * 1024,       384 * 1024, 0}, \
}
#endif /* FAL_PART_HAS_TABLE_CFG */
#endif /* _FAL_CFG_H_ */

main.c

/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-04-28     tyustli      first version
 */

#include 
#include 
#include 

#define LED0_PIN    GET_PIN(E, 7)
#define FS_PARTITION_NAME  "filesystem"

#include "fal.h"
#include "dfs_file.h"

int main(int argc, char *argv[])
{
    fal_init();

    struct rt_device *flash_dev = fal_mtd_nor_device_create(FS_PARTITION_NAME);

    if (flash_dev == NULL)
    {
        rt_kprintf("Can't create a mtd device on '%s' partition.\n", FS_PARTITION_NAME);
    }
    else
    {
        rt_kprintf("Create a mtd device on the %s partition of flash successful.\n", FS_PARTITION_NAME);
    }

    if(rt_device_find(FS_PARTITION_NAME) != RT_NULL)
    {
        dfs_mkfs("lfs", FS_PARTITION_NAME);

        if (dfs_mount(FS_PARTITION_NAME, "/", "lfs", 0, 0) == RT_EOK)
        {
            rt_kprintf("onchip lfs filesystem mount to '/'\n");
        }
        else
        {
            rt_kprintf("onchip lfs filesystem mount to '/' failed!\n");
        }
    }
    else
    {
        rt_kprintf("find filesystem portion failed\r\n");
    }

    return RT_EOK;
}

效果展示

RT-Thread--片上 flash挂载 littlefs 文件系统_第6张图片

你可能感兴趣的:(RTOS)