【OpenCPU】MN316-DLVD丨Flash使用介绍

菩禔看科技 2024-04-23 03:06:33

在MN316 标准版SDK中,定义了操作模组内置flash接口,用户可操作空间为64KB,分为16个block,每个block大小为4KB。用户如有操作flash的需求,可调用相关接口。

一、FOTA使用流程解析

以下流程图为使用MN316OpenCPU SDK flash功能时的常见流程。

关于Flash功能的各种接口,可在SDK中include\cmiot\cm_flash.h查看;

关于Flash Demo示例,可在SDK中examples\flash\cm_demo_flash.c查看。

图1 flash测试流程图

二、Flash 接口介绍与demo解析

1、Flash信息结构体

flash包含块的数量,和单块空间大小。

图2 flash_info结构体变量

2、获取flash信息接口:

此接口可以获取内置flash相关信息。信息可以参考cm_flash_info_t结构体内容,flash包含的块数为16块,每个块的大小为4KB。

图3 获取flash_info的接口

3、Flash擦除接口:

此接口可以擦除flash内容,按块擦除,每个块的大小为4KB,执行成功返回0。

图4 flash擦除接口

3、Flash写数据接口:

此接口用于往flash里写数据,可直接调用,不需提前擦除flash。

参数addr:数据写入的地址;

参数buf:待写入数据的首地址;

参数Size:待写入数据的长度。

执行成功后返回实际写入长度。

图5 flash写数据接口

4、Flash读数据接口:

此接口用于从flash里读数据。

参数addr:数据读取的地址:

参数buf:数据读取的缓存地址,需要分配内存。

参数Size:读取数据的长度。

图6 flash读数据接口

三、Flash demo 演示

定义写入字符串,分配读取内存,打印开始标志位,写入待测字符串,后读取刚写入字符串。

图7demo演示对flash写和读的功能

打印读取字符串,释放内存,擦除flash。

图8释放flash读数据内存,擦除已写数据

SDK中使用命令行输入build dlvd_h0 demo,logview工具合并生成demo固件后烧写到被测模组中,上电后DEMO程序开始运行,待AT串口输出please input cmds:输入测试flash指令:CM:FLASH调用cm_test_flash函数。测试结果如下所示:

图9运行测试flash demo例程,模组串口打印

需要使用模组内置flash功能的用户可以参考以上代码流程,以上便是flash相关demo的代码解析及应用介绍。





转载自中移物联网,仅供模组品牌对应于中移物联网模组体系参考。

声明:《菩禔物联》所发表内容均为原创,所有原创内容仅用于交流,不代表任何立场和观点。极少数优才文章注明来源的,版权归原出处所有(无法查证版权的或未注明出处的均来源于网络搜集)。如有侵权,请联系我们删除或更改。内容的真实性、准确性和合法性由原作者负责。转载内容(视频、文章、广告等)只以信息传播为目的,仅供参考,不代表本平台认同其观点和立场。

The content published in the Bodhi Union of Things is original, and all original content is for communication purposes only and does not represent any position or viewpoint. A very small number of excellent talent articles indicate their source, and the copyright belongs to the original source (those that cannot be verified or whose source is not indicated are all collected online). If there is any infringement, please contact us to delete or make changes. The authenticity, accuracy, and legality of the content are the responsibility of the original author. The reprinted content (videos, articles, advertisements, etc.) is only for the purpose of information dissemination and is for reference only. It does not mean that this platform agrees with its views and positions.

0 阅读:0

菩禔看科技

简介:感谢大家的关注