Zigbee persistent data management and non-volatile memory

Revision as of 17:03, 6 March 2023 by Registered User
Under construction.png Coming soon

1. Introduction

In a Zigbee network, if a node is turned off due to power shutdown or any other reason, the network data stored in its RAM will be lost. This can result in the loss of important information and can affect the functioning of the network. For that, we need to store some type of data, that we call Persistent Data, in a Non-Volatile Memory (NVM). These data might be network settings, security keys, and other configuration information.
The STM32WB storage in Flash memory is done by the mean of dedicated persistent data APIs that we will describe in this wiki.

2. Persistent Data Management

By saving critical data in NVM each time they change, the Zigbee network node can ensure that the data is always up-to-date and that the node can quickly recover from a power failure or other unexpected event. The end-user has 2 options:

  • Manually manages when to save data in NVM.
  • Relies on the stack notification.

If the end-user chooses to manage the saving of data in NVM himself, he will need to determine the appropriate time to call the save data function based on his specific use case and application requirements. On the other hand, if the end-user chooses to rely on the stack notifications, he can use these notifications as triggers to automatically save critical data in NVM, ensuring that the data is always up-to-date and persistent.

2.1. Stack Notification

The STM32WB ZigBee stack notifies the application each time persistent data change. First, the application must enable notification by registering persistent data change notification.

/* Register Persistent data change notification */
ZbPersistNotifyRegister(zigbee_app_info.zb, APP_ZIGBEE_persist_notify_cb, NULL);    

Once persistent data change notification is registered, end-user needs to implement the callback function to handle the notification. This function will be called each time there is a persistent data change in the Zigbee network.

/*
* @brief notify to save persistent data callback
* @param zb: zigbee context pointer, cbarg: callback arg pointer
* @retval: None
*/
static void APP_ZIGBEE_persist_notify_cb(struct ZigbeeT * zb, void *cbarg)
{
   APP_DBG("Notification to save persistent data requested from stack");
   /* Save the persistent data */
   APP_ZIGBEE_persist_save();
} 

In order to disable the notification, the application calls the stack API with NULL parameters:

/* Disable Notification */
ZbPersistNotifyRegister(zigbee_app_info.zb, NULL, NULL);  

2.2. Memory Mapping

As shown in the figure below, there are two APIs used to store and retrieve the persistent data:

  • The ZbPersistGet API allows to store in cache the persistent data.
  • The ZbStartupPersist API allows to retrieve persistent data from the Flash.
Memory Mapping
Connectivity NVM MemoryMapping.png

Note : Cluster attributes are not persistent data by default. It must be declared with ZCL_ATTR_FLAG_PERSISTABLE flag.

const struct ZbZclAttrT zcl_onoff_server_attr_list[] = 
{
    {
       ZCL_ONOFF_ATTR_ONOFF, ZCL_DATATYPE_BOOLEAN,
       ZCL_ATTR_FLAG_REPORTABLE|ZCL_ATTR_FLAG_PERSISTABLE, 0, NULL, {0, 0}, {0, 0}
    },
};  

user must declare the flash memory range in the scatter file for NVM


3. EEPROM Emulator

NVM is typically implemented using flash memory or EEPROM technology, which allows data to be written and rewritten many times, providing long-term data storage capabilities. In a Zigbee network, the EEPROM Emulator is made up of three parts: the EEPROM Emulation header, the NVN layer, and the application layer.

The STM32WB NVM uses the EEPROM emulator that impact the real size available for the persistent data. It is important to note that the available size of EEPROM Emulator is limited, and care should be taken to use this storage space efficiently to ensure the stable and reliable operation of the Zigbee network.
Basically, as shown in the figure below, we have a first header of 4 U64 words is taken for the page, and a second EE header for each record that sizes U32 words (2032 bytes). Thus, the remaining size per page for data is 2032 bytes.

Flash memory example with EEPROM Emulator
Connectivity NVM EE.png


4. NVM application example

An example is provided in STM32CubeWB MCU Package[1]. to do: figure qui explique le use case ce que montre le use case

5. References