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: Non-Volatile Memory

Part Number: CC2642R
Other Parts Discussed in Thread: UNIFLASH

Hello, 

I am using CC2642R1 with latest ble 5 sdk. In my project I need to save datas in flash for all users. I tried to use osal_snv_read/write functions and also I tried to nvs functions. 

- When I use osal_snv_read/write functions; it writes datas end of last data. I am calling osal_snv_write function with same page ID more than once and datas are written and the address of new data starts after where last one ends. 

Here the problem is, let's say I have 2 data (x and y). First I am writing x ( osal_snv_write(0x101,sizeof(x),&x) ) then I am writing 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.

- I tried to use nvs functions according to nvsinternal example but nvs_open fails. I am using simple_peripheral. What should I do to work with nvs functions istead of osal_snv functions in simple peripheral example. Should I turn off the osal_snv? I've already tried to not initialize osal_snv in osal_icall_ble.c but program stop working after bios_start function. So what should I do to use nvs functions?
Best regards,
  • Hi,

    There is a confusion between the id of a NV item (typically 0x101) and the page number. Generally speaking, the application does NOT have access to the NV page number - only to the NV item id.

    You should use one different NV id for each variable you wish to keep in NV memory. In other words, I recommend to use the NV id 0x101 for x and the NV id 0x102 for y. Behind the scene the NV driver will physically read/write/erase the pages for you.

    I hope this will help,

    Regards,

  • Thank you for your replay. I understand. But I still wonder how can I use nvs functions instead of osal_snv.. functions? I have a lot of datas and each part of the datas changes different frequency, so if I have all the control on memory with nvs functions it would be better and efficient. So could you help me to use nvs functions with simple peripheral examples? (when I try to use nvs nvs_open fails.)

  • Hi,

    First of all, the BLE stack uses the osal_snv API to access the NV memory. As a result we recommend to use this API to access the NV memory in order to avoid conflicts. Based on the details you have provided, I don't think using the NVS driver would help - especially because you can almost define as many NV id you want as long as they are unique. However, if you are interested in following this path I can point you to the documentation  and the driver API decription.

    Best regards,

  • I don't think using the NVS driver would help - especially because you can almost define as many NV id you want as long as they are unique.

    So BLE_NVID_CUST_START defines as 0x100 and BLE_NVID_CUST_END defines as 0x11F. That means I can use 31 IDs. Can I just change BLE_NVID_CUST_END and increase number of IDs? and also, in syscfg NVS region size is 0x4000, can I also change it or region base randomly? What are my limitations?

  • Hi,

    You can definitely inc4ease the number of IDs in the customer area. To do so, change the value of BLE_NVID_CUST_END to any value below 0x3FF (0x3FF is the maximum value usable).

    The size of the NVS region is limited by the size of the Flash physically presents and available on the device. If you declare a too big area, the linker will not be able to link the image and will throw an error.

    Best regards,

  • Hi,

    I'm so appreciated for your answers so far. I know I am asking too much but :) Here is a last question, I got all the things about IDs but what about pages? Is a page 256 bytes long? In document it says 1 or 2 pages for SNV. I believe it cannot be just 2 of 256 bytes for SNV :) so what is a size of page and how much can I use? In syscfg region size is 0x4000 and sector size 0x2000,. I think SNV use just part of it not all of it because gap bound manager. How can I know how much of it used by SNV? 

    I don't want to define too much IDs with a few pages. It sounds wrong :) Is it wrong? How much IDs wil be written in a page, is it limited? 

    I know I asked to much but if you can answer I will be very happy Slight smile

    Best regards,

  • Hi,

    Make sure to well review our documentation. The flash is split into erasable pages of 8 kB. 

    The Flash is used to keep your SW and the NVS.

    There is no limit on the number of IDs per page. Only the amount of data is limited.

    Regards,

  • Thank you for your help.

    Best Regars,