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

  • Hi,

     

    nWre said:
    I'm already using SPI3 for a sensor, can I just add an arbitrary number to the SPI interface? Like SPI4?

    No, do not do that. This will then point the hardware to a non-existing SPI instance. nRF9160 has from 0 to 3:

    https://infocenter.nordicsemi.com/topic/ps_nrf9160/spim.html?cp=2_0_0_5_12_5#topic

    If you want to setup more than one sensor, you should do it similar to how it is done on the thingy91:

    https://github.com/nrfconnect/sdk-nrf/blob/main/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L128-L151

     

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

    Once you have setup the external flash area, you can address it directly to the flash-backend that you're using (NVS, littlefs or which ever you chose). The logic you require needs to be added manually in your application.

     

    Kind regards,

    Håkon

  • Hi! I have it setup like this in an overlay file:

    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	sck-pin = <19>;
    	mosi-pin = <18>; 
    	miso-pin = <17>; 
    	cs-gpios = <&gpio0 23 0>,<&gpio0 22 0>,<&gpio0 21 0>; 
    	clock-frequency = <10000000>;
    	label = "SENSORARRAY";
    	sensor8: sensor8@0 {
    		compatible = "adi,adxl355";
    		status = "okay";
    		label = "sensor8";
    		spi-max-frequency = <10000000>;
    		reg = <0>;
    	};
    
    	sensor40: sensor40@1 {
    		compatible = "adi,adxl357";
    		status = "okay";
    		label = "sensor40";
    		spi-max-frequency = <10000000>;
    		reg = <1>;
    	};
    	sensor200: sensor200@2 {
    		compatible = "adi,adxl375";
    		status = "okay";
    		label = "sensor200";
    		spi-max-frequency = <10000000>;
    		reg = <2>;
    	};
    };


    I can communicate with the sensors but they do interfere with each other even when their corresponding cs-pin is set to high(blocking). I don't really understand why but one question I have about this is if

    spi_dev = device_get_binding("SENSORARRAY");

    Instead should be separated by child nodes, like this
    spi_dev8 = device_get_binding("sensor8");
    spi_dev40 = device_get_binding("sensor40");
    spi_dev200 = device_get_binding("sensor200");


    I've tried this all day but couldn't get any other value from this but null. I've tried aliases, node_label, node_path but nothing. Maybe I'm misunderstanding this and that the master is the dev, not the slaves.

    I'm using the same MISO,MOSI and SCLK lines for all three. They also share 3V-input and GRND. Apart from this they have different CS-pins. I've tried them one by one and they're all working, however when I connect more than one sensor, there is interference.

    I hope you can clear some of this up for me, I'll keep banging my head against your fine hardware in the meantime ;)

    Snowy, gothenburgian regards!

    Edit: It appears as though I am not the solderer I thought I was. The interference came from shoddy soldering. I would still like to know the answer to the device binding question though, as of now, it works with getting the spi binding for all three sensors.

Related