cancel
Showing results for 
Search instead for 
Did you mean: 

STM32h7 problem with SDMMC Initialization

TLuke.2
Associate II

Hello,

I'm using an STM32h753i-eval2 board and trying to access an SD card through the SDMMC peripheral.

I have my RCC set on Master Clock Output 1.

I has the SDMMC external transceiver present set to no.

System clock mux is set to HSI

PLL Source is HSI

Using PLL1Q as the SDMMC clock, which I've tried at 25, 50, 100, and 200Mhz (docs suggest the slowest SD cards run at 25mhz).

The problem arises in the generated init code in HAL_SD_InitCard when it calls SD_PowerON:

/* SEND CMD55 APP_CMD with RCA as 0 */

   errorstate = SDMMC_CmdAppCommand(hsd->Instance, 0);

always returns SDMMC_FLAG_CTIMEOUT

I've tried increasing the timeout times with no luck. I've stepped through all the clock setup code at runtime and everything looks in order. Any insight would be very helpful and appreciated.

4 REPLIES 4

Typically you'd clock PLL1Q at 200 MHz and divide down that at the SDMMC via SDMMC->CLKCK register, initially dividing down to 400 KHz for first connection, and then up to 25 or 50 MHz depending on ClockDiv passed in. All MicroSD form-factor cards should clock at up to 50 MHz, although the lines ringing on most designs will probably be a limiting issue. The 25 MHz was the full-size (postage stamp size) SD/MMC cards

Watch that the DISKIO or HAL_SDMMC_ routines aren't passing in really quick timeouts, computed as a function of the block counts. Use a minimum of 1000 ms rather than 100 ms.

Check IRQHandler present and correctly bound, lot of #define, watch the linker vs vector table.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TLuke.2
Associate II

Thank you for your response.

I've set the 1Q clock to 200mhz and a sdmmc clockDiv of 3 (which I believe means divide by 4, correct?) To give me 50mhz.

I've increased timeouts to absurd amount (10 seconds). Still have the same issue.

I'm not using an sdmmc interrupt in the NVIC table, is this required?

Oddly enough, if I breakpoint just before MODIFY_REG(SDMMCx->CMD, CMD_CLEAR_MASK, tmpreg);

I can see that the SDMMCx->STA is 0, and then when I step over it, it's instantly 4, which is a response timeout flag. This is before even trying to poll the command response. Not sure if that makes sense, especially if I'm using high timeouts.

This all moves far too fast to single step. Probing / inspecting the SDMMC register space will break the FIFO. Instrument code, and report state/flow that way.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
margce
Associate III

Hi @TLuke.2 any chance you solve this issue? What was the solution?

I'm having a very similar issue with a NUCLEO STM32H5 board that I connected to a custom daughter board with an microSD card running in 

I've check the connections, clock speeds, and every configuration seems correct but when the code hits the SD_PowerON function it returns timeout. Inside the function I can see that the flag SDMMC_FLAG_CTIMEOUT (inside SDMMC1->STA ) is set before the soft timer expires.

Any suggestions on what should I check next?

Thanks