cancel
Showing results for 
Search instead for 
Did you mean: 

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

DDesr.1
Associate II

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

2 REPLIES 2
Imen.D
ST Employee

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

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
DDesr.1
Associate II

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.