Skip to main content
krestan
Associate II
April 7, 2016
Question

STM32F4 SDIO high speed write to sd card

  • April 7, 2016
  • 7 replies
  • 5638 views
Posted on April 07, 2016 at 14:15

I've a following problem. I'm using STM32F427VG connected to microSD card via SDIO interface. I'm using ST driver, configured for 4-bit data access and DMA tranfer. I need to reach continuous write speed above 3000kb/sec, but the write sometimes hangs and the transfer is interrupted for more than 200msec (sometimes even 500msec), which is a problem. I've a constant data stream and I can not allocate too large buffer in a memory, because I've only internal SRAM in STM32 available (I can only accept not more than 30-50msec delay). I'm using multiple block tranfer, each block in size of 16Kb. I've tried different sd cards, but still the result is the same. If I put the card to the computer, then the write speed is much higner than 3000kb/sec and I don't expect it's a timeout generated by the card, this is too long timeout I guess.

#stm32f4-sdio
This topic has been closed for replies.

7 replies

Tesla DeLorean
Guru
April 7, 2016
Posted on April 07, 2016 at 15:44

You'll probably want to instrument to understand where the time is going.

I'd probably look for it writing file system structures outside the linear flow of the data. You could perhaps preallocate the file space, or use lazy write caching of the table updates.

It is hard to compare operation with a 3GHz PC with 4GB of RAM against a STM32F4

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
stm322399
Senior
April 7, 2016
Posted on April 07, 2016 at 16:03

Be sure that the timeout up to ''250ms (or twice that value)'' comes from SDCard specification, you have to live with.

Your PC has plenty of memory to buffer writes and sustain a high average throughput, try to buffer as much as you can on your MCU.

krestan
krestanAuthor
Associate II
April 7, 2016
Posted on April 07, 2016 at 22:56

I know that comparing it with the PC is not much reasonable. What I don't uderstand, if there is some trick how to manage some linear data flow of write without this significant delay. I need to grab the compressed image data from DCMI and write them to the micro SD and I've here on a table quite cheap MJPEG camera, where is only one single IC connected to the camera and micro SD and it's not something what looks like with a megabytes of SRAM and it can reach this data flow without any problems and my application is having a frame drops when the card write hangs for such a long time. I'm having only around 100Kb buffer, which can handle approx. 30msec write delay.

Tesla DeLorean
Guru
April 7, 2016
Posted on April 07, 2016 at 23:32

Must be something with your code, I can delivery 9.7 MB/s sustained writes on a 256MB file, with 32KB blocks, through FatFs, and 13.9 MB/s reads, using an 84 MHz STM32F401 part, and a 16GB SanDisk Ultra. I've also cross-checked the integrity of the data both on the target system, and after the fact on a PC.

Now admittedly I'm playing with a bit of a stacked deck, but I'm pretty sure I'm not seeing any timeouts/dropouts.

CPU:84000000, SDIO:67200000,33600000

CRC32 D5F18244 Memory Image

268435456 Bytes, 2320154779 Cycles

9.718566 MBps Write (FatFs)

268435456 Bytes, 2302213160 Cycles

9.794305 MBps Write (FatFs)

268435456 Bytes, 1621010257 Cycles

13.910201 MBps Read (FatFs)

268435456 Bytes, 1621079461 Cycles

13.909607 MBps Read (FatFs)

CRC32 (990702) Copyright (C) Micro Solutions Inc., 1991-1999

Calculate the CRC-32 of the file.

CRC-32 D5F18244 (  20175532 Bps)

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
mostafa z
Associate II
April 16, 2017
Posted on April 16, 2017 at 14:26

Hi

how compute this value?

SDIO:67200000,33600000 

i am using stm32f407 by samsung 16G sd card but write speed is 2MB/s!!!

and no difference speed between BSD_SD_ReadBlocks_DMA  and  

BSD_SD_ReadBlocks function?!!

please help me

Tesla DeLorean
Guru
April 8, 2016
Posted on April 08, 2016 at 06:52

Might also want to check the errata for SDIO/DCMI DMA interactions. I'm not big into cameras and video these days.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Andreas S.
Associate II
August 24, 2017
Posted on August 24, 2017 at 11:15

Hi all,

I am trying to get a hight speed write to SD via SDIO as well. I use a project generated with Cube MX, 4bit SDIO and DMA. But I only get a write speed of about 300 kBytes/s. I write 1000 times a 100 byte block, because I need a write about every 100 us. With a 100 byte block I have a write time of about 25 us, but every fifth time over 1 ms. Weird...The time span to the 1 ms write decreases the less bytes I write.

When I look at the trace of TrueStudio, I see that more than 60% of the time is spend in the function SDMMC_GetCmdResp1, compared to only 0.05% in BSP_SD_WriteBlocks_DMA...

I am running it on a STM32f429IGT on a WaveShare Board at 180MHz with 8MHz external crystal. My clocksettings for the main clocks are 8MHz HSE, M=8, N=360, P=2, AHB Pre=1, APB1 Pre =4 and APB2=2 -> 90 MHz -> its this to high?.

Clocksetting for SDIO is 0, as CubeMX advises.

What would the max speed be for a write to SD card via SDIO?

I use a 16Gig SD card with SpeedClass 10 from SanDisk.

I have played around with some settings of FatFs, e.g. set the _MIN_SS and _MAX_SS to 4096, then I have a write speed of about 2MBit/s, but the card is not readable in Windows anymore.

Another interesting thing is, when I compile it with O2, the written file seems to be corrupted...

Thanks a lot,

best regards

Andreas

Wisnu Pramadi
Associate
October 13, 2017
Posted on October 13, 2017 at 08:15

Hi Andreas,

It seems that the Cube MX generated code try to check whether the SD card busy or not by pooling on 

SDMMC_GetCmdResp1. In my case the SD card stay busy for ~100ms after writes.

Andreas S.
Associate II
October 16, 2017
Posted on October 16, 2017 at 10:02

Hi Wisnu,

thanks, I will check that.

Another issue is, that switching to 4 bit mode does not work in a project created by CubeMX, I wil create a question for that.

Poonam Deoghare
Associate II
March 28, 2018
Posted on March 28, 2018 at 08:56

Hi team,

I used 1bit bus mode for DMA write for writing 1000 blocks in loop one at a time.

Time taken to complete this operation was 930 msec.

I changed bus mode to 4-bit mode for same operation and time observed was 900 msec.

I was expecting less time but its almost same. Do I need to do some other setting to make 4 bit bus mode work.

Steps I followed:-

selected 4 bit mode for sdio in cubemx and generated the code.

Tesla DeLorean
Guru
March 28, 2018
Posted on March 28, 2018 at 13:18

Not going to confirm timing, but single sector reads have significant overhead, basically worst case scenario. Read 1000 sectors not 1 sector 1000 times.

After the card connects at 400 KHz at 1-bit it usually negotiates up to 24-25 MHz at 4-bits

Not wading into issues with CubeMX code generation.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Poonam Deoghare
Associate II
March 28, 2018
Posted on March 28, 2018 at 15:41

Read 1000 sectors not 1 sector 1000 times.

>> I am incrementing read_addr by 512 bytes each time.

and loop goes on 1000 times so it means i am reading 1000 blocks.

Please let me know if I use 4bit bus mode then it should work like how it works for 1-bit mode but with more throughput.