cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL3X HAL Does not properly calculate BRR values when using HSE clock source

divmstr
Associate III

I am using the LPUART in a very high speed mode, almost the max at 5Mb/s. I set the clock source to the LPUART to HSE/3, or 16MHz, and specified 5000000 in the Baud Rate field of the initialization. HAL_UART_INIT returns with no error (HAL_OK), but successive attempts to receive data end up in framing errors, indicative of a baud rate mismatch. 

To test it I lowered the baud rate to 115200, and tried that with the same result. Table 92 on page 713 lists the BRR value for this to be 0x8AE3, however, setting a breakpoint at line 3236 of stm32wl3x_hal_uart.c, where the BRR is initialized with the calculated value, it was a far lower value, hence the noted behaviour.

The problem is in the value returned by HAL_RCCEx_GetPeriphClkFreq, which returns 24MHz (HSE/2) instead of the correct value of 16MHz. The problem appears to be in the switch statement between lines 260 and 275 of stm32wl3x_hal_rcc_ex.c. It returns the proper LSE value if properly configured, but always HSE/2 otherwise. It should be returning either HSE/3 or HSE/4, depending on the CLKROOTDIV value, which it is not taking into consideration.

 

2 REPLIES 2
divmstr
Associate III

That should have been Table 92 on Page 713 of RM0511, Revision 4.

STTwo-32
ST Employee

Hello @divmstr 

Thank you so much for reporting this behavior. This was also escalated in the community and internally and it will be fixed on the Future releases. More details available on this post.

Best Regards.

STTwo-32

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.