AnsweredAssumed Answered

FatFS SDIO DMA write speed

Question asked by polotnyanko.nikita on Jul 23, 2014
Latest reply on Jul 23, 2014 by polotnyanko.nikita
I'm trying to get more SD card write performance with STM32F207ZET6 + SDIO + DMA + FatFS.
I'm using Kingston 8GB MicroSDHC 4 class. I formatted it with SD Formatter tool. File system FAT32 with 32KB clusters.
Write speed on PC with USB card reader is 5 MB/s.
PCB design seems fine:
1. 33k pull-ups for all SD card lines except CLK.
2. 3.3V powered SD card and decoupled with 100n ceramic in parallel with 4u7 ceramic X7R and 68u tantalum.
3. Short PCB traces from uC to SD card (less then 30mm).
With 32KB write buffer I can get only 1.66 MB/s write speed.
I tried few different FatFS + STM32 + SDIO + DMA implementation:
1. This code from clive1:
2. This code from Nemui:
3. STM32CubeF2 FatFs_uSD code example:
It's all configured as SDIO + DMA + 120MHz SYSCLK + 48MHz SDIOCLK + 24MHz SDIO_CK + 4-bit bus wide.
And all this gave the same write speed test result - 1.66 MB/s with 32KB buffer.
I measured write speed with this code:

#define SD_WRITE_BUF_SIZE 32768
    // Test write
    uint8_t sd_buf_write[SD_WRITE_BUF_SIZE];
    uint32_t cnt = 0;
    uint32_t i = 0;
    while (i < SD_WRITE_BUF_SIZE)
        sd_buf_write[i++] = (cnt>>24)&0x0FF;
        sd_buf_write[i++] = (cnt>>16)&0x0FF;
        sd_buf_write[i++] = (cnt>>8)&0x0FF;
        sd_buf_write[i++] = (cnt>>0)&0x0FF;
    for (;;)
        rc = f_write(&Fil, sd_buf_write, SD_WRITE_BUF_SIZE, &bw);
        if (bw<SD_WRITE_BUF_SIZE) while(1);
        if (rc) while(1);

        rc = f_sync(&Fil);
        if (rc) while(1);
I started it for 100 seconds and calculated the write speed value as file_size/100.
I got fastest write speed with 3*32KB buffer - 2.8 MB/s.
I read on this forum that clive managed to get up to 10 MB/s write speed with fewer buffer size.
What could be the the bottleneck in my case?