Closed
Description
This is due to a bug in ST's driver code that's still there today in the latest "cube" release. They managed to demonstrate an awareness of the issue by correctly declaring the CardCapacity
member of the HAL_SD_CardInfoTypedef
structure as a uint64_t
. Unfortunately they don't understand that the width of the type being assigned to is not taken into account until after the calculation on the right-hand side is done, and that calculation is done at 32-bit width. Result: overflow on this line:
pCardInfo->CardCapacity = ((pCardInfo->SD_csd.DeviceSize + 1)) * 512 * 1024;
The fix can be done in a few ways, here's the one I chose:
pCardInfo->CardCapacity = (_cardInfo.SD_csd.DeviceSize + 1) * 512ULL * 1024ULL;