Skip to main content

Example code for NVRAM VES Code for DA14681 with flash

1 year ago

Example code for NVRAM VES Code for DA14681 with flash

Posted bymahmed10610 points 1 reply
0 upvotes

Hi dialog

I am working in a custom board based on DA14681 and using firmware pxp reporter. Everything is working smoothly as expected, but now i want to save my data into flash.

In flash adapter document, it is mentioned that
" A sector can be erased a limited number of times only (guaranteed by manufacturer). After that
number of erase cycles, data storage is unreliable."

" Writing small amounts of data at the same location many times, will result in wearing the flash
(the number of write/erase cycles are device-specific, see the corresponding Flash datasheet)."

" VES
VES drivers provide access to a partition entry with power failure and wearing protection. To achieve
this, VES drivers write data to random locations within the flash without needing to erase a whole
sector when the same location is modified. This is accomplished by writing to different flash locations
for the same user provided address. The VES driver provides virtual addressing, that is, the user
指定的地址是一个真正的翻译flash location before a read or write operation. For this to
work, the flash size must be bigger than the addressing space visible to the user. A common rule of
thumb is 8x the virtual EEPROM size needed."
So my scnerio is the same that i want to write little very frequently in the flash, But i couldnt find any example code for ad_nvms_ves_write, ad_nvms_ves_read.

So is there any example code in which VES mode is implemeted so that i can add this feature in my project. Thanks

accepted answer!

1 year ago

PM_Dialog

Hi mahmed106,

Many thanks for your question online. There isn’t any document describing the VES functionality. However, it can be used either to read or write data. For an application to use VES there are three prerequisites:

  1. The Partition ID should only be NVMS_GENERIC_PART and tagged as PARTITION_FLAG_VES.
  2. dg_configNVMS_VES macro should be defined in config/custom_config_qspi.h

I would suggest you to have a look atSPI Adapter Concepttutorial from our support website which demonstrates how to read/write the LOG partition (NVMS_LOG_PART). You will need to modify the ad_nvms_open() before accessing a partition entry as follow:

nvms_var = ad_nvms_open(NVMS_GENERIC_PART);

Be aware that VES driver provides access to the partition with power failure protection. It uses virtual addressing. The address space available for the user application is smaller than physical flash space occupied by the partition, but user can read and write to this address space without worrying that data will be lost. If power fails during a write, the specific data being written can be lost but other data will not be affected. For getting more information how the VES feature works, please read section 2.4.2 of the tutorial.

#define dg_configFLASH_ADAPTER (1) #define dg_configNVMS_ADAPTER (1) #define dg_configNVPARAM_ADAPTER (1)

Thanks, PM_Dialog