@@ -193,8 +193,31 @@ void USART2_IRQHandler(void)
193193}
194194#endif /* RT_USING_UART2 */
195195
196+ #if defined(RT_USING_UART3 )
197+ /* UART3 device driver structure */
198+ static struct drv_uart uart3 ;
199+ struct rt_serial_device serial3 ;
200+ void USART3_IRQHandler (void )
201+ {
202+ struct drv_uart * uart ;
203+ uart = & uart3 ;
204+ /* enter interrupt */
205+ rt_interrupt_enter ();
206+ /* UART in mode Receiver -------------------------------------------------*/
207+ if ((__HAL_UART_GET_FLAG (& uart -> UartHandle , UART_FLAG_RXNE ) != RESET ) &&
208+ (__HAL_UART_GET_IT_SOURCE (& uart -> UartHandle , UART_IT_RXNE ) != RESET ))
209+ {
210+ rt_hw_serial_isr (& serial3 , RT_SERIAL_EVENT_RX_IND );
211+ /* Clear RXNE interrupt flag */
212+ __HAL_UART_CLEAR_FLAG (& uart -> UartHandle , UART_FLAG_RXNE );
213+ }
214+ /* leave interrupt */
215+ rt_interrupt_leave ();
216+ }
217+ #endif /* RT_USING_UART3 */
218+
196219#if defined(RT_USING_UART6 )
197- /* UART2 device driver structure */
220+ /* UART6 device driver structure */
198221static struct drv_uart uart6 ;
199222struct rt_serial_device serial6 ;
200223void USART6_IRQHandler (void )
@@ -214,7 +237,7 @@ void USART6_IRQHandler(void)
214237 /* leave interrupt */
215238 rt_interrupt_leave ();
216239}
217- #endif /* RT_USING_UART3 */
240+ #endif /* RT_USING_UART6 */
218241
219242/**
220243* @brief UART MSP Initialization
@@ -260,6 +283,22 @@ void HAL_UART_MspInit(UART_HandleTypeDef *uartHandle)
260283 GPIO_InitStruct .Alternate = GPIO_AF7_USART2 ;
261284 HAL_GPIO_Init (GPIOA , & GPIO_InitStruct );
262285 }
286+ else if (uartHandle -> Instance == USART3 )
287+ {
288+ /* USART3 clock enable */
289+ __HAL_RCC_USART3_CLK_ENABLE ();
290+ __HAL_RCC_GPIOB_CLK_ENABLE ();
291+ /**USART3 GPIO Configuration
292+ PB10 ------> USART3_TX
293+ PB11 ------> USART3_RX
294+ */
295+ GPIO_InitStruct .Pin = GPIO_PIN_10 | GPIO_PIN_11 ;
296+ GPIO_InitStruct .Mode = GPIO_MODE_AF_PP ;
297+ GPIO_InitStruct .Pull = GPIO_PULLUP ;
298+ GPIO_InitStruct .Speed = GPIO_SPEED_FREQ_VERY_HIGH ;
299+ GPIO_InitStruct .Alternate = GPIO_AF7_USART3 ;
300+ HAL_GPIO_Init (GPIOB , & GPIO_InitStruct );
301+ }
263302 else if (uartHandle -> Instance == USART6 )
264303 {
265304 /* USART6 clock enable */
@@ -300,6 +339,16 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef *uartHandle)
300339 */
301340 HAL_GPIO_DeInit (GPIOA , GPIO_PIN_2 | GPIO_PIN_3 );
302341 }
342+ else if (uartHandle -> Instance == USART3 )
343+ {
344+ /* Peripheral clock disable */
345+ __HAL_RCC_USART3_CLK_DISABLE ();
346+ /**USART3 GPIO Configuration
347+ PB10 ------> USART3_TX
348+ PB11 ------> USART3_RX
349+ */
350+ HAL_GPIO_DeInit (GPIOB , GPIO_PIN_10 | GPIO_PIN_11 );
351+ }
303352 else if (uartHandle -> Instance == USART6 )
304353 {
305354 /* Peripheral clock disable */
@@ -338,6 +387,17 @@ int hw_usart_init(void)
338387 RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
339388 uart );
340389#endif /* RT_USING_UART2 */
390+ #ifdef RT_USING_UART3
391+ uart = & uart3 ;
392+ uart -> UartHandle .Instance = USART3 ;
393+ uart -> irq = USART3_IRQn ;
394+ serial3 .ops = & drv_uart_ops ;
395+ serial3 .config = config ;
396+ /* register UART3 device */
397+ rt_hw_serial_register (& serial3 , "uart3" ,
398+ RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
399+ uart );
400+ #endif /* RT_USING_UART3 */
341401#ifdef RT_USING_UART6
342402 uart = & uart6 ;
343403 uart -> UartHandle .Instance = USART6 ;
@@ -348,7 +408,7 @@ int hw_usart_init(void)
348408 rt_hw_serial_register (& serial6 , "uart6" ,
349409 RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
350410 uart );
351- #endif /* RT_USING_UART2 */
411+ #endif /* RT_USING_UART6 */
352412 return 0 ;
353413}
354414INIT_BOARD_EXPORT (hw_usart_init );
0 commit comments