AnsweredAssumed Answered

SD MMC Power on issue (STM32L4)

Question asked by palazzolo.daniele on Dec 15, 2016
Latest reply on Apr 28, 2017 by Gabriele Caletti
Hi,
I'm developing a firmware for a custom board with a STM32L486 microcontroller.
The device record the audio to a micro SD card.
I'm using the HAL driver.
It's work fine with at least 6 different sd card that I have (Productors and size differents), but I tried a Sandisk Ultra 64 GB.
The HAL_SD_Init work only the first time. I've implemented a state machine with SD Init and SD DeInit functions, when I try remove and insert again the sd card, the HAL_SD_Init function fails. With the other SD Card this operation works correctly.
I checked the issue, and I saw that the problem is in static HAL_SD_ErrorTypedef SD_PowerON(SD_HandleTypeDef *hsd) function.
The command that the card fails is SD_CMD_APP_CMD and the error is SD_COM_CRC_FAILED . The prevous SD_CMD_GO_IDLE_STATE and SD_SDMMC_SEND_IF_COND is ok.
if the I change the code:
/* Power ON Sequence -------------------------------------------------------*/
  /* Disable SDMMC Clock */
  __HAL_SD_SDMMC_DISABLE(hsd);
 
  /* Set Power State to ON */
  SDMMC_PowerState_ON(hsd->Instance);
 
  /* 1ms: required power up waiting time before starting the SD initialization
     sequence */

  HAL_Delay(1);
 
  /* Enable SDMMC Clock */
  __HAL_SD_SDMMC_ENABLE(hsd);
in :
/* Power ON Sequence -------------------------------------------------------*/
  /* Disable SDMMC Clock */
  __HAL_SD_SDMMC_DISABLE(hsd);
 
  /* Set Power State to ON */
  SDMMC_PowerState_ON(hsd->Instance);
 
  /* Enable SDMMC Clock */
  __HAL_SD_SDMMC_ENABLE(hsd);

  /* 1ms: required power up waiting time before starting the SD initialization
     sequence */

  HAL_Delay(1);
It works fine. I just move the HAL_Delay after __HAL_SD_SDMMC_ENABLE.
I searched in the reference manual of the microcontroller why the HAL driver wait 1 ms before to enable SDMMC CLK, but I don't found nothing.
I saw that if I sent two times the commnd SD_CMD_GO_IDLE_STATE or sent another SD_CMD_APP_CMD, the card works correctly too.
It's ok the delay before __HAL_SD_SDMMC_ENABLE or can I move it after this command?
Why I must wait 1 ms after SDMMC_PowerState_ON and I cannot Enable SDMMC Clock.

Outcomes