2020-02-11 06:56 AM
Hi.
Im experiencing a race condition in SDMMC_CmdReadSingleBlock. (being called trough HAL_SD_ReadBlocks_DMA).
SDMMC_CmdReadSingleBlock calls SDMMC_SendCommand in order to start transfer.
Then it calls SDMMC_GetCmdResp1 to verify that transfer is started.
Problem occurs when code is interrupted (by unrelated interrupts) between SDMMC_SendCommand and SDMMC_GetCmdResp1.
If the interruption last long enough, transfer will be finished and HAL_SD_IRQHandler will be executed before SDMMC_GetCmdResp1 is allowed to run.
HAL_SD_IRQHandler clears the SDMMC-flag that SDMMC_GetCmdResp1 is looking for, and SDMMC_GetCmdResp1 eventually returns with timeout-error.
This in turn causes HAL_SD_ReadBlocks_DMA to return with error.
I am able to disregard the error returned by HAL_SD_ReadBlock_DMA by verifying through HAL_SD_RxCpltCallback that transfer actually were successful.
Problem is that SDMMC_GetCmdResp1 has such a long timeout condition.
The timeout is hardcoded to 5s with a macro. Does it really need to be this long?
All it does is to wait for a command-respons. It should be a matter of ms, right?
But actually it gets even worse.
The timeout is implemented as a while-loop with a counter.
It does not take into consideration that it can be interrupted!
In my case, SDMMC_GetCmdResp1 times out after 15s.
So im wondering, will there be any changes to this driver in the near future?