cancel
Showing results for 
Search instead for 
Did you mean: 

MicroSD card problem, bug in the file(stm32f4xx_hal_sd.c) ?

rwmao
Senior
Posted on January 15, 2017 at 23:06

Hello 

I am reporting a bug generated by cubemx in the file stm32f4xx_hal_sd.c.

Please read the thread: 

https://community.st.com/0D50X00009XkfctSAB

 , 

https://community.st.com/0D50X00009XkeRpSAJ

 

Here is the thing:

1. Pack version: STM32Cube_FW_F4_V1.13.0, Cubemx 4.16.1. The uSD card I tested is 1GB made in japan.

2. The lib for microSD and file is generated by cubemx wizard.

3. I tested the microSD on the chip STM32F405RGT6 . . 

4. The problem I confronted is that initialization of sd card always fails, but everything goes through smoothly if I reset the chip(via nrst). Weird? Make the story short. Initialization of SD card fails in the function: SD_PowerON(SD_HandleTypeDef *hsd) with error code SD_COM_CRC_FAILED. Note the function is defined in the file: stm32f4xx_hal_sd.c

5. I moved the HAL_Delay(1) to after clock_enable in the function

SD_PowerON

 , everything is working well.

I am not sure is this sd card related. Any people has similar problem?

#stm32-stm32f4 #sdio #stm32f411 #bug-stm32cubemx #microsd #stm32-sdio-initialization-error
1 ACCEPTED SOLUTION

Accepted Solutions
Amel NASRI
ST Employee
Posted on January 16, 2017 at 13:28

Hi

mao.rongwei

‌,

As said in

https://community.st.com/0D50X00009XkeRpSAJ

, the bug is confirmed and will be fixed in coming driver versions.

-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.

View solution in original post

6 REPLIES 6
Posted on January 16, 2017 at 09:21

SDMMC/SDIO's clock are put out continuously when execute __HAL_SD_SDMMC_ENABLE().

To insert above 1msec delay after __HAL_SD_SDMMC_ENABLE(),it means to send more than 74 initial clock to SDCard.
Amel NASRI
ST Employee
Posted on January 16, 2017 at 13:28

Hi

mao.rongwei

‌,

As said in

https://community.st.com/0D50X00009XkeRpSAJ

, the bug is confirmed and will be fixed in coming driver versions.

-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.

Poonam Deoghare
Associate III
Posted on March 15, 2018 at 10:07

Hi everyone,

I am using STM32F413 Disc Eval.

I am trying to write- read micro sd ( very old samsung 1gb micro sd card) card using sdmmc driver [without file system] .

Its working fine in debug mode in keil but its not working in normal mode( flash code and press reset).

I tried all the above options .But still problem is not solved.

/* Set Power State to ON */

  SDIO_PowerState_ON(hsd->Instance); 

  /* Enable SDIO Clock */

  __HAL_SD_ENABLE(hsd); 

  /* Required power up waiting time before starting the SD initialization

  sequence */

  HAL_Delay(2U);  

/****My code */

HAL_SD_Erase(&hsd, 0X1200, 0X1400);

    HAL_SD_WriteBlocks(&hsd, input, 0X1200, 1, SDMMC_DATATIMEOUT);

   // HAL_Delay(10000);

    HAL_SD_ReadBlocks(&hsd, output, 0X1200, 1, SDMMC_DATATIMEOUT);

    //HAL_Delay(1000);

    printf('\n output is %s \n',output);

 /*******My Output ****/

SD init Done

 CardState is 4

 output is

  Thanks in advance.

Poonam

Posted on March 15, 2018 at 14:07

>>Its working fine in debug mode in keil but its not working in normal mode( flash code and press reset).

You'll need to instrument code and output via serial port so you can understand what's happening without the debugger.

Check all clock are enabled properly, and no critical delays, things the debugger may alter.

Don't use arbitrary delays, and review status returned by functions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 21, 2018 at 09:09

The problem is solved by adding few lines of code for checking status of SD card.

My code working for SD card read write [512 bytes] in polling mode.

HAL_GPIO_WritePin(LED2_GREEN_GPIO_Port, LED2_GREEN_Pin, GPIO_PIN_RESET);

    for (int i =0; i<1;i++)

    {    

    HAL_GPIO_WritePin(LED2_GREEN_GPIO_Port, LED2_GREEN_Pin, GPIO_PIN_SET);

    HAL_SD_Erase(&hsd, 0X1200, 0X1400);

    HAL_GPIO_WritePin(LED2_GREEN_GPIO_Port, LED2_GREEN_Pin, GPIO_PIN_RESET);        

  }    

    while(HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER)

    {}

    HAL_SD_WriteBlocks(&hsd, input, 0X1200, 1, SDMMC_DATATIMEOUT);

    

    while(HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER)

    {}

    HAL_SD_ReadBlocks(&hsd, output, 0X1200, 1, SDMMC_DATATIMEOUT);
Parmin Nayani
Associate III

Thanks for the post. I spent a couple of days looking for an answer to the problem and your post helped me immensely.