I have an STM32L4 project configured to use LL drivers in CubeMX. I am using
- An stm32L4 series MCU
- Desired baud rate 115200
The LL library function
does not correctly set the LL_USART_InitTypeDef USART_InitStruct
USART_InitStruct.BaudRate parameter for USART1.
In the source stm32l4xx_ll_usart.c this appears to be due to line 288
ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct)
periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE);
returning 40 MHz instead of 80 MHz (as set in CubeMX), causing the `USART->BRR` register to be set to half the value it should be as described in reference manual RM0394. The effective baud rate is then twice that requested by the USART_InitStruct.
The line causing the problem appears to be 352 in stm32l4xx_ll_rcc.c
uint32_t LL_RCC_GetUSARTClockFreq(uint32_t USARTxSource)
usart_frequency = RCC_GetPCLK2ClockFreq(RCC_GetHCLKClockFreq(RCC_GetSystemClockFreq()));
Given that this occurs in the LL drivers I must assume this is an LL driver bug and not a CubeMX one. Note that the LL driver is reporting the peripheral clock to be half the value needed for communication to work correctly. When configured with HAL, the baud rate is set correctly.
Since this appears to be the only place to report such bugs, I am posting this here. Please reply if more information is required.
EDIT: Incorrect line number quoted in stm32l4xx_ll_rcc.c updated.