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!

  • * 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).

  • Hi Sebastiaan! Thank you for answering, truly appreciate it! I was to understand that the nRF9160DK has a 64 Mb external flash memory described here:
    https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_nrf91_dk%2FUG%2Fnrf91_DK%2Fexternal_memory.html

    This is indeed done via SPI.

    I'm thinking http communication but that is mostly because it's the one I know and have used, does it make much of a difference?

    That's a clever solution for getting the data, I will look into that solution.

    Many thanks!

  • I'm thinking http communication but that is mostly because it's the one I know and have used, does it make much of a difference?

    That's a very broad question :). Communication protocols are often fundamentally different with respect to speed, reliability, transfer size, security, ease of use, ...

    HTTP might be fine for now, you could extend it to HTTPS for improved security in the future. Coap might also be worth looking into, if your cloud platform supports it directly - I have unfortunately never used it yet since we typically interact with AWS which does not support coap.

  • Since you mention using the nRF9160DK's external flash, it is important that you switch in the lines for the external flash. That is done by re-programming the board controller, with the sequence explained here:

    https://devzone.nordicsemi.com/f/nordic-q-a/80836/extend-flash-size-of-nrf9160---single-slot-application/335345#335345

     

    create the file my_project/pm_static.yml, which holds something like this (alter sizes to your needs):

    settings_storage:
      address: 0x0
      region: external_flash
      size: 0x40000

     

    Kind regards,

    Håkon

  • Hi Håkon!

    I wrote the code from your link in to nrf9160dk_nrf9160_common.dts and it compiles.

    After creating the pm_static.yml I need to include it in CMakeLists.txt, correct? If so, how? I tried creating an overlayfile and using that instead of the nrf9160dk_nrf9160_common.dts and targeting it in my CMakeLists but it wasnt included, thus I resorted to writing it in the nrf9160dk_nrf9160_common.dts file instead.

    Are there any sample code of reading and writing? I do not know the syntax. As it is SPI, I'm guessing the CS-pin needs to be sit high/low during reading/writing, is this correct?

    Thanks for your patience with my very newbie questions Slight smile

    Thanks for all your help!

Related