0
\$\begingroup\$

I'm a software developer and trodding in murky waters here so please do forgive my lack of knowledge. I've been developing a sensor with the nRF9160DK and some accelerometers. I need to continuously write data to a memory as the RAM is not enough to hold an entire event.

I've tried a NOR-flash, it was not fast enough, I need to write at least 32kB/s. I tried an sd-card. It was fast enough but allocating new pages took a bit too long and the power drawn was way too high. I'm now thinking of a NAND or FRAM external memory and writing via QSPI. The memory size needs to be at least 8MB which might make FRAM difficult.

Here is where I'd like help. What would you recommend? What draws the least but still fulfills the speed demands? If there is a specific product you have in mind, I'd greatly appreciate it. Or maybe an alternative, I found this that might be interesting: https://www.electrokit.com/en/product/sparkfun-openlog-2/ as it draws 2mA in idle mode though I doubt that is with the sd-cards draw included. I'm open to any recommendation to solve this! It's the last bump in a very long road I have been traveling.

I should mention I've also tried shutting down the sd-card and starting it first at en event is triggered but the mounting time is too slow(148 ms) and critical data is lost. I could save 148 ms of data in RAM but I don't think the mounting operation can be paused or multithreaded in the required way.

Thank you beforehand and please, ask if I didn't include information I did not know to be vital.

\$\endgroup\$
12
  • \$\begingroup\$ Is this a continuous write? 32kB/s doesn't seem that fast though. \$\endgroup\$ Commented Feb 2, 2022 at 15:20
  • \$\begingroup\$ Yes, 32kb/s for up to 20 seconds \$\endgroup\$ Commented Feb 2, 2022 at 15:28
  • 1
    \$\begingroup\$ Is it kB or kb? How long is downtime? \$\endgroup\$ Commented Feb 2, 2022 at 15:32
  • \$\begingroup\$ Sorry, 32kB/s. Downtime as in time between events? That could be anything from 0 seconds to many days \$\endgroup\$ Commented Feb 2, 2022 at 15:38
  • \$\begingroup\$ Some of the 64 and 32MB NAND flash I'm seeing says 50us for byte programming, 1ms for 256 byte page writes, and 2ms for 512 byte page writes. That should be more than enough except for bytewise writes. Are you writing piece meal? Or erasing pages all the time or something? \$\endgroup\$ Commented Feb 2, 2022 at 15:48

2 Answers 2

1
\$\begingroup\$

I am just going to address the SD card part.

First of all, for efficient writes, you must write data in blocks of 512 bytes (to match the block size*). If you write data in sizes that are not multiples of 512, or not aligned to 512 byte boundaries, the card will have to erase and rewrite each block multiple times. So, buffering is essential.

Second, you have a number of options to reduce the latency:

  • use a good quality SD card rated for high speed,
  • preallocate a contiguous file to the required size,
  • ensure the filesystem on the SD card is not fragmented, and ideally formatted with the official tool,
  • give up on the filesystem entirely, and just use the card as a block storage device.

As for multi-threading, there is no reason why that wouldn't be possible as long as the SD thread and the data collection thread don't use the same hardware resources.

* also called sector size, for some cards it might be 1024 instead of 512 — check the one you're using.

\$\endgroup\$
3
  • \$\begingroup\$ Thank you! What an answer! Does the size of the sd-card affect performance? I have formatted the 32gb sd-card with the official tool and it says the clustersize are 32kB. So I should write 32kB in one swoop then? That is one second of data and there is more than enough RAM for that. If I were to give up on the filesystem, I have no idea how I would write data, could you care to explain the general idea and function behind this? Sorry, but this is all new to me. I'm learning as I'm going. Really appreciate the help, you have no idea. \$\endgroup\$ Commented Feb 3, 2022 at 8:21
  • \$\begingroup\$ @nwretborn briefly, cluster != sector. Maybe it's called block size in the tool? I'll get back to the other questions in a bit! \$\endgroup\$ Commented Feb 3, 2022 at 9:58
  • \$\begingroup\$ preallocating a file solved the write problem speed, I thank you for that! Now it's just the multithreading part of the mounting procedure that remains to be solved. \$\endgroup\$ Commented Feb 8, 2022 at 12:14
0
\$\begingroup\$

I am going to address two other options:

Modern SPI/QSPI NOR flash easily supports 128-256 kByte/s continuous write bandwidth if you ensure that the sectors are pre-erased before writing. Whether you use it in QSPI or SPI mode does not matter. The SPI bandwidth is not the bottleneck when it comes to write performance.

Standby current of flash is less than 100µA, and less than 25mA while actively writing.

You did not list non-volatility as a requirement. There are PSRAM with SPI or QSPI interface which can handle extremely high write bandwidths. No need for pre-allocation or pre-erasing sectors. Power consumption is similar to flash.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you Timmy, it seems as though my use of the drivers are the problem and a much lower standby current of the sd-card should be reachable. I will look this over. I thank you for your knowledgeable answer \$\endgroup\$ Commented Feb 9, 2022 at 23:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.