cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SD_GetCardState Unreliable Delay

ZThat
Senior

Hello All,

I am attempting to utilize the SDMMC port on the STM32F7 to transfer large images from external SDRAM to an attached SD card.

I am currently doing this successfully at 5 FPS. I want to speed it up to 10 FPS, but I am having unreliable delays when writing to this SD card. It is a class 10 SD card, which should allow me to transfer files at 10MB/s. My images are roughly half a MB, so I should theoretically be able to transfer 20 FPS if I didn't have to worry about capturing additional images from the camera and processing them. I have ensured that I can process the images at 10FPS if the SD card writes at the advertised speed. However, I am seeing occasional delays.

The SD card interrupt frequency led me to believe that it is saving images at the advertised speed, but when I then try to immediately start another write (or even after a sufficiently short time period), I get a HAL error while writing. I can use two methods to eliminate this error.

1) I make my continuation contingent on the HAL_SD_GetCardState function call returning that the SD card is ready, but the time period that it takes the SD card to be ready according to this function call is highly variable. It can randomly slow me back down to the point where I must write at only 5 FPS. Sometimes the HAL_SD_GetCardState actually completely blocks me for an extended period of time and doesn't allow me to capture additional camera images.

2) I insert a 0.1 second delay between my writes. Much shorter seems to cause issues, but at least this doesn't randomly block me like the HAL_SD_GetCardState tends to

I have both an IT transfer and DMA transfer of the images functional. Is there any better way (for either an IT or DMA transfer) to tell that the SD card is ready for another write than with the HAL_SD_GetCardState function? Also, has anyone seen this perform more reliably? I am seeing different results day to day, and I am not sure if that is just the SD card algorithm accounting for my writes with different memory management patterns or if it is because of a degrading connection.

Also, I am using a SMLE04DA1 SD card. Has anyone had more success using my same method with a different type of SD card that can actually reliably write video at the advertised speed?

Thanks!

2 REPLIES 2
EKirs.1
Associate

I have also been struggling with similar issue. I did some tests to measure these occasional delays.

I write 32Kbyte buffers sequentially during several minutes. Each of those buffers contains a timestamp in uS (taken from from an MCU timer and placed in the block being written). Then I analyze the recorded time stamps on my PC.

Normal writes take about 8ms (i.e. 4Mbytes/s), which actually matches the SD card class (4) write performance. However, often this time is actually higher (40ms, 90ms) and even less frequently I have really long delays up to 1-2 seconds!

If someone has already solved this issue, it would be nice to know the solution.

The above test is done on STM32L496 MCU, STM32Cube_FW_L4_V1.16.0, with FreeRTOS and DMA, but without FatFs. I start writing from sector 0 from 4-byte aligned memory buffer in SRAM.

Thank you.

Here is the graph with the write duration.0693W000004K7hXQAS.jpg