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

How to write uint8_t some_array via FDS ?

Hello everyone,

I use sdk14.2 softdevice S132. I want to write "uint8_t some_array [7] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06};" with use fds_write and read the array from the memory location and store the array into another array. Prosses like this;

1- Write the array  "uint8_t some_array [7] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06};" to memory via FDS

2- Read the array from address location (fds_read)

3- Store the read array into another array (for example second_array(7)).

4- Finally, to be sure, we should read this sequence in this way;

NRF_LOG_HEXDUMP_INFO(second_array,7); 

and result have to be;

 0> <info> app:  00 01 02 03 04 05 06   |....... 

I read some document and examine some example, but I did not see how to write a sequence with multiple elements into flash memory.

Do you have any suggestion?

Parents
  • Hi Ugur

    Have you had a look at the fstorage example in the SDK?

    If you are looking for a simple library to read and write one or more bytes to flash I think fstorage is the better choice. FDS is more sophisticated, but might be a bit overkill for what you are trying to do. 

    Best regards
    Torbjørn

  • Hi ovrebekk, thanks for your answer. I have a few questions;

    Q-1 Do I have to use the Cli.c library? If no, how to read array and then  store it into another array ?

    Q-2 Is there an example of FDS that I have described above (uint8_t some_array [7])?

    I looked the LINK, but it wrote "static uint32_t const m_deadbeef[2] = {0xDEADBEEF,0xBAADF00D};"  This is not exactly what I want to learn. "uint8_t some_array [7] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06};" I want to save it and read it, then copy it to another array. 

  • Hi

    1) No, you can remove the CLI library if you like. This is just included to provide a command line interface when running the example. If you delete all the cli_xxx functions from main.c the library should no longer be used. 

    2) The m_hello_world variable is a char array, which is almost the same as a uint8_t array (the only difference is that char is signed, while uint8_t is unsigned). 

    You can modify line 292 in main.c to write your some_array instead of m_hello_world:
    rc = nrf_fstorage_write(&fstorage, 0x3f000, some_array, sizeof(some_array), NULL);
    APP_ERROR_CHECK(rc);

    The read function works almost exactly the same, and you can use that to read the data into another array:

    rc = nrf_fstorage_read(&fstorage, 0x3f000, second_array, sizeof(second_array));
    APP_ERROR_CHECK(rc);

    If you just want to move data from one RAM buffer to another you can also use memcpy(..), but you probably know this already. 

    Best regards
    Torbjørn

Reply
  • Hi

    1) No, you can remove the CLI library if you like. This is just included to provide a command line interface when running the example. If you delete all the cli_xxx functions from main.c the library should no longer be used. 

    2) The m_hello_world variable is a char array, which is almost the same as a uint8_t array (the only difference is that char is signed, while uint8_t is unsigned). 

    You can modify line 292 in main.c to write your some_array instead of m_hello_world:
    rc = nrf_fstorage_write(&fstorage, 0x3f000, some_array, sizeof(some_array), NULL);
    APP_ERROR_CHECK(rc);

    The read function works almost exactly the same, and you can use that to read the data into another array:

    rc = nrf_fstorage_read(&fstorage, 0x3f000, second_array, sizeof(second_array));
    APP_ERROR_CHECK(rc);

    If you just want to move data from one RAM buffer to another you can also use memcpy(..), but you probably know this already. 

    Best regards
    Torbjørn

Children
Related