SDFAT non blocking write for Teensy 4.1

hemantK

New member
Hello All,

For one of my project which has high throughput and logging functionality, I have hot a roadblock where I cannot use blocking write to SD card any more.

I was wondering if anyone has implementing a non blocking write for SDFAT library.

Thanks for reading.
 
Many thanks for the quick response. I had seen this post but the implementation is for non blocking read and not write.
 
There is a problem with async writes to SDCards though. It takes an indeterminate amount of time to write to an SDCard. Sometimes it is essentially the speed at which you can write across the interface. But, sometimes one or more sectors must be erased and bookkeeping needs to happen before more sectors can be written. When this happens the card will block until it is ready. This makes writing potentially more difficult as it can block at any time for reasons known only to the sdcard's controller. I doubt it would be as simple as merely setting up DMA and forgetting it. The device would need to constantly check whether there is a write in progress still blocking and only send blocks when the card is not busy. I haven't looked deep into the belly of the beast in sdfat but I'll bet non-blocking writing will prove to be a little more challenging than reading.
 
I doubt it would be as simple as merely setting up DMA and forgetting it. The device would need to constantly check whether there is a write in progress still blocking and only send blocks when the card is not busy. I haven't looked deep into the belly of the beast in sdfat but I'll bet non-blocking writing will prove to be a little more challenging than reading.
If you're curious, SdFat example TeensySdioLogger illustrates how to use its RingBuf object and isBusy() method to avoid the very long blocking calls. With this method, each 512-byte sector write blocks for 5-6 us.
 
The simpest way to have hight throuput to SD card is
- to have all processing at interrupt level
- handly SD card operation in loop()
- use of large (e.g. 16 MByte extmem) ring buffer
This is equivalent to non-blocking operation.
Works for me for up to 2.4 MBytes/s data recording
 
Back
Top