Skip to content

Commit bea0b19

Browse files
authored
Merge pull request #5121 from GoldBr1987/master
modify set uart clk bug
2 parents 1fcd2b6 + 65f5225 commit bea0b19

File tree

3 files changed

+1086
-369
lines changed

3 files changed

+1086
-369
lines changed

bsp/hc32f4a0/drivers/drv_usart.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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

293327
static 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+
316367
static 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

321372
static rt_err_t hc32_configure(struct rt_serial_device *serial,

0 commit comments

Comments
 (0)