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.