CN / EN
Doc Feedback
Thanks for your interest, welcome to contact us.
Thanks for your feedback

NVDS

NVDS is a lightweight logical data storage system based on Flash Hardware Abstract Layer (Flash HAL). NVDS is located in the Flash memory and data in it will not get lost in power-off status. By default, NVDS occupies the last sector of the Flash memory for storage.

NVDS is an ideal choice to store small data blocks, for example, application configuration parameters, calibration data, states, and user information. Bluetooth LE Stack will also store parameters (such as device binding information) in NVDS.

NVDS has the following characteristics:

  • Each storage item (TAG) has a unique TAG ID for identification. User applications can read and change data according to TAG IDs, regardless of physical storage addresses.
  • It is optimized based on medium characteristics of Flash memory and supports data check, word alignment, defragmentation, and erase balance.
  • The size and the start address of NVDS are configurable. The Flash memory is divided into sectors (4 KB/sector). NVDS can be configured as several sectors, and the configured start address shall be 4 KB-aligned.

NVDS provides the following five simple APIs to manipulate non-volatile data in Flash.

Table 2 NVDS APIs
Function Prototype Description

uint8_t nvds_init(uint32_t start_addr, uint8_t sectors)

Initialize the Flash sectors used by NVDS.

uint8_t nvds_get(NvdsTag_t tag, uint16_t *p_len, uint8_t *p_buf)

Read data according to TAG IDs from NVDS.

uint8_t nvds_put(NvdsTag_t tag, uint16_t len, const uint8_t *p_buf)

Write data to NVDS and mark the data with TAG IDs. If no TAG exists, create one.

uint8_t nvds_del(NvdsTag_t tag)

Remove the corresponding data of a TAG ID in NVDS.

uint16_t nvds_tag_length(NvdsTag_t tag)

Obtain the data length of a specified TAG.

For more information about NVDS APIs, see GR551x API Reference or the NVDS header file (available in SDK_Folder\components\sdk\gr55xx_nvds.h).

Figure 7 shows the format of the data stored in NVDS:

Figure 7 NVDS data format

Table 3 shows the data header format:

Table 3 Data header format
Byte Name Description
0–1 tag Data tag
2–3 len Data length
4–4 checksum Checksum of data header
5–5 value_cs Data checksum
6–7 reserved Reserved field
Note:

Bluetooth LE Stack also stores some parameters in NVDS. Therefore, it is required to allocate a Flash storage area to NVDS. By default, GR551x SDK uses the last sector of Flash memory for NVDS. You can modify macros NVDS_START_ADDR and NVDS_NUM_SECTOR in custom_config.h to configure the start address and the size of NVDS. Bluetooth LE Stack and applications share the same NVDS storage area. However, TAG ID namespace is divided into different categories. You can only use the TAG ID name category assigned to applications.

  • Applications have to use NV_TAG_APP(idx) to obtain the TAG ID of application data. The TAG ID is used as an NVDS API parameter.
  • Applications cannot use idx as the NVDS API parameter directly. The idx value ranges from 0x0000 to 0x3FFF.

Before running an application for the first time, you can use GProgrammer to write the initial TAG value used by Bluetooth LE Stack and the application to NVDS. If you specify an NVDS area start address, instead of using the default NVDS area in GR551x SDK, make sure the start address configured in GProgrammer is the same as that defined in custom_config.h. For more information about configuration of the NVDS area start address in custom_config.h, see “Configuring custom_config.h”.

Scan to follow

Open WeChat, use "Scan" to follow.