2024-11-15 06:08 AM
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");
}
2024-11-15 06:19 AM
Keep in mind the Cube is only meant as a start and will not cover all cases.
2024-11-15 06:22 AM
However instead of
lpuart_ker_ck_pres > (4096U * huart->Init.BaudRate
( lpuart_ker_ck_pres / 4096) > huart->Init.Baudrate
should avoid the overflow
2024-11-15 06:32 AM
@Uwe Bonnes wrote:Cube ... will not cover all cases.
and this certainly doesn't look like an everyday case:
uint32_t BaudRate = 28333334;
That's over 28 Mega Baud!!
That's even faster than this:
2024-11-15 06:53 AM
There was some discussion lately about how to achieve baudrates that high and using the LPUART was one hint.
2024-11-15 07:10 AM
Yes, that was the thread I linked!
2024-11-15 07:47 AM
this is my preferred solution. Maybe this find a way into the next release
if (lpuart_ker_ck_pres > (4096U * (uint64_t)BaudRate))
2024-11-15 07:49 AM
Yes this is fast. It is a performance test for this Isolator SI8622ED-B-ISR in loop back mode