This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 Flash read/write SDK v11

Hi,

I am currently designin one of our product with a nRF51822 QFAC included, and I need to store 17k-bytes in a non-volatile memory.

I am writing the firmware using SDK v11, and I had a look at the flashwrite example using NVMC. In this example it seems that the function is only able to write one 32 bit value on one page. So I also checked the "ble_flash" driver that looks more suitable to my application.

My questions are the following :

Is it possible to store 17kB of data in the flash ?

Could you please tell me which library is the most optimized for my case ?

PS : BLE with SoftDevice will be enabled, so it have to work with it.

Best regards,

Guillaume

  • The answer to both your questions is "yes". Nordic has said that the Flash Data Storage (FDS) library is the library to use for this going forward.

    I have a sample project on Github that shows how to use FDS to do this.

    For SDK 11:

    We statically allocate storage while the device is in use. so for whatever your use, make sure your container is allocated:

    ###For Writing

    void save_friends(friends_list_t * friends_list) {
    	static fds_record_chunk_t chunk;
    
    	fds_record_t record;
      record.file_id = DATA_STORAGE_TYPE_ID;
      record.key = DATA_STORAGE_INSTANCE_ID;
    
    	chunk.p_data = friends_list;
      NRF_LOG_PRINTF("size should be storing for max_length: %u\n", sizeof(friends_list_t));
    	uint16_t max_length =  sizeof(friends_list_t);
    	uint16_t length_words = max_length / 4;
    	chunk.length_words = length_words; //number of 4-byte word chunks of color_friends_t
    	uint32_t err_code;
      record.data.p_chunks = &chunk;
      record.data.num_chunks = 1;
      err_code = fds_record_update(&friend_list_descriptor, &record);
      NRF_LOG_PRINTF("UPDATE FRIENDS: max_length: %u, length_words: %u, Error Code was: %u\n", max_length, length_words, err_code);
      APP_ERROR_CHECK(err_code);
    }
    

    For Reading

    void load_friends(friends_list_t * friends_to_load)
    {
      static fds_find_token_t tok;
      static fds_flash_record_t record;
      while(fds_record_find(DATA_STORAGE_TYPE_ID, DATA_STORAGE_INSTANCE_ID, &friend_list_descriptor, &tok) == NRF_SUCCESS) {
        fds_record_open(&friend_list_descriptor, &record);
        memcpy(friends_to_load, record.p_data, sizeof(friends_list_t));
        NRF_LOG_PRINTF("friends to load, num of friends is: %u\n", friends_to_load->num_of_friends);
        fds_record_close(&friend_list_descriptor);
      }
    }
    

    I have branches for SDK 10 and SDK 11:

    github.com/.../SDK11_upgrade

    There are a few issues:

    1. Sometimes the write operation can interfere with the softdevice and cause the device to reset. I haven't yet solved this problem.
    2. fds_update did not work in SDK10; I haven't yet checked to see if it works in SDK 11, but the above code assumes they fixed the probem in SDK 11. If not, then check the SDK 10 branch in that repo to see how I worked around it.
  • Ok thanks gortok, I'll have a look on it. For I am just trying to figure out if I need some external flash IC on my PCB or not :)

  • @guillaume not for what you need. After the softdevice is flashed, you have 112KB left over on the device (if you're using the xxAC variant), and if you want to use the Dual bank DFU, you need double your application space to update the application firmware. You can use Single Bank. Either way, you have more than enough room to flash 17Kb using the nordic FDS library.

  • @gortok : Thanks :) I noticed that there is another library called pstorage that look to be safer to use with a softdevice. Is another option I could consider ?

  • @guillaume: pstorage is older and I would not recommend it for development, as it will be deprecated soon. To quote @gortok, "FDS is the library to use for this going forward". FDS is designed so that it can be used with a SoftDevice, and is for example used by the Peer manager, which is a replacement for the older Device manager.

Related