This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2652P7: OSAL SNV erase multi Customer's NV IDs

Part Number: CC2652P7
Other Parts Discussed in Thread: SYSCONFIG, UNIFLASH

Tool/software:

Hi,

I would like to erase multiple customer-specific NV (non-volatile) IDs approximately 100 entries totaling around 1 KB. However, the available OSAL SNV API only provides functions for reading and writing individual items.

To work around this limitation, I increased the NV storage size to 0x8000 and set NVOCMP_NVPAGES to 4. The intention is to allocate Customer's NV IDs to NV pages 2 or 3, allowing for erasure of these entries by erasing an entire page at once.

Could you please advise on the feasibility and best practices for this approach?

SDK: simplelink_cc13xx_cc26xx_sdk_8_30_01_01

Best regards,

Bank

  • Hi !

    Flash has two sections that the user can interact with : Simple NV (SNV) Area and Application’s Non Volatile Storage (NVS) Area. SNV Area is used by the Bluetooth stack to store bonding information, but for small amount of data (below 100 bytes).

    Since you want to store 1 kB of data, we recommend using the NVS Area. The NVS has API function for reading, writing and erasing memory, and more, which would fit your needs. You could define a new NVS area in SysConfig, and use the API to write, read and erase your data.

    You can read more about how to handle the flash in the chapter about Flash memory in the User Guide.

    Kind regards,
    Maxence

  • Hi Maxence,

    but for small amount of data (below 100 bytes).

    I have already increased the NV storage size.

    Since you want to store 1 kB of data, we recommend using the NVS Area. The NVS has API function for reading, writing and erasing memory, and more, which would fit your needs. You could define a new NVS area in SysConfig, and use the API to write, read and erase your data.

    To work around the NVS issue, I erased the flash and loaded the image via UniFlash, then performed an initial reset of the board. However, the flash read status and data appeared to be incorrect. A subsequent reset of the board the same incorrect results.

    NVS_Handle nvsHandle;
    NVS_Attrs regionAttrs;
    NVS_Params nvsParams;
    uint8_t rgbVal[4];
    uint8_t rgbVal2[4];
    
    void rgbVal_Init(void) {
    //--------------------//
    
      NVS_init();
      NVS_Params_init(&nvsParams);
    
      nvsHandle = NVS_open(CONFIG_NVS_0, &nvsParams);
      if (nvsHandle == NULL) {
        while (1) {}
      }
    
      NVS_getAttrs(nvsHandle, &regionAttrs);
    
      uint16_t status = SUCCESS;
      uint16_t status2 = SUCCESS;
    
      status = osal_snv_read(NVID_GPWM, NVGPWM_SIZE, (uint8_t *)&rgbVal);
      status2 = NVS_read(nvsHandle, 0, (uint8_t *)&rgbVal2, 4);
      
      Log_info2("read status %x, %x", status, status2);
      Log_info4("dbg  %x, %x, %x, %x", rgbVal[0], rgbVal[1], rgbVal[2], rgbVal[3]);
      Log_info4("dbg2  %x, %x, %x, %x", rgbVal2[0], rgbVal2[1], rgbVal2[2], rgbVal2[3]);
      
      if (status != SUCCESS) {
        rgbVal[IDX_R_LED] = StatePWM_Val[STATE_POWER_ON_INIT][IDX_R_LED];
        rgbVal[IDX_G_LED] = StatePWM_Val[STATE_POWER_ON_INIT][IDX_G_LED];
        rgbVal[IDX_B_LED] = StatePWM_Val[STATE_POWER_ON_INIT][IDX_B_LED];
        rgbVal[IDX_W_LED] = StatePWM_Val[STATE_POWER_ON_INIT][IDX_W_LED];
        status = osal_snv_write(NVID_GPWM, NVGPWM_SIZE, (uint8_t *)&rgbVal);
      } // !SUCCESS
    
      if (status2 != SUCCESS) {
        rgbVal2[IDX_R_LED] = 0xAA;
        rgbVal2[IDX_G_LED] = 0xBB;
        rgbVal2[IDX_B_LED] = 0xCC;
        rgbVal2[IDX_W_LED] = 0xDD;
        status2 = NVS_write(nvsHandle, 0, (uint8_t *)rgbVal2, 4, NVS_WRITE_POST_VERIFY);
      }
    
      Log_info2("write status %x, %x", status, status2);
      Log_info4("dbg  %x, %x, %x, %x", rgbVal[0], rgbVal[1], rgbVal[2], rgbVal[3]);
      Log_info4("dbg2  %x, %x, %x, %x", rgbVal2[0], rgbVal2[1], rgbVal2[2], rgbVal2[3]);
    
      NVS_close(nvsHandle);
      
    } // void rgbVal_Init(void)

    Best regards,

    Bank

  • Hi,

    Is it possible that your CONFIG_NVS_0 is overwritten by CONFIG_NVSINTERNAL or CONFIG_NVSINTERNAL ?
    Could you send me sysconfig screenshot of those configs ?

    Kind regards,
    Maxence

  • Hi Maxence,

    FYI

    Best regards,

    Bank

  • Hi,

    Sorry for the late reply. Could you check if you can write into the NVS and then read it right after to see if this works ? Your problem right now is that the NVS value is not conserved after a power cycle, right ?

    Here's the code you could use :

    NVS_Handle nvsHandle;
    NVS_Attrs regionAttrs;
    NVS_Params nvsParams;
    
    void rgbVal_Init(void) {
    //--------------------//
    
      NVS_init();
      NVS_Params_init(&nvsParams);
    
      nvsHandle = NVS_open(CONFIG_NVS_0, &nvsParams);
      if (nvsHandle == NULL) {
        while (1) {}
      }
    
      NVS_getAttrs(nvsHandle, &regionAttrs);
      
      uint16_t status = SUCCESS;
      
      uint8_t dataArray[4] = {0xCA, 0xFE, 0xBE, 0xEF};
      status = NVS_write(nvsHandle, 0, (uint8_t *)dataArray, 4, NVS_WRITE_POST_VERIFY);
    
      Log_info2("write status %x", status);
    
      uint8_t dataArrayRead[4] = {0x00, 0x00, 0x00, 0x00};
      status = NVS_read(nvsHandle, 0, (uint8_t *)dataArrayRead, 4);
      
      Log_info2("read status %x", status);
      Log_info2("values read : %x, %x, %x, %x", 
        dataArrayRead[0], dataArrayRead[1], dataArrayRead[2], dataArrayRead[3]);
      
      NVS_close(nvsHandle);
      
    } // void rgbVal_Init(void)

    Kind regards,
    Maxence

  • Hi,

    Could you check if you can write into the NVS and then read it right after to see if this works ?

    This operation is works.

    Your problem right now is that the NVS value is not conserved after a power cycle, right ?

    After a power cycle, the system should verify the contents of the NVS. If the flash has been erased or the data was not previously stored, the read operation should not return a success status. A comparison should be made between the results of osal_snv_read and NVS_read to detect such conditions."

    Best regards,

    Bank