SD write issue

04 Jul 2019

Hello experts,

we try to migrate our old program from mbed-os 5.3.x to the new 5.12.x. Our basic functions are serial data fetching + SD reading/writing(FATFileSystem) + MQTT sending. We face a strange issue in the new OS. Sometimes, the time of the SD-writing behaviour rises to more than one second, even nearly two second, but the normal situation is around 30 ms. This happens quite regularly. Due to this issue, it seems to cause a bus fault error. The value of the BFSR returns 0x4, which indicates a data bus error.

Has anyone an idea what is the real reason of this issue and how to avoid it?

P.S. in the old OS, the time of SD-writing was normally around 200-400ms.

Best regards, YMZ

10 Jul 2019

Update:

More of our implementation: SD writing tasks were pushed into a memory queue and the actual wrting behaviour was implemented by a separate thread to avoid the conflict of calling two writing tasks at same time.

After adding fflush() and setting a fixed internal write buffer to our data size (380 byte), there was no BFSR fault after 5-day running. But the long latency happened more often after 3-day writing on every 4 seconds, which caused the overflow of the queue and killed the thread.

To expand the size of the queue does not solve our problem, because when the writing duration is more than 1.5 seconds, it will block the serial task, which must be avoided.

So, is there a doable solution to avoid this random long latency?

17 Jul 2019

Since someone has the same issue, the fflush() and a fixed internal write buffer do improve the performance. The long latency was likely caused by the serial thread, which shortly blocked the SD thread with the lower priority.