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

上期带大家了解了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文件。
移植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 1024static 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 name); ret = -1;return ret; } rt_kprintf(erase (%s) partition finish!, partiton_name);/* read the specified partition and check data */for (i = 0; i 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 name); ret = -1;return ret; }for(j = 0; j len - i) > buf_size ? buf_size : (partition->len - i); ret = fal_partition_write(partition, i, buf, len);if (ret 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 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 name); ret = -1;return ret; }for(j = 0; j = 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测试结果
打开串口助手,输入命令: msh />easyflash_sample
复制代码
第一次命令调用:第二次reset开发板后调用:
结语
至此,fal分区管理easyflash变量管理已经全部介绍完毕了,经历从移植软件模拟spi框架到lpc55s69,到移植过程中不断遇到的问题,解决问题并提供应用示例,并完成开发日记、开发笔记及应用教学,作者坦言整个过程还是受益良多的。希望大家怀揣着一颗求知及授学之心,共同建设好这个领域! 参考资料:
iot-os之rt-thread(十一)--- fal分区管理与easyflash变量管理
rt-thread文档中心:fal组件
本文转载自:   end
    更多恩智浦ai-iot市场和产品信息,邀您同时关注“nxp客栈”微信公众号
      nxp客栈
恩智浦致力于打造安全的连接和基础设施解决方案,为智慧生活保驾护航。
        长按二维码,关注我们
恩智浦mcu加油站
这是由恩智浦官方运营的公众号,着重为您推荐恩智浦mcu的产品信息、开发技巧、教程文档、培训课程等内容。
  长按二维码,关注我们
原文标题:【lpc55s69】使用fal分区管理与easyflash变量管理(下集)
文章出处:【微信公众号:恩智浦mcu加油站】欢迎添加关注!文章转载请注明出处。

Motor-CAD最新版本的NVH功能介绍
讨论一下平台与各种“流”的关系
Eta Compute的Tensai Flow将机器学习置于物联网的边缘
智能手机拍照的质量会受到哪些因素的影响
2020年数据科学领域的四种发展趋势
【LPC55S69】使用FAL分区管理与easyflash变量管理(下集)
CMOS 磁传感器结构:AEAT-6600-T16
高速热电偶的应用事项
革命性的可穿戴式触感VR设备
区块链身上的神秘吸引力究竟在哪?
关于verilog中的无符号数和有符号数
荣耀V9怎么样?荣耀V9评测:华为荣耀V9颜值性能给力,功能也不示弱两个功能大大增加用机体验
高精度工业环路供电的传感器变送器:蒙特雷子系统参考设计
基于CX88168、CX20463和CX20437芯片实现高速MODEM的设计
夏普2016年度财务将获利400亿日元
基于Matlab的高功率因数校正技术的仿真
为什么需要直流稳压电源?
集成碲镉汞长波320×256偏振探测器的设计
如何将MAXQ2000用作电压表
电池模拟器的功能及应用