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

2023-09-15 14:53:08

目标

熟悉片上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

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

nvm3资料汇总

参考三份资料:

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

《ug103-07-non-volatile-data-storage-fundamentals.pdf》

《an1135-using-third-generation-nonvolatile-memory.pdf》

《nvm3_generic.h》末尾文档,与第一个在线文档类似

补充资料

SDK的API文档:

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

蓝牙协议栈API文档:

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

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

更多推荐

Maven

目录Maven安装及配置使用IDEA创建Maven项目MavenPOM​编辑什么是Maven?Maven是一个Java项目管理和构建工具,它可以定义项目结构、项目依赖,并使用统一的方式进行自动化构建,是Java项目不可缺少的工具。主要作用?Maven就是是专门为Java项目打造的管理和构建工具,它的主要功能有:标准化的

实用!Python大型Excel文件处理:快速导入、导出与批量处理

Python是一种功能强大的编程语言,它提供了丰富的库和工具,使得处理大型Excel文件变得容易和高效。下面将介绍如何使用Python快速导入、导出和批量处理大型Excel文件。下面是一些建议和实践经验,希望能对你有所帮助。一、Excel文件处理库的选择在开始之前,我们需要选择一个适合处理Excel文件的库。以下是一些

【React】单页面应用限制多开登录

react单页面应用限制多开登录情景测试小姐姐提了一个BUG:在同一浏览器中打开两个页面,两个页面分别登录不同的账号.A页面先登录A,B页面再登录B,此时回到A页面,交互时账号数据应该刷新为B登录的账号分析这个问题,其实没什么必要,因为我不认为我们这个系统的单个使用者会同时拥有多个账号,但人家非说会有,那行吧,我说了不

ChatGPT批量写作文章软件

什么是ChatGPT批量写作文章。简单来说,它是一种使用ChatGPT技术的方法,可以帮助您批量生成各种类型的文章和内容。无论您是需要新闻报道、博客文章、产品描述、社交媒体帖子还是其他类型的内容,ChatGPT都能满足您的需求。它可以在极短的时间内为您生成大量文章,让您事半功倍。147GPT批量文章生成工具​www.1

linux动态扩容系统盘(非lvm磁盘)

查看磁盘状态执行df-Th查看磁盘情况[root@iotdbtest1~]#df-ThFilesystemTypeSizeUsedAvailUse%Mountedondevtmpfsdevtmpfs7.7G07.7G0%/devtmpfstmpfs7.7G07.7G0%/dev/shmtmpfstmpfs7.7G456

【CSS3】

文章目录1.简介2.边框3.圆角4.背景5.渐变CSS3径向渐变6.文本效果7.字体8.2D转换9.3D转换10.过渡11.动画12.多列13.用户界面14.按钮​1.简介模块CSS3被拆分为"模块"。旧规范已拆分成小块,还增加了新的。一些最重要CSS3模块如下:选择器盒模型背景和边框文字特效2D/3D转换动画多列布局

前端JavaScript Error 类: 异常处理与错误管理

🎬岸边的风:个人主页🔥个人专栏:《VUE》《javaScript》⛺️生活的理想,就是为了理想的生活!目录引言1.Error类简介2.Error类属性3.Error类的API4.Error类的应用场景5.自定义错误类型6.注意事项引言在JavaScript开发中,处理错误和异常是非常重要的。Error类是JavaS

一文快速创建前端react项目

目前React是最受欢迎和广泛使用的JavaScript库之一。许多知名的公司和组织都在使用React来构建它们的Web应用程序,包括Facebook,Netflix等。学习好React将会使你能够获得更多的就业机会和职业发展机会。要快速创建React项目,你可以使用CreateReactApp工具。CreateRea

【腾讯云国际站】CDN内容分发网络特性介绍

为什么使用腾讯云国际站CDN内容分发网络?当用户直接访问源站中的静态内容时,可能面临的体验问题:客户离服务器越远,访问速度越慢。客户数量越多,网络带宽费用越高。跨境用户访问体验较差。腾讯云国际站CDN如何改善您的网络体验:腾讯云国际站CDN缓存内容后,用户仅需要访问就近的CDN节点即可获取静态内容。缓解源站带宽压力,网

实现AIGC更好的数据存力,这家科技巨头为我们指明了方向

存力即数据存储能力蕴藏着巨大的发展机会【全球存储观察|热点关注】2023年,全球被ChatGPT的热潮席卷,拥抱AIGC的创新赛道成为众多企业的新选择。全球存储观察分析指出,影响AIGC发展的三大因素也日益凸显,即算力、存力与运力,算力即计算能力;存力即数据存储能力;运力即网络运载能力。而其中令业界越来越重视的存力,蕴

Linux——Shell脚本编程(2)

一、Shell变量LinuxShell中的变量分为,系统变量和用户自定义变量(这个用的比较多)。系统变量:$HOME、$PWD、$SHELL、$USER等等,比如:echo$HOME等等..显示当前shell中所有变量:set举例说明:二、设置环境变量记得在注释的时候,内容单独放在一块。位置参数变量注意此处的脚本中,确

热文推荐