cancel
Showing results for 
Search instead for 
Did you mean: 

Ensure that Frequency clock is in the range [3 * baudrate, 4096 * baudrate]

kernelport
Visitor

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");
}

 

7 REPLIES 7
Uwe Bonnes
Principal III

Keep in mind the Cube is only meant as a start and will not cover  all cases.

However instead of

lpuart_ker_ck_pres > (4096U * huart->Init.BaudRate

( lpuart_ker_ck_pres / 4096) > huart->Init.Baudrate
 should avoid the overflow


@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:

https://community.st.com/t5/stm32-mcus-products/stm32-uart-at-20-mbps/m-p/740727/highlight/true#M265668

 

There was some discussion lately about how to achieve baudrates that high and using the LPUART was one hint.

Yes, that was the thread I linked!

 

this is my preferred solution. Maybe this find a way into the next release 

if (lpuart_ker_ck_pres > (4096U * (uint64_t)BaudRate))

Yes this is fast. It is a performance test for this Isolator  SI8622ED-B-ISR in loop back mode