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.

CC254XF256 SNV Memory API

Hi,

I am currently utilising OSAL Simple Non-Volatile (SNV) Memory API to read and write small chunks of data. I can see by default that two pages have been reserved for NV items which should amount to  4096 bytes (2048 * 2) for CC254XF256.

This was working brilliantly for me thus far, however it looks like when I reach the end of the first page (i.e 2048) it fails. Scanning through the SNV Memory API source code, I cannot see any switch to the next page and it seems like only one page can be used at any one time.

Could someone either correct me or suggest the proper use of this API?

Cheers,

Jerome

  • Hi Jerome, 

    How does it fail? If you look in osal_snv.c, there function osal_snv_compact(uint8 threshold) deals with moving the valid entries to a new page if a threshold has been reached. You can set up the snv driver to use multiple pages, but you have to remember to adjust the linker configuration accordingly to ensure tha you don't have collisions with code space. 

    Peder

  • Hi Peder,

    Yes sorry, I can see how osal_snv_compact() is attempting to move entries to a new page. I already have two pages which is enough. After stepping through the source code, it fails for me during compacting:

    [osal_snv.c: static void compactPage( uint8 srcPg )]

    ...
    if (findItem(dstPg, dstOff, lastId) == 0) { // This item was not copied over yet. // This must be the latest value. // Write the latest value to the destination page xferItem(dstPg, dstOff, hdr.len, srcOff - hdr.len); dstOff += hdr.len + OSAL_NV_WORD_SIZE; }
    ...

    Where, xferItem(0x7E, 4, 32, 2056 - 32). The srcOff is looks like an invalid offset (i.e. >=2048). Thus the proceeding verifyWordM() function fails.

    Also what use case is it recommended to call osal_snv_compact(), as compactPage() is already called during osal_snv_write()?

    Cheers,

    Jerome

  • Hi Jerome, 

    It looks to me like you're probably filling up the page betweeen each call to osal_snv_compact. If you use the snv functions extensively, you should probably place a few more calls to the compact function as well. The trick is to do this when the BLE stack does not have much going on, like just after a connection event for example. 

    Peder

  • Hi Peder,

    I've added osal_snv_compact commands more frequently as suggested but makes no difference. Still consistently has the same error. I've attached a spreadsheet of the flash memory before and after the error.

    Could you explain what osal_snv_compact function is attempting to achieve?

    Because it looks like it is just switching between two pages (0x7d and 0x7e) and copying memory to the other page every time a "compacting" event occurs. At the end of the function the new active page is set so it continues to use the page that memory that was just copied to. The way I understand it, it uses an entire extra flash page for this compacting process.

    Jerome

    8715.flash_mem.xlsx

  • Hi Jerome, 

    Updated values of all SNV variables are written sequentially. The osal_snv_compact function is called periodically, and will check if the current page has reached a threshold for when it is deemed full. At that point, it will parse the page backwards and move all the latest and valid variable entries to a new page and erase the old one. No other pages are involved in the process. 

    Peder

  • Hi Peder,

    Thanks answered my question. I'll look to increasing number of flash pages in order to use SNV for amount of data I need (i.e. more than one 2048 page). Most of my entries will should stay valid so compacting will not help my issue.

    Thanks,

    Jerome