Question
Ensure that Frequency clock is in the range [3 * baudrate, 4096 * baudrate]
Dear MCD Application Team,
in Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c you can find this check:
/* Ensure that Frequency clock is in the range [3 * baudrate, 4096 * baudrate] */
if ((lpuart_ker_ck_pres < (3U * huart->Init.BaudRate)) ||
(lpuart_ker_ck_pres > (4096U * huart->Init.BaudRate)))
{
ret = HAL_ERROR;
}assume huart->Init.BaudRate is 28333333 and lpuart_ker_ck_pres=170000000 the result is larger than uint32_t and results in a HAL_ERROR
You can check this with this small test application. Maybe you can fix this in the next release.
#include <stdio.h>
#include <stdint.h>
int main() {
uint32_t BaudRate = 28333334;
uint32_t lpuart_ker_ck_pres = 170000000;
printf("Start;\n");
if (lpuart_ker_ck_pres < (3U * BaudRate))
{
printf("Error(1);\n");
}
if (lpuart_ker_ck_pres > (4096U * BaudRate))
{
printf("Error(2);\n");
}
printf("End;\n");
}
