Resolved! Bug in uart init function when setting baudrate register (BRR). In file /Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c at line 3201, it calculates usartdiv casting it to uint16_t and then checks if it is less than 0xffff.
In this way, error never occurs leading to wrong baudrates. if (pclk != 0U) { /* USARTDIV must be greater than or equal to 0d16 */ usartdiv = (uint16_t)(UART_DIV_SAMPLING16(pclk, huart->Init.BaudRate, huart->Init.ClockPrescaler)); ...