Posted on January 15, 2017 at 22:43 found the problem. The hal file generated by cubemx has a bug(maybe not really).
https://community.st.com/0D50X00009XkeRpSAJ
suggests the solution.
In the file:\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_sd.c,
find the function,
SD_PowerON, move HAL_Delay(1); behind the clock enable.
Problem solved.
static HAL_SD_ErrorTypedef SD_PowerON(SD_HandleTypeDef *hsd){ SDIO_CmdInitTypeDef sdio_cmdinitstructure; __IO HAL_SD_ErrorTypedef errorstate = SD_OK; uint32_t response = 0U, count = 0U, validvoltage = 0U; uint32_t sdtype = SD_STD_CAPACITY; /* Power ON Sequence -------------------------------------------------------*/ /* Disable SDIO Clock */ __HAL_SD_SDIO_DISABLE(); /* Set Power State to ON */ SDIO_PowerState_ON(hsd->Instance); /* 1ms: required power up waiting time before starting the SD initialization sequence */ // HAL_Delay(1); //should be after __HAL_SD_SDIO_ENABLE() /* Enable SDIO Clock */ __HAL_SD_SDIO_ENABLE();//moved to here /* 1ms: required power up waiting time before starting the SD initialization sequence */ HAL_Delay(1);�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?