2020-06-03 07:38 AM
Hi
i'm using an own made stm32h750vb board to write on sd memory using fatfs third party lib from cubemx.
the problem i encountered is unstable function of f_write. sometimes it takes more time to write.
to measure the time f_write takes i set a gpio pin before and after it, and monitored the pin by oscilloscope.
in my code i generate a timer interrupt to write on certain times on sd memory and compare to gpio pin i set to measure f_write speed.
in picture up signal shows gpio pin set before f_write and reset after f_write, and down signal edges show timer interrupt that f_write starts on this transition.
as you see at first picture(left one) sometimes f_write takes more time. result is for writing a 16k block size dummy data, 400mhz cpu clock, 50mhz sdmmc clock with 4bit interface,and a sdhc microsd 4gig c4 memory.
i tried different data block size(512byte,1Kb,4Kb,8Kb,32Kb) with different swmmc clock speed from 25mhz to 100mhz), but the problem still exists.
i tried to investigate if the problem is with f_wrie function or bsp_sd_driver. i put the gpio test pin before and after hal_write_sd_blocks function that interfacing with sdmmc in lower level of f_write and it seems to work fine (secondpic) and inconsistency of write to sd is related to something in f_write function!
please help.
2020-06-03 07:45 AM
It is caused by the internal controller in the card, doing wear leveling, ECC recovery and whatnot. You can't do anything about it. An SD card is a consumer product not suitable for real time operation.
Delays of 10 to 20 ms are quite common, up to 250 ms have been observed. Get a bigger buffer for your data, write in a separate task, and pray.
2020-06-03 07:53 AM
FatFs manages file structures and Fat tables, your f_write may cause several read and write operations at the DISKIO layer, instrument that to better understand the interactions. The command/response of the media's controller can be relatively slow at times.
2020-06-03 07:56 AM
All the source code is available for inspection.
Check buffer alignment, and read the cards erase block size info, it is doing a lot of shuffling of block resources on the NAND.
FatFs manages the blocking/deblocking or unaligned writes into a file.
2020-06-03 07:57 AM
thanks berendy,I admit your answer somehow, but i doubt that.
i tried a different sd memories,write delay varied but still exists. also as you see in picture some delays of writing is not related to hal_sd_write_blocks that write data to sd and seems to be related to f_write function operation!!
2020-06-03 09:13 AM
so you are approving that problem is related to sd memory operation?
is there any class or type of sd memory that have less delay or inconsistency?
2020-06-03 11:41 AM
> is there any class or type of sd memory that have less delay or inconsistency?
Faster cards will be more responsive, but no cards will be instantaneous for all operations, particular with file system operations which can write to several areas for a single file operation. The delay can also vary depending on factors outside of your control. That's just how SD works. You're not interfacing with the memory directly.
2020-06-04 10:44 AM
Look for cards with A2 speed rating.
2020-06-04 11:24 AM
I'm saying a couple of things, a) interactions are more complex than just your requests to f_write(), b) the cards ultimately pace the access speeds and their internal buffering/blocking strategy.
High end brand devices will have better and more consistent performance than "catch-of-the-day" devices
2020-06-06 01:42 AM
thanks to all.
i got the fastest sd memory supported by stm32h7 series that is a sdhc uhs-i U3 sd memory and it seems the problem solved. this class of sd memory guarantee for at least 30MB/sec speed.