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.

CC2642R: osal_snv_write function does not write same page every call

Part Number: CC2642R
Other Parts Discussed in Thread: UNIFLASH

Hello eveyone,

I have CC2642R1 dev board. 

I am using simple peripheral ble-5 example. I am trying to write flash with osal_snv_write() function. I've just put the function in button handler, for each button press function starts writing from the adress which last time it ends to write. 

To be more clear;

The code I'm writing is:

uint8_t deneme [] = {
0x11, 0x12, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x21, 0x22, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x31, 0x32, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x41, 0x42, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x51, 0x52, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x61, 0x62, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x71, 0x72, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x81, 0x82, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0x91, 0x92, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0xa1, 0xa2, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0xb1, 0xb2, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0xc1, 0xc2, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0xd1, 0xd2, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f,
0xe1, 0xe2, 0x13, 0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1b,0x1c,0x1d,0x1e,0x1f
};
t = osal_snv_write(0x101, 240, &deneme);

as I said, It's written in button handler function. ( BLE_NVID_CUST_START is defined as 0x100)

When I press button first time, function starts to write 0x48062 flash adress and ends 0x48133. Then when I press button second time, It doesn't start to write 0x48062, I starts to write 0x48152 flash adress. Every time continues like this. 

So is it normal? Because my page ID is always 0x101 as you can see. By the way NVS region base adress is 0x48000 in syscfg. 

  • Hi,

    The behavior experienced is expected.

    The non-volatile memory requires energy and time to be erased. In addition, an erase will affect a whole memory page and have consequence on the durability of the device. (see the datasheet to get details on the number of read/writ cycles accepted by the part).

    To avoid all these, the NV driver is written in a way to avoid erasing the flash as much as possible. To do this, the driver duplicates the data instead of overwriting them. The NV driver provides and interface to mask the complexity of this. You may want to review the documentation within <SDK>\source\ti\drivers\NVS.h for further details.

    Best regards,

  • But what if I want to erase the memory? How can delete it by using simple nv functions?

  • Hi,

    At the OSAL level, there is no function to force the erase of the NV memory.

    As mentioned before, the NV memory will be erased by page. It means the data will have to be copied somewhere to avoid losing them (the driver handles this when needed).

    In general, when you are not interested anymore by a piece of data, you can "overwrite it" with the smallest data possible. Something like this could probably help:

    uint8_t nothing = 0;
    uint8 t = osal_snv_write(0x101, 0, &nothing);

    Best regards,

  • So the main problem is, lets say I have 2 value (x and y) that I have to keep in non volatile memory. When I write x ( osal_snv_write(0x101,sizeof(x),&x) ) then I write y ( osal_snv_write(0x101,sizeof(y),y) ) x and y are in non volatile memory end to end. The problem is when I call osal_snv_read function it starts to read the adress of beginning of where y is written. I tried to call a few times but every time it starts to read from where y is starting. So I can only read y and after y. How can I read x, then? 
    And since every value is written after last one, why there is page IDs? It doesn't stop to write after last value even the adress bigger than 255. and lastly even if I change the page ID, it doesn't write somewhere else. After erasing all memory with uniflash, it starts samme adress even if pageID is different.

  • Hi,

    Please open a new thread for this new issue.

    Best regards,