File tree Expand file tree Collapse file tree 3 files changed +1086
-369
lines changed Expand file tree Collapse file tree 3 files changed +1086
-369
lines changed Original file line number Diff line number Diff line change 66 * Change Logs:
77 * Date Author Notes
88 * 2020-10-30 CDT first version
9+ * 2021-10-05 lizhengyang fix set uart clk bug
910 */
1011
1112/*******************************************************************************
@@ -289,6 +290,39 @@ static struct hc32_uart uart_obj[] =
289290 UART_CONFIG ("uart10" , USART10 ),
290291#endif
291292};
293+ static const struct uart_index uart_clock_map [] =
294+ {
295+ #ifdef BSP_USING_UART1
296+ {0 , M4_USART1 },
297+ #endif
298+ #ifdef BSP_USING_UART2
299+ {1 , M4_USART2 },
300+ #endif
301+ #ifdef BSP_USING_UART3
302+ {2 , M4_USART3 },
303+ #endif
304+ #ifdef BSP_USING_UART4
305+ {3 , M4_USART4 },
306+ #endif
307+ #ifdef BSP_USING_UART5
308+ {4 , M4_USART5 },
309+ #endif
310+ #ifdef BSP_USING_UART6
311+ {5 , M4_USART6 },
312+ #endif
313+ #ifdef BSP_USING_UART7
314+ {6 , M4_USART7 },
315+ #endif
316+ #ifdef BSP_USING_UART8
317+ {7 , M4_USART8 },
318+ #endif
319+ #ifdef BSP_USING_UART9
320+ {8 , M4_USART9 },
321+ #endif
322+ #ifdef BSP_USING_UART10
323+ {9 , M4_USART10 },
324+ #endif
325+ };
292326
293327static const struct uart_irq_handler uart_irq_handlers [sizeof (uart_obj ) / sizeof (uart_obj [0 ])];
294328
@@ -313,9 +347,26 @@ static uint32_t hc32_get_uart_index(M4_USART_TypeDef *Instance)
313347 return index ;
314348}
315349
350+ static uint32_t hc32_get_uart_clock_index (M4_USART_TypeDef * Instance )
351+ {
352+ uint32_t index = 10 ;
353+
354+ for (uint8_t i = 0U ; i < ARRAY_SZ (uart_clock_map ); i ++ )
355+ {
356+ if (uart_clock_map [i ].Instance == Instance )
357+ {
358+ index = uart_clock_map [i ].index ;
359+ RT_ASSERT (index < 10 )
360+ break ;
361+ }
362+ }
363+
364+ return index ;
365+ }
366+
316367static uint32_t hc32_get_usart_fcg (M4_USART_TypeDef * Instance )
317368{
318- return (PWC_FCG3_USART1 << hc32_get_uart_index (Instance ));
369+ return (PWC_FCG3_USART1 << hc32_get_uart_clock_index (Instance ));
319370}
320371
321372static rt_err_t hc32_configure (struct rt_serial_device * serial ,
You can’t perform that action at this time.
0 commit comments