SDK:
simplelink_cc13xx_cc26xx_sdk_8_30_01_01
配置:


现象:
1、 在project_zero工程中, NVS_write卡死
2、在nfsexternal工程中, NVS_write返回NVS_STATUS_INV_WRITE(-7)
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
/* Driver Header files */
#include <ti/display/Display.h>
#include <ti/drivers/NVS.h>
/* Driver configuration */
#include "ti_drivers_config.h"
#define FOOTER "=================================================="
/* Buffer placed in RAM to hold bytes read from non-volatile storage. */
static char buffer[64];
static const char signature[] = {"SimpleLink SDK Non-Volatile Storage (NVS) SPI Example."};
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
NVS_Handle nvsHandle;
NVS_Attrs regionAttrs;
NVS_Params nvsParams;
Display_Handle displayHandle;
Display_init();
NVS_init();
displayHandle = Display_open(Display_Type_UART, NULL);
if (displayHandle == NULL)
{
/* Display_open() failed */
while (1) {}
}
NVS_Params_init(&nvsParams);
nvsHandle = NVS_open(CONFIG_NVSEXTERNAL, &nvsParams);
if (nvsHandle == NULL)
{
Display_printf(displayHandle, 0, 0, "NVS_open() failed.");
return (NULL);
}
Display_printf(displayHandle, 0, 0, "\n");
/*
* This will populate a NVS_Attrs structure with properties specific
* to a NVS_Handle such as region base address, region size,
* and sector size.
*/
NVS_getAttrs(nvsHandle, ®ionAttrs);
/* Display the NVS region attributes. */
Display_printf(displayHandle, 0, 0, "Sector Size: 0x%x", regionAttrs.sectorSize);
Display_printf(displayHandle, 0, 0, "Region Size: 0x%x\n", regionAttrs.regionSize);
/*
* Copy "sizeof(signature)" bytes from the NVS region base address into
* buffer.
*/
NVS_read(nvsHandle, 0, (void *)buffer, sizeof(signature));
/*
* Determine if the NVS region contains the signature string.
* Compare the string with the contents copied into buffer.
*/
if (strcmp((char *)buffer, (char *)signature) == 0)
{
/* Write buffer copied from flash to the console. */
Display_printf(displayHandle, 0, 0, "%s", buffer);
Display_printf(displayHandle, 0, 0, "Erasing SPI flash sector...");
/* Erase the entire flash sector. */
NVS_erase(nvsHandle, 0, regionAttrs.sectorSize);
}
else
{
int_fast16_t rc = NVS_erase(nvsHandle, 0, regionAttrs.sectorSize);
Display_printf(displayHandle, 0, 0, "NVS_erase, rc = %d", rc);
/* The signature was not found in the NVS region. */
Display_printf(displayHandle, 0, 0, "Writing signature to SPI flash...");
/*
* Write signature to memory. The flash sector is erased prior
* to performing the write operation. This is specified by
* NVS_WRITE_ERASE.
*/
rc = NVS_write(nvsHandle, 0, (void *)signature, sizeof(signature), NVS_WRITE_PRE_VERIFY | NVS_WRITE_POST_VERIFY);
Display_printf(displayHandle, 0, 0, "Write, rc = %d", rc);
memset(buffer, 0, sizeof(buffer));
rc = NVS_read(nvsHandle, 0, (void *)buffer, sizeof(signature));
Display_printf(displayHandle, 0, 0, "read %d: %s", rc, buffer);
}
NVS_close(nvsHandle);
Display_printf(displayHandle, 0, 0, "Reset the device.");
Display_printf(displayHandle, 0, 0, FOOTER);
return (NULL);
}
输出
Sector Size: 0x1000 Region Size: 0x1000 NVS_erase, rc = 0 Writing signature to SPI flash... Write, rc = -7 read 0: Reset the device. ==================================================






