天狼落星
再API文档中找到了使用NVDS API,但是如何使用?
1.初始化: uint8_t nvds_init(uint32_t start_addr,uint8_t pages )
2 .写入: uint8_t nvds_put(NvdsTag_t tag,uint16_t len,const uint8_t * p_buf )
3 .读取: uint8_t nvds_get(NvdsTag_t tag,uint16_t * p_len,uint8_t * p_buf )
4 .获取NVDS长度: uint16_t nvds_tag_length(NvdsTag_t tag)
5 .释放NVDS: uint8_t nvds_del(NvdsTag_t tag)
请问NvdsTag_t tag 直接声明就行了吗
走进风雨里
以uart_tx_rx工程为例,进行如下操作可以使NVDS模块正常工作。
使用NVDS需要 将如下文件加入到当前工程参与编译:
SDK_Folder\components\libraries\hal_flash\hal_flash.c
SDK_Folder\components\sdk\linker\lib\ble_sdk.lib
SDK_Folder\drivers\src\gr55xx_hal_exflash.c
SDK_Folder\drivers\src\gr55xx_hal_xqspi.c
SDK_Folder\drivers\src\gr55xx_ll_xqspi.c
使用NVDS需要 将如下路径加入到当前工程头文件路径:
..\..\..\..\..\components\libraries\hal_flash
..\..\..\..\..\components\sdk
使用NVDS需要 引用如下头文件:
#include "hal_flash.h"
#include "gr55xx_nvds.h"
代码示例:
使用NVDS写入函数将长度10字节数组写入NVDS Item tag为0x0001的空间,并读取通过串口打印输出。
#include <stdio.h>
#include <string.h>
#include "app_log_port.h"
#include "gr55xx_hal.h"
#include "boards.h"
#include "hal_flash.h"
#include "gr55xx_nvds.h"
#define NVDS_ITEM_USER 0x0001
void nvds_test(void)
{
uint16_t len = 0;
uint8_t WriteBuffer[10] = {0}, ret = 0;
for(uint8_t i = 0; i < 10; i++)
{
WriteBuffer[i] = i;
}
ret = nvds_put(NVDS_ITEM_USER, sizeof(WriteBuffer), WriteBuffer);
if( ret == NVDS_SUCCESS )
{
printf("nvds_put SUCCESS\r\n");
for(uint8_t i = 0; i < 10; i++)
{
WriteBuffer[i] = 0;
}
len = nvds_tag_length(NVDS_ITEM_USER);
ret = nvds_get(NVDS_ITEM_USER, &len, WriteBuffer);
if( ret == NVDS_SUCCESS )
{
printf("nvds_get SUCCESS\r\n");
printf("NVDS 0x%X Data: ", NVDS_ITEM_USER);
for(uint8_t i = 0; i < 10; i++)
{
printf("0xX ", WriteBuffer[i]);
}
printf("\r\n");
}
}
else
{
printf("NVDS get error %d\r\n", ret);
}
}
int main(void)
{
hal_flash_init();
nvds_init(NVDS_START_ADDR, NVDS_NUM_PAGE);
hal_init();
/* Initial printf mode and UART */
app_log_port_init();
nvds_test();
printf("\r\n");
printf("******************************************************\r\n");
printf("* NVDS example. *\r\n");
printf("* *\r\n");
printf("* Config: 115200, 8-bits, 1-stopbit, none *\r\n");
printf("* *\r\n");
printf("* UART0 <-----> UART to USB *\r\n");
printf("* TX(GPIO10) -----> RX *\r\n");
printf("* RX(GPIO11) <----- TX *\r\n");
printf("* *\r\n");
printf("* This sample code will write and read nvds. *\r\n");
printf("******************************************************\r\n");
app_log_port_flush();
printf("\r\nThis example demo end.\r\n");
while(1);
}
PS:如果我的回答能够帮助您解决问题,请将此问题设置为已解决,谢谢。
天狼落星
头文件也添加了还是报错;
在串口透传的例子中没有报错,但向NVDS中读写数据未有现象
打开微信,使用“扫一扫”即可关注