2021-02-10 04:44 AM
I'm using STM32F446, I found one issue.
==============================================================================
##### 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).
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);
2021-02-10 05:43 AM
> is the comment in STM32F4xx_hal_uart.c wrong?
Yes.
There's no "alternate function input"
Except in the old 'F1 family, if you set a pin to AF in GPIO_MODER (and assign some AF in respective GPIO_AFR), the module to which this pin is assigned controls the direction of that pin. UARTs set Rx pin to Input, Tx to Output, as soon as you enable the receiver/transmitter/UART in UART_CR1.
JW
2021-02-12 02:24 AM
Hello @HXiao.1 and welcome to the STM32 Community,
I escalated the wrong comment to the development team for correction in the coming releases.
Thanks for your contribution.
Imen