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 Reply Children
  • 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!

  • Hi,

     

    nWre said:
    After creating the pm_static.yml I need to include it in CMakeLists.txt, correct?

    No, just place it in the root of your project folder.

    nWre said:
    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.

    Usually you want to do this with the board file, so that each sub-project is supplied with the same configuration.

      

    When you're creating an overlay that you want to be included in multiple projects (ie. non-secure application, secure application, and mcuboot), you have to specify this for each project.

    You can do this by placing your $(BOARD).overlay file in these two folder structures:

    https://github.com/nrfconnect/sdk-nrf/tree/v1.7.1/tests/modules/mcuboot/external_flash/boards

    https://github.com/nrfconnect/sdk-nrf/tree/v1.7.1/tests/modules/mcuboot/external_flash/child_image/mcuboot/boards

     

    nWre said:
    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?

    The overlay for your spi-flash (including the peripheral itself) will look something like this (depending on spi-nor flash you've chosen, gpios used etc):

    https://github.com/nrfconnect/sdk-zephyr/blob/main/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_common_0_14_0.dtsi#L42-L65

     

    Kind regards,

    Håkon

  • Hi! Thanks Håkon! I'm already using SPI3 for a sensor, can I just add an arbitrary number to the SPI interface? Like SPI4? Are there any examples writing to the external flash? I'd like to create numerous .bin or .hex files which I then send via LTE to server, once acknowledged that they are recieved, I want to free up that memory for other sensor data.

Related