This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing/reading data to external flash on the nRF9160DK

Hello Nordic!

I have connected a sensor to the DK via SPI. It outputs a lot of data, a lot... for 1 second of data I get 4096 entries. Each entry is 10 bytes in length.


I want to store 20 seconds of sensor data on the flash memory, that is a total of about 0,8 MB if my calculations are correct.

The sensor has a FIFO-queue so if the write operation is quick enough there shouldn't be any data loss.
Once 20 seconds worth of data is recorded I then want to send this via LTE to server, I'm guessing in chunks.

Questions:
* How do I go about this? Is there a binary write example available?

* What size should the chunks be for this example?

* Once a file is written and done, before going in to the LTE-part of the design, is there any way to extract the bin file for data validation from the DK?


Thank you!

Parents
  • * write to flash: some elements to take into account. Since your program is also stored in flash, you need to make sure it never gets overwritten. There is already a "storage" partition in the flash by default on NRF9160 (if I am correct): check the device tree, and you will find the storage_partition:

                            storage_partition: partition@fa000 {
                                label = "storage";
                                reg = < 0xfa000 0x6000 >;
                            };

    You could adapt the size via an overlay, but evidently it all still needs to fit in the 1MB flash. In fact, this storage partition is used for non-volatile-storage (NVS) of which I guess you can find some examples. But you'll not use it in that way.You'll probably need following configs: CONFIG_FLASH=y, CONFIG_FLASH_PAGE_LAYOUT=y, CONFIG_MPU_ALLOW_FLASH_WRITE=y

    If you need 0.8 MB of data, it might be best to go for an external flash device with SPI access.

    * chunk size: that strongly depends on the communication protocol that you would use to upload the data (coap, http, mqtt, ...?).

    * Maybe with the NRF programmer it's possible to download a partition of the flash. I've never done that but it might be possible. If that is not supported, you can always implement a functionality to transmit your binary data over the UART and write a python script that listens on the VCOM port, reassembles all the data and stores it in a file. You could initiate this transfer by e.g. clicking on a button, or by implementing a 2-way communication protocol between the python script and your NRF (so it can be triggered on command from your python script).

Reply
  • * write to flash: some elements to take into account. Since your program is also stored in flash, you need to make sure it never gets overwritten. There is already a "storage" partition in the flash by default on NRF9160 (if I am correct): check the device tree, and you will find the storage_partition:

                            storage_partition: partition@fa000 {
                                label = "storage";
                                reg = < 0xfa000 0x6000 >;
                            };

    You could adapt the size via an overlay, but evidently it all still needs to fit in the 1MB flash. In fact, this storage partition is used for non-volatile-storage (NVS) of which I guess you can find some examples. But you'll not use it in that way.You'll probably need following configs: CONFIG_FLASH=y, CONFIG_FLASH_PAGE_LAYOUT=y, CONFIG_MPU_ALLOW_FLASH_WRITE=y

    If you need 0.8 MB of data, it might be best to go for an external flash device with SPI access.

    * chunk size: that strongly depends on the communication protocol that you would use to upload the data (coap, http, mqtt, ...?).

    * Maybe with the NRF programmer it's possible to download a partition of the flash. I've never done that but it might be possible. If that is not supported, you can always implement a functionality to transmit your binary data over the UART and write a python script that listens on the VCOM port, reassembles all the data and stores it in a file. You could initiate this transfer by e.g. clicking on a button, or by implementing a 2-way communication protocol between the python script and your NRF (so it can be triggered on command from your python script).

Children
No Data
Related