Non blocking writes to sd card

hey everyone, I'm trying to to make a data logger for a flight controller I'm working on. I will be buffering all data that needs to be stored on the sdcard and writing out chunks in multiples of sector size (512 bytes). What I am unsure about is whether the sdfat library uses non blocking dma writes or if it blocks on writing to files. If anyone knows the answer to that or could show me how to make it non blocking I would really appreciate it! Thanks!
 
If you have acquisition running at interrupt level and sd card access in loop(), then SD card access is not blocking acquisition. See the different logger examples.
SdFat could be set to DMA if SPI access (i.e NOT T4.1 built in SDcard) but Bill Greiman suggests not to use DMA. SDIO access (T4.1 built in card) does not support DMA (AFAIK).
 
Last edited:
SdFat is blocking for both read and write. There is a fairly recent thread where someone modified SdFat to do non-blocking reads, but not writes. There is a way, though, to limit blocking times to 5-6 us and avoid the very long blocking times of 40+ ms. SdFat example program TeensySdioLogger shows how.
  • define an SdFat RingBuf large enough to hold ~50 ms of data
  • use SdFat's preAllocate() function to create however large of a file you want
  • always write to SD in chunks of 512 bytes (one sector)
  • use SdFat's isBusy() function to avoid writing when the SD card is busy
 
@joepasquariello: SD access ONLY blocks other actions in loop(). If ALL other functions run at interrupt level these are NOT blocked. In acquisition systems it is anyway preferable to have acquisition and RT processing at interrupt level (as audio library does)
 
@joepasquariello: SD access ONLY blocks other actions in loop(). If ALL other functions run at interrupt level these are NOT blocked. In acquisition systems it is anyway preferable to have acquisition and RT processing at interrupt level (as audio library does)
Yes, only loop() will be blocked. What I'm saying is that if you want to avoid those occasional long blocking times of 40+ ms, there is an easy way to do it.
 
Back
Top