Skip to content

Commit

Permalink
Bugfix for Nucleo slow SDMMC clock
Browse files Browse the repository at this point in the history
Clock setup for SDMMC peripheral moved into main().

Previous SPI clock source fix had introduced a regression when
NUCLEO_SLOW_SDMMC_CLOCK was defined.
  • Loading branch information
dresco committed Jan 22, 2024
1 parent d2e5b61 commit bb27fe4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Src/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2364,7 +2364,7 @@ bool driver_init (void)
hal.info = "STM32H743";
#endif

hal.driver_version = "240119";
hal.driver_version = "240122";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
#endif
Expand Down
14 changes: 12 additions & 2 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ void SystemClock_Config(void)
// Clock configuration
//
// - 480MHZ system clock
// - 48MHz clock for USB, SDMMC, SPI1/SPI2/SPI3 from PLL1Q
// - 48MHz clock for SPI4/SPI5 from PLL2Q
// - 48MHz clock from PLL1Q - USB, SDMMC1, SPI1/SPI2/SPI3
// - 48MHz clock from PLL2Q - SPI4/SPI5
// - 12MHz clock from PLL2R - optional SDMMC1 clock source with NUCLEO_SLOW_SDMMC_CLOCK
//
// WeAct MiniSTM32H7xx & BTT SKR3 using 25MHz crystal
// Nucleo dev board using 8MHz clock source (STLink MCO)
Expand Down Expand Up @@ -325,6 +326,15 @@ void SystemClock_Config(void)
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
#endif

#if SDCARD_ENABLE
PeriphClkInitStruct.PeriphClockSelection = PeriphClkInitStruct.PeriphClockSelection | RCC_PERIPHCLK_SDMMC;
#ifdef NUCLEO_SLOW_SDMMC_CLOCK
PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL2;
#else
PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL;
#endif //NUCLEO_SLOW_SDMMC_CLOCK
#endif //SDCARD_ENABLE

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
Expand Down
25 changes: 6 additions & 19 deletions Src/stm32h7xx_hal_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,18 @@ void HAL_MspInit(void)
void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(hsd->Instance==SDMMC1)
{
/* USER CODE BEGIN SDMMC1_MspInit 0 */

/* USER CODE END SDMMC1_MspInit 0 */

/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDMMC;
PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL;

#ifdef NUCLEO_SLOW_SDMMC_CLOCK
// Select alternative SDMMC clock source for prototyping on Nucleo with external uSD breakout. A slower
// clock is needed for signal integrity (note that changing the ClockDiv does not have the same effect).
//
// PLL2R clock source is configured @ 12MHz for Nucleo boards.
//
PeriphClkInitStruct.SdmmcClockSelection = RCC_SDMMCCLKSOURCE_PLL2;
#endif

if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock initialisation moved to main().
*
* The NUCLEO_SLOW_SDMMC_CLOCK symbol allows for an alternative SDMMC clock source, useful when
* prototyping on Nucleo dev boards with external uSD breakout. A slower clock may be needed for
* signal integrity (note that changing the ClockDiv does not have the same effect).
*/

/* Peripheral clock enable */
__HAL_RCC_SDMMC1_CLK_ENABLE();
Expand Down

0 comments on commit bb27fe4

Please sign in to comment.