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

片上 flash挂载 Fatfs 文件系统

平台 stm32l475-atk-pandora

使能片上 flash

在这里插入图片描述

使能 fal 软件包

在这里插入图片描述

使能 mtd

在这里插入图片描述

打开文件系统

在这里插入图片描述

Maxium sector size to be handled 需要根据实际情况进行设置,这里设置为 4096。

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 <rtthread.h>
#include <board.h>

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 <rtthread.h>
#include <rtdevice.h>
#include <board.h>

#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_blk_device_create(FS_PARTITION_NAME);

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

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

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

    return RT_EOK;
}

效果展示

在这里插入图片描述

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值