STMicroelectronics / stm32h7xx-hal-driver

Provides the STM32Cube MCU Component "hal_driver" of the STM32H7 series.
BSD 3-Clause "New" or "Revised" License
97 stars 43 forks source link

SDMMC MMC HighSpeed/DDR ClockDiv too high at 52MHz #60

Closed royb3 closed 1 month ago

royb3 commented 5 months ago

Describe the set-up

Using STM32CubeIDE 1.15.0 with latest board package.

Describe the bug When running the SDMMC peripheral at 104MHz (Required for DDR), and switching the Bus speed to 52MHz DDR. The Clockdiv calculation is off by 1, causing the MMC Clock to run at 26MHz.

How To Reproduce

  1. Indicate the global behavior of your application project

  2. The modules that you suspect to be the cause of the problem (Driver, BSP, MW ...) The stm32h7xx_hal_mmc.c, line 4046: Init.ClockDiv = (sdmmc_clk / (2U * MMC_HIGH_SPEED_FREQ)) + 1U;

  3. The use case that generates the problem When running the clock slightly below 52MHz, the clockdiv is set correctly, but at 52MHz precisely, it is set too high.

  4. How we can reproduce the problem As described above.

Additional context A possible fix could be to add 1 to the divider, so the 52MHz would be rounded down: Init.ClockDiv = (sdmmc_clk / (2U * MMC_HIGH_SPEED_FREQ + 1U)) + 1U; 52MHz will then get rounded down, and the clock div gets correctly set to 1.

KRASTM commented 5 months ago

Hello @royb3,

Thank you for the report.

I agree that when SDMMC peripheral at 104MHz and switching to MMC high-speed causing the MMC Clock to run at 26MHz.

But I don't know what you mean in the third point: When running the clock slightly below 52MHz, did you mean, rather to work with 104MHz, you choose a clock below 52MHz?

Could you explain or share more details, so we can confirm the issue.

With regards.

royb3 commented 5 months ago

Hi @KRASTM

When I set the sdmmc clock at 103.999 MHz, the clockdiv is correctly being set to 1, causing the MMC clock to run at 52MHz. This is the workaround I now use for getting 52MHz HighSpeed / DDR.

KRASTM commented 5 months ago

ST Internal reference: 184656

KRASTM commented 1 month ago

Fixed in commit https://github.com/STMicroelectronics/stm32h7xx_hal_driver/commit/6f5e35e30ac09ba7bf44139a97b289d3df53cf9c

royb3 commented 1 month ago

@KRASTM Thank, this fix would work for me since I will set the clock to 104, but if I now would set the clock to something between 52 and 104, this would lead now lead to an invalid clock div of 0.