Why matching SD cards behave differently on the STM32H743i-eval board?
STM32H743i-EVAL w/BSP V1.11.0
SD Cards:
16GB SanDisk MicroSDHC I C4 (circle C with number inside)
16GB SanDisk MicroSDHC C2
Both cards are supposed to be V2.0. Both work in all the SD devices (cameras, PC, thumb drive adaptors, USB readers). When used in the eval board one ( I C4) fails and the other passes initialization. The point of failure is found in stm32h7xx_hal_sd.c at line 3155 where an attempt is made to send the CMD8 app command. The errorstate returned is 4. It does not always fail which makes wonder if there is a timing problem, however when it does fail it is always the same card that is the SDHC I C4 which I believe is the faster card.
When the command passes on the failing card the hsd>instance structure looks like this:
When it fails it looks like this:
Along the way, while looking for possible timing problems I came across this in stm32h7xx_hal_s at line 519:
HAL_Delay(1U + (74U * 1000U / (sdmmc_clk)));
which happens just before the SD_PowerOn() is called. According to the comments, it is supposed to cause a wait for 74 cycles after the SD init sequence. Question is 74 cycles of what? Since it is a HAL delay call I assume 74 HAL tick cycles. Careful attention to the code will reveal that the equation in the HAL_Delay argument can't possibly come out to 74 because the sdmmc_clk value is calculated with the goal of being 400,000 or thereabouts. That being so, the HAL_Delay will always be 1. The other wrinkle is that I am using ThreadX and the ticks are set to 100Hz Perhaps this is all rather moot if the 74 cycles are with reference to the 400,000 clock currently driving into the SD card. If so, 1 system tick is plenty.
Still this all looks very odd. It may be someone decided it might be possible that the sdmmc_clk might be as low as 1000Hz, in which case this would insure at least 74 scmmc_clk's.
I extended the delay by forcing a longer time to no effect so I am at a loss.