@@ -114,9 +114,10 @@ void uart_deinit(void) {
114114STATIC bool uart_init2 (pyb_uart_obj_t * uart_obj ) {
115115 USART_TypeDef * UARTx ;
116116 IRQn_Type irqn ;
117- uint32_t GPIO_Pin ;
117+ uint32_t GPIO_Pin , GPIO_Pin2 ;
118118 uint8_t GPIO_AF_UARTx = 0 ;
119119 GPIO_TypeDef * GPIO_Port = NULL ;
120+ GPIO_TypeDef * GPIO_Port2 = NULL ;
120121
121122 switch (uart_obj -> uart_id ) {
122123 #if defined(MICROPY_HW_UART1_PORT ) && defined(MICROPY_HW_UART1_PINS )
@@ -197,18 +198,10 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
197198 irqn = UART5_IRQn ;
198199 GPIO_AF_UARTx = GPIO_AF8_UART5 ;
199200 GPIO_Port = MICROPY_HW_UART5_TX_PORT ;
201+ GPIO_Port2 = MICROPY_HW_UART5_RX_PORT ;
200202 GPIO_Pin = MICROPY_HW_UART5_TX_PIN ;
203+ GPIO_Pin2 = MICROPY_HW_UART5_RX_PIN ;
201204 __UART5_CLK_ENABLE ();
202-
203- // The code after the case only deals with the case where the TX & RX
204- // pins are on the same port. UART5 has them on different ports.
205- GPIO_InitTypeDef GPIO_InitStructure ;
206- GPIO_InitStructure .Pin = MICROPY_HW_UART5_RX_PIN ;
207- GPIO_InitStructure .Speed = GPIO_SPEED_HIGH ;
208- GPIO_InitStructure .Mode = GPIO_MODE_AF_PP ;
209- GPIO_InitStructure .Pull = GPIO_PULLUP ;
210- GPIO_InitStructure .Alternate = GPIO_AF_UARTx ;
211- HAL_GPIO_Init (MICROPY_HW_UART5_RX_PORT , & GPIO_InitStructure );
212205 break ;
213206 #endif
214207
@@ -242,6 +235,13 @@ STATIC bool uart_init2(pyb_uart_obj_t *uart_obj) {
242235 GPIO_InitStructure .Alternate = GPIO_AF_UARTx ;
243236 HAL_GPIO_Init (GPIO_Port , & GPIO_InitStructure );
244237
238+ // init GPIO for second pin if needed
239+ if (GPIO_Port2 != NULL ) {
240+ mp_hal_gpio_clock_enable (GPIO_Port2 );
241+ GPIO_InitStructure .Pin = GPIO_Pin2 ;
242+ HAL_GPIO_Init (GPIO_Port2 , & GPIO_InitStructure );
243+ }
244+
245245 // init UARTx
246246 HAL_UART_Init (& uart_obj -> uart );
247247
0 commit comments