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.

CCS/CC2652P: How to use nvocmp APIs?

Part Number: CC2652P


Tool/software: Code Composer Studio

Hello,

I use CC2652P, SimpleLink SDKv4.20, TI15.4 Stack.

In 15.4 stack, there are NV APIs in nvocmp.c, I have some using questions about these APIs.

First, I init function pointers as below(Omit some macros):


NVOCMP_loadApiPtrs(&Main_user1Cfg.nvFps);

if(Main_user1Cfg.nvFps.initNV)
{
    Main_user1Cfg.nvFps.initNV(NULL);
}

Then, I read, write data with these APIs:

void NVOCMP_loadApiPtrs(NVINTF_nvFuncts_t *pfn)
{
    // Load caller's structure with pointers to the NV API functions
    pfn->initNV       = &NVOCMP_initNvApi;
    pfn->compactNV    = &NVOCMP_compactNvApi;
    pfn->createItem   = &NVOCMP_createItemApi;
    pfn->updateItem   = &NVOCMP_updateItemApi;
    pfn->deleteItem   = &NVOCMP_deleteItemApi;
    pfn->readItem     = &NVOCMP_readItemApi;
    pfn->readContItem = &NVOCMP_readContItemApi;
    pfn->writeItem    = &NVOCMP_writeItemApi;
    pfn->getItemLen   = &NVOCMP_getItemLenApi;
    pfn->lockNV       = NULL;
    pfn->unlockNV     = NULL;
    pfn->doNext       = NULL;
    pfn->expectComp   = &NVOCMP_expectCompApi;
    pfn->eraseNV      = &NVOCMP_eraseNvApi;
    pfn->getFreeNV    = &NVOCMP_getFreeNvApi;
}

I test data write and read as below:

Main_user1Cfg.nvFps.eraseNV();  // erase NV

uint32_t free_bytes = Main_user1Cfg.nvFps.getFreeNV();  // get free

printf("free bytes before: 0x%X, %u\n", free_bytes, free_bytes);

NVINTF_itemID_t id;

id.systemID = NVINTF_SYSID_APP;
id.itemID = 0;
id.subID = 0;

uint32_t data_test = 0x33445566;

uint8_t status = Main_user1Cfg.nvFps.writeItem(id, 4, &data_test);  // write data

printf("NV write status :%u\n", status);

status = Main_user1Cfg.nvFps.writeItem(id, 4, &data_test); // write data again, same data, same id
printf("NV write status :%u\n", status);

free_bytes = Main_user1Cfg.nvFps.getFreeNV();  // get free

printf("free bytes after: 0x%X, %u\n", free_bytes, free_bytes);

Output information is as below:

free bytes before: 0x1FF0, 8176
NV write status :0
NV write status :0
free bytes after: 0x1FDA, 8154

 

Then I read data from NV with SmartRF Flash Programmer 2 ver1.8.2, as below:



My NV start address is 0x52000. And I did find the data 0x33445566 I want to write.

But I found 0x33445566 twice. Why twice? I wrote twice, but with the same ID.

So, one ID doesn't have unique physical address?


I compare the date with this format in nvocmp.c.

Does the first data 0x7C matches header byte0 above?

If so, 0x7C in binary is b0111 1100, bit0-bit5(system id) is 11 1100, this is 0x3C, 60 in decimal. But system ID in code should be 7 not 60.

What's the relationship between systemID, itemID, subID and the physical address of an item in NV region?

Is there any document explains these concepts in detail?

And why free bytes before is 8176 not 8192, when NV is erased, there should be 8kB (8192)?

Thank you very much.

  • Hello yingtao,

    There is a section in the 15.4-Stack User's Guide which covers non-volatile memory which I recommend you reference along with the nvocmp.c comments regarding the design overview.  The NVOCMP_writeItemApi does not check for redundancy but simply writes data for the new item and marks the old item, if it exists, as inactive.  This is why you are noticing the same NV data twice.  If you look at the bit Field Description then you will se that the system id is from 0-5 of the compressed item header information, and since nv item and system id are zero in your example they create the 0x1C0000 observed (0x13B[6/4]96 is the data length, CRC, and address). Both the flash memory page itself as well as NV items contain headers which contain pertinent addressing and ID information which explain why there are fewer bytes in the flash memory page than expected.

    Regards,
    Ryan

  • Thank you, I am much more clear now than before.

    Another question.

    Each Item has a header of 7 bytes, so, if each item's content has only one byte, then ,each item takes 8 bytes in NV region including header bytes.

    If NV is 8kB, then the whole NV region can restore 1024 items regardless of NV page header.

    Is that right?

    If so, it is a litte waste of NV space beause each item has a 7bytes header.

  • Several NV items contain more than one byte of data, as demonstrated in your example which uses four bytes.  Consider ways to store multiple bytes of data into one NV item so that you are not unnecessarily wasting space for headers.  If this is not possible then consider increasing the number of active NV pages available.

    Regards,
    Ryan