How to config UART in STM32F446?
I'm using STM32F446, I found one issue.
- In STM32F4xx_hal_uart.c, it stated that.
==============================================================================
##### How to use this driver #####
==============================================================================
[..]
The UART HAL driver can be used as follows, pay attention to the last line about UART pins, it's stated that RX as alternate function input.
(#) Declare a UART_HandleTypeDef handle structure (eg. UART_HandleTypeDef huart).
(#) Initialize the UART low level resources by implementing the HAL_UART_MspInit() API:
(##) Enable the USARTx interface clock.
(##) UART pins configuration:
(+++) Enable the clock for the UART GPIOs.
(+++) Configure these UART pins (TX as alternate function pull-up, RX as alternate function Input).
- When I generate code by CubeMX, the generated code in function HAL_UART_MspInit, GPIO_PIN_3 is RX, and GPIO_PIN_2 is TX, but both of them are configured the same. It's different from the description in STM32F4xx_hal_uart.c. I tested, and found that the CubeMX generated code works. If I configure GPIO_PIN_3 as GPIO_MODE_INPUT, UART does not work, is the comment in STM32F4xx_hal_uart.c wrong?
GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
