cancel
Showing results for 
Search instead for 
Did you mean: 

SDIO fail to run over freq > 2MHz

YMant.1
Associate II

Hello Everyone !

I am using 4bit SDIO over STM32 F4 Nucleo board (STM32F412ZG).

I am facing issue when running higher SDIO_CK clock.

When I use smaller 'Div' value (higher freq), it does not produce correct clock and in stead produces very small clock in hertz/Kilohertz and also does not send any signal over D[0-3].

Because of this I end up in getting 'Data underrun' problems while writing.

But when I use smaller clock than 2MHz, SDIO works just fine.

Anyone faced similar kind of issue?

Attaching the clock configuration here

This is same behaviour even when I use SDIOCK (marked in image) <=24MHz.

Additional details -

  • Hardware flow control disabled
  • 4 bit bus
  • Clock power save disabled
  • Clock edge falling (also checked with rising)
  • Clock bypass disabled

5 REPLIES 5
TDK
Guru

The HAL code is not optimized enough to keep up with higher clock rates. You can compile in Release mode to mitigate the issue, or manually unroll/optimize the loops responsible for feeding/reading information.

If you feel a post has answered your question, please click "Accept as Solution".

Double check PLL settings and clock routing.

Would suggest unpacking RCC settings to present what the hardware configuration actually looks like. Then confirm it matches expectations.

There are AHB/SDIO related clocking expectations.

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

Thank you @Community member​  for your input !

As you said, `There are AHB/SDIO related clocking expectations.` are there any specific requirements for that?

I had tried to alter the clock from HSE, HSI and sysclk. But it did not work on higher frequencies.

Current clock settings are as-

Do you feel any obvious issues there?

YMant.1
Associate II

image not shown, adding as attachment..

The Reference Manual for at least some of the F4 series talks about a specific ratio, which I interpret to prevent clock inversions or pipeline stalls as it moves data across clock domains.

"PCLK2 and SDIO_CK clock frequencies must respect the following condition: Frequency(PCLK2) ≥ 3 �?� 8 × Frequency(SDIO_CK)"

On the original F4 there wasn't an explicit statement about the PLL running, so there was some confusion about why a 16 MHz HSI run system couldn't use SDIO. In the days of CubeMX diagrams this is perhaps a little clearer, plus in later model F4's the "48 MHz" source could be derived elsewhere and could be higher..

"The SDIO uses two clock signals:

• SDIO adapter clock SDIOCLK up to 50 MHz (48 MHz when in use with USB)

• APB2 bus clock (PCLK2)"

It doesn't explicitly state this comes from a PLL that must be running, and a work-around for an errata puts the top speed at 75 MHz, not 50 MHz. The same errata for the older model F4 indicates BYPASS mode doesn't work properly, and experience indicates HW Flow Control is also broken.

Polled mode has some vulnerabilities to overrun/underrun, as the data transfer phase is not interruptable, and is intolerant to the MCU wandering off to other tasks mid-stream.

2 MHz in my estimation is very slow, a properly wired and terminated SD cards should get to 24 MHz without a problem. There are checks for signal slew in 4-bit mode, but I don't think those present as over/under-run conditions.

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