Skip to main content
Visitor II
June 3, 2020
Question

why fatfs f_write has unstable speed?

  • June 3, 2020
  • 5 replies
  • 3637 views

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.​

    This topic has been closed for replies.

    5 replies

    Visitor II
    June 3, 2020

    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.

    Saghi.1Author
    Visitor II
    June 3, 2020

    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!!

    Graduate II
    June 3, 2020

    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.​

    Graduate II
    June 3, 2020

    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.​

    Saghi.1Author
    Visitor II
    June 3, 2020

    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?​

    Super User
    June 3, 2020

    > 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.

    Visitor II
    June 4, 2020

    Look for cards with A2 speed rating.

    Saghi.1Author
    Visitor II
    June 6, 2020

    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.​