芯科蓝牙BG27开发笔记8-片上Flash读写

news2024/10/5 15:34:23

目标

熟悉片上Flash的特点,知道如何使用,最好找到示例代码,有完整例程那是最好的

查找参考手册

除了768K的主空间,还包含:

1. USERDATA区域,用户定义数据,可以读写。大小只有1K。

2. 设备特性和识别信息的DEVINFO空间

3. 内部生产测试和校准信息的CHIPCONFIG。


RAM有两个部分:

RAM0:共64K,0x20000000 - 0x2000FFFF

SEQRAM:应该是RF状态机需要的,如果不使用RF,可以用作其他。

主flash,768K:

最小擦除单元1页,8K大小。

10K擦除寿命。

查找蓝牙api.h

目前不知道这该如何使用,暂且不考虑。


/**
 * @addtogroup sl_bt_nvm NVM
 * @{
 *
 * @brief NVM
 *
 * Provide an interface to manage user data objects (key/value pairs) in the
 * flash memory. User data stored within the flash memory is persistent across
 * reset and power cycling of the device. Because Bluetooth bondings are also
 * stored in the flash area, in addition to the flash storage size, the space
 * available for user data also depends on the number of bondings the device has
 * at the time.
 *
 * On EFR32[B|M]G1x devices, either PS Store or NVM3 data storage driver can be
 * used. PS Store is supported by the Bluetooth stack only. Using NVM3 is
 * recommended if the device needs to support Dynamic Multiple Protocol (DMP).
 * On EFR32[B|M]G2x devices, only NVM3 is supported. When NVM3 is used,
 * applications can also use the NVM3 APIs directly.
 *
 * In PS Store, the flash storage size is fixed at 2048 bytes. The maximum data
 * object size associated to a key is 56 bytes. A Bluetooth bonding uses at
 * maximum 138 bytes for secure connections and 174 bytes for legacy pairing.
 *
 * In NVM3, the flash store size is configurable and the minimum is 3 flash
 * pages. The maximum data object size is configurable up to 4096 bytes. A
 * Bluetooth bonding uses maximum 110 bytes for secure connections and 138 bytes
 * for legacy pairing. For more details, see AN1135 "Using Third Generation
 * NonVolatile Memory (NVM3) Data Storage".
 */

/* Command and Response IDs */
#define sl_bt_cmd_nvm_save_id                                        0x020d0020
#define sl_bt_cmd_nvm_load_id                                        0x030d0020
#define sl_bt_cmd_nvm_erase_id                                       0x040d0020
#define sl_bt_cmd_nvm_erase_all_id                                   0x010d0020
#define sl_bt_rsp_nvm_save_id                                        0x020d0020
#define sl_bt_rsp_nvm_load_id                                        0x030d0020
#define sl_bt_rsp_nvm_erase_id                                       0x040d0020
#define sl_bt_rsp_nvm_erase_all_id                                   0x010d0020

/**
 * @addtogroup sl_bt_nvm_keys Defined Keys
 * @{
 *
 * Define keys
 */

/** Crystal tuning value override */
#define SL_BT_NVM_KEY_CTUNE 0x32      

/** @} */ // end Defined Keys

/***************************************************************************//**
 *
 * Store a value into the specified NVM key. Allowed NVM keys are in range from
 * 0x4000 to 0x407F. At most, 56 bytes user data can be stored in one NVM key.
 * The error code 0x018a (command_too_long) is returned if the value data is
 * more than 56 bytes.
 *
 * @param[in] key NVM key
 * @param[in] value_len Length of data in @p value
 * @param[in] value Value to store into the specified NVM key
 *
 * @return SL_STATUS_OK if successful. Error code otherwise.
 *
 ******************************************************************************/
sl_status_t sl_bt_nvm_save(uint16_t key,
                           size_t value_len,
                           const uint8_t* value);

/***************************************************************************//**
 *
 * Retrieve the value of the specified NVM key.
 *
 * @param[in] key NVM key of the value to be retrieved
 * @param[in] max_value_size Size of output buffer passed in @p value
 * @param[out] value_len On return, set to the length of output data written to
 *   @p value
 * @param[out] value The returned value of the specified NVM key
 *
 * @return SL_STATUS_OK if successful. Error code otherwise.
 *
 ******************************************************************************/
sl_status_t sl_bt_nvm_load(uint16_t key,
                           size_t max_value_size,
                           size_t *value_len,
                           uint8_t *value);

/***************************************************************************//**
 *
 * Delete a single NVM key and its value from the persistent store.
 *
 * @param[in] key NVM key to delete
 *
 * @return SL_STATUS_OK if successful. Error code otherwise.
 *
 ******************************************************************************/
sl_status_t sl_bt_nvm_erase(uint16_t key);

/***************************************************************************//**
 *
 * Delete all NVM keys and their corresponding values.
 *
 *
 * @return SL_STATUS_OK if successful. Error code otherwise.
 *
 ******************************************************************************/
sl_status_t sl_bt_nvm_erase_all();

/** @} */ // end addtogroup sl_bt_nvm

在ssv5的文档中搜索“flash”:

找到两篇文档:

ug103-07-non-volatile-data-storage-fundamentals-断电存储

an1135-using-third-generation-nonvolatile-memory-NVM3使用方法

上图有多个flash操作库,但是BG27只能选择NVM3。如何使用NVM3在文档中有说明,不过为什么就没有一个简单的例程直接开箱即用呢???

查阅文档:

NVM3 - NVM Data Manager - v3.1 - Gecko Platform API Documentation Silicon Labs

结合A1115文档阅读;

以上文档说明已很充足,上图examples中也有少量代码:

【Example 1 shows initialization, usage of data objects and repacking.】

#include "nvm3.h"
#include "nvm3_hal_flash.h"
 
// Create a NVM area of 24kB (size must equal N * FLASH_PAGE_SIZE, N is integer). Create a cache of 10 entries.
NVM3_DEFINE_SECTION_STATIC_DATA(nvm3Data1, 24576, 10);
 
// This macro creates the following:
// 1. An array to hold NVM data named nvm3Data1_nvm
// 2. A section called nvm3Data1_section containing nvm3Data1_nvm. The application linker script must place this section correctly in memory.
// 3. A cache array: nvm3Data1_cache
 
void nvm3_example_1(void)
{
  // Declare a nvm3_Init_t struct of name nvm3Data1 with initialization data. This is passed to nvm3_open() below.
  NVM3_DEFINE_SECTION_INIT_DATA(nvm3Data1, &nvm3_halFlashHandle);
 
  nvm3_Handle_t handle;
  Ecode_t status;
  size_t numberOfObjects;
  unsigned char data1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  unsigned char data2[] = { 11, 12, 13, 14, 15 };
  uint32_t objectType;
  size_t dataLen1;
  size_t dataLen2;
 
  status = nvm3_open(&handle, &nvm3Data1);
  if (status != ECODE_NVM3_OK) {
    // Handle error
  }
 
  // Get the number of valid keys already in NVM3
  numberOfObjects = nvm3_countObjects(&handle);
 
  // Skip if we have initial keys. If not, generate objects and store
  // persistently in NVM3 before proceeding.
  if (numberOfObjects < 2) {
    // Erase all objects and write initial data to NVM3
    nvm3_eraseAll(&handle);
    nvm3_writeData(&handle, 1, data1, sizeof(data1));
    nvm3_writeData(&handle, 2, data2, sizeof(data2));
  }
 
  // Find size of data for object with key identifier 1 and 2 and read out
  nvm3_getObjectInfo(&handle, 1, &objectType, &dataLen1);
  if (objectType == NVM3_OBJECTTYPE_DATA) {
    nvm3_readData(&handle, 1, data1, dataLen1);
  }
  nvm3_getObjectInfo(&handle, 2, &objectType, &dataLen2);
  if (objectType == NVM3_OBJECTTYPE_DATA) {
    nvm3_readData(&handle, 2, data2, dataLen2);
  }
 
  // Update and write back data
  data1[0]++;
  data2[0]++;
  nvm3_writeData(&handle, 1, data1, dataLen1);
  nvm3_writeData(&handle, 2, data2, dataLen2);
 
  // Do repacking if needed
  if (nvm3_repackNeeded(&handle)) {
    status = nvm3_repack(&handle);
    if (status != ECODE_NVM3_OK) {
      // Handle error
    }
  }
}

【Example 2 shows initialization and usage of counter objects. The counter object uses a compact way of storing a 32-bit counter value while minimizing NVM wear.】

#include "nvm3.h"
#include "nvm3_hal_flash.h"
 
// Create a NVM area of 24kB (size must equal N * FLASH_PAGE_SIZE, N is integer). Create a cache of 10 entries.
NVM3_DEFINE_SECTION_STATIC_DATA(nvm3Data2, 24576, 10);
 
#define USER_KEY        1
 
// This macro creates the following:
// 1. An array to hold NVM data named nvm3Data2_nvm
// 2. A section called nvm3Data2_section containing nvm3Data2_nvm. The application linker script must place this section correctly in memory.
// 3. A cache array: nvm3Data2_cache
 
void nvm3_example_2(void)
{
  // Declare a nvm3_Init_t struct of name nvm3Data2 with initialization data. This is passed to nvm3_open() below.
  NVM3_DEFINE_SECTION_INIT_DATA(nvm3Data2, &nvm3_halFlashHandle);
 
  nvm3_Handle_t handle;
  Ecode_t status;
  uint32_t counter = 1;
 
  status = nvm3_open(&handle, &nvm3Data2);
  if (status != ECODE_NVM3_OK) {
    // Handle error
  }
 
  // Erase all objects
  nvm3_eraseAll(&handle);
 
  // Write first counter value with key 1
  nvm3_writeCounter(&handle, USER_KEY, counter);
 
  // Increment the counter by 1 without reading out the updated value
  nvm3_incrementCounter(&handle, USER_KEY, NULL);
 
  // Read the counter value
  nvm3_readCounter(&handle, USER_KEY, &counter);
}

找到现成的示例

可以通过检索关键词来查找使用到nvm3接口的代码,是否有一个完整例程存在?

检索词可以用,nvm3_open,nvm3_readData

但是前提是,要有例程源码存在。

一般情况,如nordic,提供了例程包,例程分为两部分:

1. 裸机例程

2. 蓝牙应用例程

在此之前,我认为芯科的例程是在ssv5 IDE中,需要自己创建才会自动生成;还有技术支持(第三方)发了一个裸机驱动包,这个我知道都是芯科官方github上有的。

经过查找,参考本帖《补充资料》,可知两个包的地址:

GitHub - SiliconLabs/bluetooth_applications: Bluetooth wireless applications. Go to https://github.com/SiliconLabs/application_examples

GitHub - SiliconLabs/peripheral_examples: Simple peripheral examples for Silicon Labs EFM32/EFR32 Series 0, Series 1, and Series 2 devices

在蓝牙例程文件夹检索关键词,选定蓝牙温控器这个例程继续阅读:

补充资料

SDK的API文档:

Gecko Platform - v3.1 - Gecko Platform API Documentation Silicon Labs

蓝牙协议栈API文档:

General Overview - v4.0 - Bluetooth API Documentation Silicon Labs

这两份文档内容很多,也很系统,有助于理解一些基本的概念。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1012699.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

长胜证券:十大流通股东占比例高好还是低好?

近年来&#xff0c;跟着我国本钱商场的不断发展&#xff0c;越来越多的投资者开始了解和关注股东占比这个目标。而在股东占比中&#xff0c;十大流转股东的持股份额是一个重要的目标。可是&#xff0c;关于投资者来说&#xff0c;十大流转股东占比是高好还是低好&#xff1f;本…

【SPI读取外部Flash】使用逻辑分析仪来读取FLASH Device ID

实验设备&#xff1a;25块钱的 逻辑分析仪 和 野火F429开发板 注意点&#xff0c;这个逻辑分析仪最大只能检测24M的波形&#xff0c;而SPI是在外部通道2&#xff0c;所以我们对系统时钟的分频&#xff0c;也就是给到通道2的时钟速度要在24M内&#xff0c;不然检测到的数据是有…

Peppertype.ai:人工智能内容营销平台

【产品介绍】 名称 Peppertype.ai 具体描述 Peppertype.ai是一个AI驱动的文章生成工具&#xff0c;可以帮助你在几秒钟内为各种渠道创建吸引人 的内容。无论你是想要写广告文案、社交媒体标题、博客大纲还是网站内容&#xff0c;Peppertype…

C++ PrimerPlus 复习 第五章 循环和关系表达式

第一章 命令编译链接文件 make文件 第二章 进入c 第三章 处理数据 第四章 复合类型 &#xff08;上&#xff09; 第四章 复合类型 &#xff08;下&#xff09; 第五章 循环和关系表达式 文章目录 for循环&#xff1b;基本语法重要问题和解答 基于范围的for循环&#xff08…

中秋学习Qt6

中秋学习Qt6 【1】Qt6 新增的模块【2】Qt6剔除模块和方法【3】Qt6改进 【1】Qt6 新增的模块 Qt6引入了一些新的模块&#xff0c;以便提供更多的功能和改进。以下是一些Qt6新增的模块&#xff1a; QtQuick3D&#xff1a;Qt6引入了全新的3D引擎模块QtQuick3D&#xff0c;它提供了…

脚本:python绘制七夕爱心

文章目录 效果脚本Reference 效果 脚本 import random from math import sin, cos, pi, log from tkinter import *CANVAS_WIDTH 640 # 画布的宽 CANVAS_HEIGHT 640 # 画布的高 CANVAS_CENTER_X CANVAS_WIDTH / 2 # 画布中心的X轴坐标 CANVAS_CENTER_Y CANVAS_HEIGHT /…

ABB 1TGE120010R1300 控制主板模块

ABB 1TGE120010R1300 控制主板模块是一种用于控制和监测电力设备的模块&#xff0c;具有以下功能&#xff1a; 控制和监测电力设备&#xff1a;该模块可以通过与电力设备连接来控制和监测设备的性能和状态&#xff0c;例如启停设备、调节电压和功率等。 通信功能&#xff1a;该…

学Python的漫画漫步进阶 -- 第十六步

学Python的漫画漫步进阶 -- 第十六步 十六、多线程16.1 线程相关的知识16.1.1 进程16.1.2 线程16.1.3 主线程 16.2 线程模块——threading16.3 创建子线程16.3.1 自定义函数实现线程体16.3.2 自定义线程类实现线程体 16.4 线程管理16.4.1 等待线程结束16.4.2 线程停止 16.5 动动…

【ant-design-vue】ant-design-vue在uniapp使用时,auto-import失败报错

前言 在我的 uniapp vue3 vite 项目中&#xff0c;使用了 ant-design-vue 4.x 组件库&#xff0c;同时我还使用了 vite 插件 auto-import 用于自动导入vue3的组合式api。当我全局引用antd-vue时&#xff0c;开发模式下可以正常运行&#xff0c;却不能 npm run build 正常打包…

港联证券:“保险+期货”快速落地生花 涉及品种累计达18个

从普洱火车站出发&#xff0c;乘车3小时40分钟&#xff0c;经过250公里山路之后&#xff0c;能够到达云南西南边境的孟连县。孟连县全称孟连傣族拉祜族佤族自治县&#xff0c;“孟连”音自傣语&#xff0c;意为“寻找到的好地方”。这里属亚热带气候&#xff0c;热区资源丰富&a…

与社交媒体结合:视频直播美颜sdk在社交平台上的应用

为了让直播内容更吸引人&#xff0c;视频直播美颜sdk&#xff08;Software Development Kit&#xff09;正逐渐崭露头角&#xff0c;为社交媒体用户提供了卓越的美颜效果和互动体验。 一、什么是视频直播美颜sdk&#xff1f; 在深入讨论如何将视频直播美颜sdk整合到社交媒体平…

vue2 项目中嵌入视频

案例&#xff1a; 代码&#xff1a; <template><div class"schematicDiagramIndex"><el-container><el-aside width"20rem"><!-- <h4 style"font-size: 18px">视频演示</h4>--><div style…

低代码平台:通过可视化的开发工具和组件库,可快速地构建应用程序,从而实现快速迭代和升级

概述&#xff1a; 低代码是一种新兴的应用程序开发方式&#xff0c;无需编码或通过少量代码就可以快速生成应用程序的开发平台。通过可视化的开发工具和组件库&#xff0c;使得开发人员可以快速地构建应用程序&#xff0c;从而实现快速迭代和升级。 低代码平台的出现是为了解…

Centos 7.4 系统,使用wireshark 抓包,获取数据包来源IP(生产环境测试可用)

1 安装wireshark yum install wireshark &#xff08;也可以使用rpm包安装&#xff0c;但是依赖包较多&#xff0c;安装可能需要多一点时间&#xff09; 2 安装完后&#xff0c;抓取数据包 tshark -i ens192 -Y "ip.dst 192.168.120.59 and tcp.dstport 4006 and fra…

微信小程序Snapshot导出海报

开启skyline app.json "lazyCodeLoading": "requiredComponents","renderer": "skyline","componentFramework": "glass-easel","rendererOptions": {"skyline": {"defaultDisplayBlo…

cuda以及pytorch安装

安装CUDA显卡驱动 这篇博客已经超级详细&#xff0c;具体就不在闭门造车了&#xff01; 最简单、实用的cuda安装教程&#xff01;&#xff01;&#xff01;&#xff08;nvidia官方渠道下载&#xff09; 检测CUDA版本&#xff08;cmd窗口命令行下&#xff09; nvidia-sminvcc…

MySQL 用户账号管理(Accounts Management)

用户需要通过账号连接到MySQL Server&#xff0c;本文总结了MySQL账号的常用管理操作。 目录 一、用户账号简介 二、账号创建 三、账号权限管理 3.1 权限赋予与回收 3.1.1 库级赋权 3.1.2 表级赋权 3.1.3 列级赋权 3.1.4 存储过程和函数赋权 3.1.5 权限查询 3.1.6 权限回收 3.2…

SpringMVC自定义注解---[详细介绍]

一&#xff0c;对于SpringMVC自定义注解概念 是一种特殊的 Java 注解&#xff0c;它允许开发者在代码中添加自定义的元数据&#xff0c;并且可以在运行时使用反射机制来获取和处理这些信息。在 Spring MVC 中&#xff0c;自定义注解通常用于定义控制器、请求处理方法、参数或者…

Linux CentOS7系统运行级别

运行级别就是Linux操作系统当前正在运行的功能级别。在早期系统设置中&#xff0c;共设有七个运行级别&#xff0c;编号从0到6。系统可以引导到任何给定的运行级别。 每个运行级别指定不同的系统配置&#xff0c;并允许访问不同的进程组合。默认情况下&#xff0c;Linux会引导…

[C++ 网络协议] 多种I/O函数

1. Linux的send&recv函数 1.1 send函数和recv函数 #include <sys/socket.h> ssize_t send( int sockfd, //套接字文件描述符 const void* buf, //保存待传输数据的缓冲地址值 size_t nbytes, //待传输的字节数 int flags …