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.

CC1352P: does NVS driver check if new data to write is the same as old one before wring into flash

Part Number: CC1352P

Hi,

To avoid wearing out flash, I assume it is better to check if the content of a NVS item is the same as its existing content before actually writing into flash. My question is, do we need to perform such check in application or the driver performs this itself?

Thanks,

ZL

  • Hi Zhiyong,

    The NVS write does not read the Flash content before writing. The source of the driver can be found here: [SDK PATH]\source\ti\drivers\nvs\NVSCC26XX.c

    There is a pre-verify flag, which is used to ensure the data is actually writeable without needing an erase. But this still is not what you are asking for. 

    You would need to handle it in the application if you need to read before writing the string.

    Regards

    Sid

  • Hi Sid,

    The function used by example projects to write in NVS seems to check if content of item is the same as existing one.

    /*********************************************************************
     * @fn      NV_writeItem
     *
     * @brief   Write a data item to NV.
     *
     * @param   nv_id - Valid NV item Id.
     * @param   len   - Length of data to write.
     * @param   *pBuf - Data to write.
     *
     * @return  NVINTF_SUCCESS if successful, failure code otherwise.
     */
    uint8 NVOCOP_writeItem( NVINTF_itemID_t nv_id, uint16 len, void *pBuf )
    //...
          for (i = 0; i < len; i++)
          {
            HalFlashRead(NV_PAGE, offset, &tmp, 1);
            if (tmp != ((uint8 *)pBuf)[i])
            {
              break;
            }
            offset++;
          }
    
          if (i == len)
          {
            // Changed value is the same value as before.
            // Return here instead of re-writing the same value to NV.
            return NVINTF_SUCCESS;
          }
    //...

    I guess as long as we call this function instead of directly calling the NVS driver, we don't need to perform such check ourselves in customized applicaion.

    Best,

    ZL

  • Hi Zhiyong,

    Yes you are right. The example checks the string in the application layer before using the write API. You can use the example function as your write function.

    Regards,

    Sid

  • Hi Sid,

    The code in NVOCOP_writeItem doesn't seem to work. In our application we have a customized NVS item to store pan id, encryption key and channel mask etc. If we call the function to save this item 3 times without changing its content, we can see 3 copies of this item in flash.

    The following screenshot is readback via Flash-Programmer-2. The channel mask with repeat of (0x55) is highlighted.

    I guess we will still have to perform such checks in application.

    Best,

    ZL

  • Hi Zhiyong,

    If you debug the code, can you please see why the logic is failing? Is it because of wrong management of "offset" by the driver?

    Regards,
    Sid