SDIO + FATFS + DMA + FreeRTOS advice, currently inconsistent write times + stalling other tasks
Hey,
I have been working on a data logger project that requires sensors to be read at 10Hz, the data timestamped and stored to an SD card. I am using FreeRTOS and a Streambuffer is used to pass data from the measurement task to the storage task. The storage task writes to a daily log file whenever there are at least 1024 bytes in the stream buffer. This usually takes around 4-5ms however sometimes much longer with the highest I've logged being 551ms. Even when using DMA these long writes block other tasks. For example the measurement task that is meant to sample every 100ms will take 110-220ms between measurements.
What is the proper way to implement FatFS on SD cards using DMA without blocking other tasks? Are there any examples of this. What I have works the majority of the time, It can run for multiple hours before any long writes happen. Also I have logged the sensor read timing over UART and it is consistently 100ms between samples if I disable SD card writes. I also have stored a sample number with each measurement and no data is lost during the long writes, it just stalls enough to delay the measurements from happening on time.
I have the measurement task running at priority 4 and the storage task as priority 3. It's not critical for me to have fast SD writes as long as they don't block the functionality of other tasks. With all sensors enabled I will be reading about 2 kB/s worth of data.
I am using a STM32L486ZGTx processor.
Thanks.
