cancel
Showing results for 
Search instead for 
Did you mean: 

SD MMC Power on issue (STM32L4)

Palazzolo.Daniele
Associate II
Posted on December 15, 2016 at 08:55

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.

#delay #sdmmc
8 REPLIES 8
Amel NASRI
ST Employee
Posted on January 12, 2017 at 11:23

Hi

Palazzolo.Daniele

‌,

Reviewing the SD Standard Specification and the HAL driver, it seems that an issue may be faced in card initialization because of a wrong delay. In fact, based on the SD specification, a delay has to be inserted between the call of__HAL_SD_SDMMC_ENABLE() and CMD0. This delay has to be the maximum of 1 msec, 74 clock cycles and supply ramp up time.

A delay of 2ms should be a good solution.

This proposal is already shared internally for farther investigation.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 13, 2017 at 02:06

Dear palazzolo.daniele and Amel N

In fact,many SD Cards need not to set 74 initial clocks and maybe works fine without this.

See Xilinx's FAQ.And I also confirmed this fact in many cards(even old MMCv3!).

https://www.xilinx.com/support/answers/52023.html

I think Your Ultra 64 GB Card may need 74 initial clocks strictly.

To fix this bug is need for ALL SDCards to work more stable.

And I found this same bug in F7Cube HAL Driver.

Amel N,please fix not only L4 but also F7 and others.

Best Regards,

Nemui.
Posted on January 13, 2017 at 09:46

Hi

Nemui.Trinomius

‌,

The update should be applied on all imapcted HAL drivers (not only L4).

In your case, could you please share the SD card model were the problem occurs?

Thank you.

- Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 13, 2017 at 15:20

ATP ProMAX1GB MiniSD(bought 9 years ago).

This is the only card required at least 74 init clocks strictly that I have.

Gabriele Caletti
Associate II
Posted on April 27, 2017 at 16:33

Hi

Although I moved the HAL_Delay() function as you suggested, I actually still have the same problem (i.e I receive a SD_COM_CRC_FAILED when sending the SD_CMD_APP_CMD) on a F412 and HAL v1.14.0.

With all other cards it is ok, and this card (a Sandisk 2GB) with the old software (which was based on the Std Periph Library) works fine. Do you have any idea what it could be?

Many thanks for your help!
Posted on April 27, 2017 at 19:04

Hi

Caletti.Gabriele

‌,

Could you please check using the last version of the STM32CubeF4 package (V1.16)?

The HAL SD driver was reworked since the version 1.15 of the Cube package.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on April 28, 2017 at 08:21

Thanks for advice, I will try it today, then I'll let you know.

Posted on April 28, 2017 at 15:14

Hi

st.mcu

I tried v1.16 and it seem to work fine. Since the SD API changed and I'm sharing this code with a F2-based project as well, do you when when a new HAL for the F2 will be available?

Many thanks!