2020-07-11 10:39 AM
We are using the SDMMC interface in an STM32H7 device. The first call to HAL_MMC_WriteBlocks_DMA takes anywhere from 50-350ms to return. Susequent calls take 2-5ms to return. The long delay messes up the timing in our application. What is the reason for the long delay? We believe it has something to do with the callback function, but we're not sure.
2020-07-11 12:12 PM
Does it take that long to return or to complete? It shouldn't be a blocking function. Although the HAL MMC support is lacking.
The first write will take longer as the MMC chip needs to get ready. The time to write a block is variable. That's just how MMC works. Subsequent calls are quicker as the MMC can guess where you're going to write and it prepares beforehand.
You can mitigate this a bit by getting a faster chip/card, but it will always take longer to write the first block.
2020-07-12 09:06 PM
TDK,
Thanks for the reply. Someone else on the project did some more debugging and verified the delay is inside the eMMC device. He also found a line in the JEDS84-50.1 standard that stated: "Some Devices may require long and unpredictable times to write a block of data." That jives with your input, so we'll come up with a workaround.
2020-07-13 01:57 AM
SD, eMMC and similar devices have unpredictable response times because they have an internal controller which manages NAND flash error correction, wear levelling, whatnot.
Even if you measure 350 ms and 5 ms now, it would degrade over time as there would be more bad blocks to correct, it would be harder to find a spare one etc.
The only workaround is to allocate a huge buffer for outstanding writes and pray.