0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

【LPC55S69】使用FAL分区管理与easyflash变量管理(下集)

恩智浦MCU加油站 来源:未知 2023-06-29 09:05 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

上期带大家了解了FAL组件和DFS文件系统的功能特点和使用方法,本期将继续解读如何将EasyFlsh移植到FAL分区。

简述EasyFlash

关于EasyFlash的来源我们已经讲过,EasyFlash是一款开源的轻量级嵌入式Flash存储器库,方便开发者更加轻松的实现基于Flash存储器的常见应用开发。非常适合智能家居、可穿戴、工控、医疗、物联网等需要断电存储功能的产品,资源占用极低,支持各种 MCU 片上存储器。

EasyFlash不仅能够实现对产品的设定参数或运行日志等信息的掉电保存功能,还封装了简洁的增加、删除、修改及查询方法,降低了开发者对产品参数的处理难度,也保证了产品在后期升级时拥有更好的扩展性。让Flash变为NoSQL(非关系型数据库)模型的小型键值(Key-Value)存储数据库。

EasyFlash软件包使用

打开ENV进入路径:RT-Thread online packages → tools packages → EasyFlash: Lightweight embedded flash memory library.,选择软件包版本为最新版。配置后退出ENV,同时使用pkgs --update下载软件包,然后再使用scons-target=mdk5重新生成MDK5文件。

4936011e-1615-11ee-962d-dac502259ad0.png

移植EasyFlash

下载完easyflash软件包后,我们复制. t-threadsplpc55sxxlpc55s69_nxp_evkpackagesEasyFlash-latestportsef_fal_port.c到目录. t-threadsplpc55sxxlpc55s69_nxp_evkoardportseasyflashef_fal_port.c,双击打开该文件,完成以下修改:

// 修改 FAL_EF_PART_NAME 为 easyflash
#define FAL_EF_PART_NAME               "easyflash"

编写EasyFlash测试用例

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


#include "rtthread.h"
#include "rtdevice.h"
#include "board.h"
#include "fal.h"


#include 


#include "easyflash.h"
#include 


#define FS_PARTITION_NAME  "filesystem"


#define BUF_SIZE 1024


static int fal_test(const char *partiton_name)
{
int ret;
int i, j, len;
uint8_t buf[BUF_SIZE];
const struct fal_flash_dev *flash_dev = RT_NULL;
const struct fal_partition *partition = RT_NULL;


if (!partiton_name)
     {
         rt_kprintf("Input param partition name is null!
");
return -1;
     }


     partition = fal_partition_find(partiton_name);
if (partition == RT_NULL)
     {
         rt_kprintf("Find partition (%s) failed!
", partiton_name);
         ret = -1;
return ret;
     }


     flash_dev = fal_flash_device_find(partition->flash_name);
if (flash_dev == RT_NULL)
     {
         rt_kprintf("Find flash device (%s) failed!
", partition->flash_name);
         ret = -1;
return ret;
     }


     rt_kprintf("Flash device : %s   "
"Flash size : %dK   
"
"Partition : %s   "
"Partition size: %dK
",
                 partition->flash_name,
                 flash_dev->len/1024,
                 partition->name,
                 partition->len/1024);


/* erase all partition */
     ret = fal_partition_erase_all(partition);
if (ret < 0)
     {
         rt_kprintf("Partition (%s) erase failed!
", partition->name);
         ret = -1;
return ret;
     }
     rt_kprintf("Erase (%s) partition finish!
", partiton_name);


/* read the specified partition and check data */
for (i = 0; i < partition->len;)
     {
         rt_memset(buf, 0x00, BUF_SIZE);


         len = (partition->len - i) > BUF_SIZE ? BUF_SIZE : (partition->len - i);


         ret = fal_partition_read(partition, i, buf, len);
if (ret < 0)
         {
             rt_kprintf("Partition (%s) read failed!
", partition->name);
             ret = -1;
return ret;
         }


for(j = 0; j < len; j++)
         {
if (buf[j] != 0xFF)
             {
                 rt_kprintf("The erase operation did not really succeed!
");
                 ret = -1;
return ret;
             }
         }
         i += len;
     }


/* write 0x00 to the specified partition */
for (i = 0; i < partition->len;)
     {
         rt_memset(buf, 0x00, BUF_SIZE);


         len = (partition->len - i) > BUF_SIZE ? BUF_SIZE : (partition->len - i);


         ret = fal_partition_write(partition, i, buf, len);
if (ret < 0)
         {
             rt_kprintf("Partition (%s) write failed!
", partition->name);
             ret = -1;
return ret;
         }


         i += len;
     }
     rt_kprintf("Write (%s) partition finish! Write size %d(%dK).
", partiton_name, i, i/1024);


/* read the specified partition and check data */
for (i = 0; i < partition->len;)
     {
         rt_memset(buf, 0xFF, BUF_SIZE);


         len = (partition->len - i) > BUF_SIZE ? BUF_SIZE : (partition->len - i);


         ret = fal_partition_read(partition, i, buf, len);
if (ret < 0)
         {
             rt_kprintf("Partition (%s) read failed!
", partition->name);
             ret = -1;
return ret;
         }


for(j = 0; j < len; j++)
         {
if (buf[j] != 0x00)
             {
                 rt_kprintf("The write operation did not really succeed!
");
                 ret = -1;
return ret;
             }
         }


         i += len;
     }


     ret = 0;
return ret;
}


static void fal_sample(void)
{
/* 1- init */
     fal_init();


if (fal_test("font") == 0)
     {
         rt_kprintf("Fal partition (%s) test success!
", "font");
     }
else
     {
         rt_kprintf("Fal partition (%s) test failed!
", "font");
     }


if (fal_test("download") == 0)
     {
         rt_kprintf("Fal partition (%s) test success!
", "download");
     }
else
     {
         rt_kprintf("Fal partition (%s) test failed!
", "download");
     }
}
MSH_CMD_EXPORT(fal_sample, fal sample);


static void fal_elmfat_sample(void)
{
int fd, size;
struct statfs elm_stat;
struct fal_blk_device *blk_dev;
char str[] = "elmfat mount to W25Q flash.", buf[80];


/* fal init */
     fal_init();


/* create block device */
     blk_dev = (struct fal_blk_device *)fal_blk_device_create(FS_PARTITION_NAME);
if(blk_dev == RT_NULL)
         rt_kprintf("Can't create a block device on '%s' partition.
", FS_PARTITION_NAME);
else
         rt_kprintf("Create a block device on the %s partition of flash successful.
", FS_PARTITION_NAME);


/* make a elmfat format filesystem */
if(dfs_mkfs("elm", FS_PARTITION_NAME) == 0)
         rt_kprintf("make elmfat filesystem success.
");


/* mount elmfat file system to FS_PARTITION_NAME */
if(dfs_mount(FS_PARTITION_NAME, "/", "elm", 0, 0) == 0)
         rt_kprintf("elmfat filesystem mount success.
");


/* Get elmfat file system statistics */
if(statfs("/", &elm_stat) == 0)
         rt_kprintf("elmfat filesystem block size: %d, total blocks: %d, free blocks: %d.
",
                     elm_stat.f_bsize, elm_stat.f_blocks, elm_stat.f_bfree);


if(mkdir("/user", 0x777) == 0)
         rt_kprintf("make a directory: '/user'.
");


     rt_kprintf("Write string '%s' to /user/test.txt.
", str);


/* Open the file in create and read-write mode, create the file if it does not exist*/
     fd = open("/user/test.txt", O_WRONLY | O_CREAT);
if (fd >= 0)
     {
if(write(fd, str, sizeof(str)) == sizeof(str))
             rt_kprintf("Write data done.
");


         close(fd);   
     }


/* Open file in read-only mode */
     fd = open("/user/test.txt", O_RDONLY);
if (fd >= 0)
     {
         size = read(fd, buf, sizeof(buf));


         close(fd);


if(size == sizeof(str))
             rt_kprintf("Read data from file test.txt(size: %d): %s 
", size, buf);
     }
}
MSH_CMD_EXPORT_ALIAS(fal_elmfat_sample, fal_elmfat,fal elmfat sample);


static void easyflash_sample(void)
{
/* fal init */
     fal_init();


/* easyflash init */
if(easyflash_init() == EF_NO_ERR)
     {
uint32_t i_boot_times = NULL;
char *c_old_boot_times, c_new_boot_times[11] = {0};


/* get the boot count number from Env */
         c_old_boot_times = ef_get_env("boot_times");
/* get the boot count number failed */
if (c_old_boot_times == RT_NULL)
             c_old_boot_times[0] = '0';


         i_boot_times = atol(c_old_boot_times);
/* boot count +1 */
         i_boot_times ++;
         rt_kprintf("===============================================
");
         rt_kprintf("The system now boot %d times
", i_boot_times);
         rt_kprintf("===============================================
");
/* interger to string */
sprintf(c_new_boot_times, "%d", i_boot_times);
/* set and store the boot count number to Env */
         ef_set_env("boot_times", c_new_boot_times);
         ef_save_env();
     }
}
MSH_CMD_EXPORT(easyflash_sample, easyflash sample);

EasyFlash测试结果

打开串口助手,输入命令:
  1. msh />easyflash_sample

复制代码

第一次命令调用:49613442-1615-11ee-962d-dac502259ad0.png第二次RESET开发板后调用:

498e3712-1615-11ee-962d-dac502259ad0.png

结语

至此,FAL分区管理EasyFlash变量管理已经全部介绍完毕了,经历从移植软件模拟SPI框架到LPC55S69,到移植过程中不断遇到的问题,解决问题并提供应用示例,并完成开发日记、开发笔记及应用教学,作者坦言整个过程还是受益良多的。希望大家怀揣着一颗求知及授学之心,共同建设好这个领域!

参考资料:

  • IOT-OS之RT-Thread(十一)--- FAL分区管理与easyflash变量管理

  • RT-Thread文档中心:FAL组件

本文转载自:

END

更多恩智浦AI-IoT市场和产品信息,邀您同时关注“NXP客栈”微信公众号

49c10750-1615-11ee-962d-dac502259ad0.jpg      

NXP客栈


恩智浦致力于打造安全的连接和基础设施解决方案,为智慧生活保驾护航。

长按二维码,关注我们

恩智浦MCU加油站


这是由恩智浦官方运营的公众号,着重为您推荐恩智浦MCU的产品信息、开发技巧、教程文档、培训课程等内容。

49d4e6b2-1615-11ee-962d-dac502259ad0.jpg  

长按二维码,关注我们


原文标题:【LPC55S69】使用FAL分区管理与easyflash变量管理(下集)

文章出处:【微信公众号:恩智浦MCU加油站】欢迎添加关注!文章转载请注明出处。


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • mcu
    mcu
    +关注

    关注

    147

    文章

    19257

    浏览量

    405239
  • 恩智浦
    +关注

    关注

    14

    文章

    6144

    浏览量

    155290

原文标题:【LPC55S69】使用FAL分区管理与easyflash变量管理(下集)

文章出处:【微信号:NXP_SMART_HARDWARE,微信公众号:恩智浦MCU加油站】欢迎添加关注!文章转载请注明出处。

收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    NXP KW45B41Z-EVK 板将 J-Link/CMSIS-DAP 固件刷新到板上的问题求解

    系统 使用 LQFP100 或 BGA98 封装的LPC55S16或LPC55S69。 尽管固件可以编程到板载的 MCU-Link 和 MCU-Link 使用LPC55S69 LQFP64 软件包的系统
    发表于 05-26 06:01

    有关 keyboard2mouse 示例的问题求解

    ; LPCIP3511HS <--> LPC55S69 <--> OHCI <--> Keyboard 但我想将作模式修改为: PC
    发表于 04-28 07:54

    从 FRAM 读取数据期间 I2C 通信卡住了,怎么解决?

    我最近开始在控制器上工作LPC55S69我正在尝试通过 I2C 总线从 FRAM 读取数据。但是有时我面临从 FRAM 读取数据的问题,因为我的代码在读取数据时卡住了。我已经配置了 I2C 超时
    发表于 04-23 06:56

    为什么无法在 LPC55S36 上使用 BLHost 转储代码(两块板上的 USB 连接问题)?

    。 设置详细信息: 工具:BLHost 2.6.7 主机作系统:Windows 10 连接:USB 电缆(在设备管理器中检测到 COM 端口) 目标:LPC55S36 MCU 驱动程序:已安装并验证
    发表于 04-17 10:04

    使用 LPC55S69 和 MCUX 驱动程序的 CDC 应该实现什么样的吞吐量?

    我有一块基于LPC55S69的板,该板目前具有一个以太网接口,可传输大约 800 kbps 的数据(在任一方向上,但双向总数应保持大致相同。客户想看看我们是否可以取消以太网接口,而是通过 USB
    发表于 04-16 09:20

    无法获得在 StarFive 上运行的 StarFive Linux 映像的 5569 版本,怎么解决?

    我是 VisionFive 2 的超级早鸟支持者,我无法获得在 StarFive 上运行的 StarFive Linux 映像的 5569 版本。绿色 LED 永远不会亮起。我尝试过使用此方法
    发表于 03-20 07:39

    Linux磁盘管理指令合集:从查看、分区到修复

    在 Linux 服务器运维或日常使用中,磁盘管理是高频操作 —— 无论是排查磁盘空间不足的问题,还是新增硬盘后的分区配置,都离不开一系列核心指令。今天就为大家整理一份「Linux 磁盘管理指令操作集」,按功能分类讲解,附带示例和
    的头像 发表于 02-03 16:07 3993次阅读
    Linux磁盘<b class='flag-5'>管理</b>指令合集:从查看、<b class='flag-5'>分区</b>到修复

    城市用水分区计量管理系统方案

    浪费,增加供水企业运营成本,也难以精准响应不同区域的用水需求,影响供水服务质量与居民用水体验。 为此,物通博联以工业数采网关为核心,构建城市用水分区计量管理系统,实现对城市各区域用水数据的实时采集、动态监控、
    的头像 发表于 09-09 10:37 804次阅读
    城市用水<b class='flag-5'>分区</b>计量<b class='flag-5'>管理</b>系统方案

    【PCA9958HN-ARD】GUI工具的使用

    :PCA9958HN-ARD评估板快速入门 | NXP 半导体),里面包含GUI上位机软件的安装包和LPC55S69开发板的固件。 然后,点击setup.exe,进行GUI上位机软件的安装,安装
    发表于 06-29 10:07

    Linux系统中磁盘分区与挂载详解

    磁盘分区是将物理硬盘划分为不同的逻辑部分,每个分区都可以被视为一个独立的存储设备。通过磁盘分区,我们可以更好地管理磁盘空间,实现数据的组织和隔离。
    的头像 发表于 06-17 15:08 2844次阅读
    Linux系统中磁盘<b class='flag-5'>分区</b>与挂载详解

    警用装备管理系统DW-S304,对警用装备的全生命周期追踪管理.

    管理系统
    jf_85364936
    发布于 :2025年06月15日 09:19:54