STM32WL3X HAL Does not properly calculate BRR values when using HSE clock source
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.
