Skip to main content
DDesr.1
Associate II
February 5, 2020
Question

UART baud rate is double when configuring PLLs using LL drivers on STM32G4xxx

  • February 5, 2020
  • 2 replies
  • 1061 views

The function LL_PLL_ConfigSystemClock_HSI() in stm32g4xx_ll_utils.c temporarily divides the AHB clock by 2 if the SYSCLK divider is 1. According to the comments, this is to "Prevent undershoot at highest frequency by applying intermediate AHB prescaler 2".

The issue is that during this temporary AHB clock rate, the SystemCoreClock is updated to also be 1/2 the expected clock.

Although LL_PLL_ConfigSystemClock_HSI() resets the AHB clock properly, it does not reset the global variable SystemCoreClock.

This incorrect value is exposed when trying to set the UART baud rate later on in stm32g4xx_hal_uart.c.

Note that I'm using the latest from https://github.com/STMicroelectronics/STM32CubeG4 (0f8a4fd) with this recent pull-request integrated.

The following patch fixes the issue. Is this the correct solution? If so, I'm happy to issue a PR.. but do not know where to do it as there is conflicting info across the web.

diff --git a/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c b/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c
index ea78949a..49bdac0c 100644
--- a/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c
+++ b/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_utils.c
@@ -329,6 +329,7 @@ ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitS
 {
 UTILS_ClkInitStruct->AHBCLKDivider = LL_RCC_SYSCLK_DIV_1;
 LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider);
+ LL_SetSystemCoreClock(pllfreq);
 }
 }
 else

This topic has been closed for replies.

2 replies

ST Technical Moderator
February 6, 2020

Hello,

>> with this recent pull-request integrated.

This pull-request link is not available. However, we have not integrated any pull requests.

Please, create a new issue at the GitHub site.

Best Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
DDesr.1
DDesr.1Author
Associate II
February 6, 2020

ah! try this one: https://github.com/STMicroelectronics/STM32CubeG4/pull/3.

Ok, I will issue a PR to https://github.com/STMicroelectronics/STM32CubeG4 and continue the conversation there.