Check at STM32Cube HAL that the required part is enabled (Like using GPIO to control LEDs, you need to enable GPIO)
UART in STM32
e.g.