cancel
Showing results for 
Search instead for 
Did you mean: 

SDIO multi block write fails sometimes

snowmonster
Associate II

Hi.

I have few questions regarding SDIO and SD card write performance.

I am using STM32F446 MCU and a simple application using polling SDIO that writes (appends) 32 blocks (16KB) of data to the SD card every 20ms. I do not use filesystem, just writing RAW bytes. Application increases block address offset for 32 before every call to multi block write.

Problem is, that sometimes multi block write fails - times out. It is rare and does not look to have any pattern - looks random.

It times out in a block data writing loop because SDIO_STA_TXFIFOHE becomes 0 during transfer. So, it may write few blocks and then it is stuck until it times out.

Data transfer timeout in DTIMER is set to 0xFFFFFFFF.

I have few questions if there is anyone with more experience with SD cards:

1. Since I do RAW writes, should writing duration be more or less constant? (around 3MB/s)

2. Why would SDIO HW and/or SD card not be ready to receive new words in FIFO once transfer is already in progress?

3. What would be the best way to handle this kind of failure? Because if I call multi block write again immediately, it also fails and needs more than 50ms timeout before another transfer succeeds?

 

Thank you very much, any help highly appreciated.

5 REPLIES 5
FBL
ST Employee

Hello @snowmonster 

According to your first question, RAW writes require less time. Check PERFORMANCE_MOVE field.

About second and third question, it is possible that the SD card may have reached its maximum write speed and is unable to accept any newer data until it has finished writing the current data to the card. You may need to monitor SDIOCLK for write/read. You can start with this check.

FBelaid_0-1688382324058.png

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!
AScha.3
Chief III

1. more or less  - right. more less.

2. my finding: sdcard always have 2 speeds , command (400khz) and data (1 or 4 lines, ...up to 200Mbit). so any command need > 0,5ms time, then data coming; BUT big difference between cheap cards and top brand hi-speed cards; cheap chinese card needed 1ms up to 40ms delay, on write card can delay 100ms and more (up to 300ms is "no error". ) so you know, why you need to wait "sometimes" 50ms or more, then data goes on.

3. noway - except a big ram buffer, for minimum 100ms (and good card, sandisk ultra or kinston canvas plus can do 90MB/s read, 30MB write and delays < 1ms always. )

and check first , what is your real max. speed (i got 0,8MB on F4 with 1bit line ...and 2,5MB/s with 4 bit lane )

If you feel a post has answered your question, please click "Accept as Solution".

Hi.

I doubt it would reach its max write speed since I write in relatively small bursts (32 blocks every 20ms, which takes write operation about 4ms). So, most of those writes are ok ... rarely they fail.

Thanks for your reply, will check the clock, too.

Thanks for your reply.

1. What I meant, write speed probably should not change much between writes if made under same conditions.

2. I am using Samsung PRO Endurance 32GB SD card. I think should be of high quality.

3. I use SDIO (4-bit lane). Due to my app, I can use max 32 block large multi block write, which takes around ~4ms. So that would be around ~3.9MB/s.

But more than "why is ti happening" I'd like to figure out why I can't repeat same write faster. To me it looks like card is not ready, but it may also be related to my driver. I do send CMS12 (stop transmission) after any initiation of multi block write command (CMD25).