@@ -27,10 +27,51 @@ void hal_uart_setbaud(hal_sfr_t uartx, uint32_t baud)
2727 uint32_t baud_cfg ;
2828
2929 uartx [UARTxCON ] |= UART_CLK_SRC1 ;
30- baud_cfg = (26000000 /2 )/baud ; //1.5M
30+ baud_cfg = (26000000 /2 )/baud ;
3131 uartx [UARTxBAUD ] = (baud_cfg << 16 ) | baud_cfg ;
3232}
3333
34+ /**
35+ * @brief Set the UART misc paramter.
36+ *
37+ * @param uartx This parameter can be UARTxN where x can be (0.2).
38+ * @param param uart config paramter pointer.
39+ */
40+ void hal_uart_setparam (hal_sfr_t uartx , struct uart_init * param )
41+ {
42+ switch (param -> word_len )
43+ {
44+ case UART_WORDLENGTH_8B :
45+ uartx [UARTxCON ] &= ~UART_BIT9_ENABLE ;
46+ break ;
47+ case UART_WORDLENGTH_9B :
48+ uartx [UARTxCON ] |= UART_BIT9_ENABLE ;
49+ break ;
50+ default :
51+ break ;
52+ }
53+
54+ switch (param -> stop_bits )
55+ {
56+ case UART_STOPBITS_1 :
57+ uartx [UARTxCON ] &= ~UART_SB2_ENABLE ;
58+ break ;
59+ case UART_STOPBITS_2 :
60+ uartx [UARTxCON ] |= UART_SB2_ENABLE ;
61+ break ;
62+ default :
63+ break ;
64+ }
65+
66+ if (param -> mode & UART_MODE_1LINE )
67+ {
68+ uartx [UARTxCON ] |= UART_1LINE_ENABLE ;
69+ }
70+ else
71+ {
72+ uartx [UARTxCON ] &= ~UART_1LINE_ENABLE ;
73+ }
74+ }
3475/**
3576 * @brief Initialize the UART mode.
3677 *
@@ -157,11 +198,15 @@ void uart_config_all(struct uart_handle *huart)
157198 hal_rcu_periph_clk_enable (RCU_UART0 );
158199 } else if (huart -> instance == UART1_BASE ) {
159200 hal_rcu_periph_clk_enable (RCU_UART1 );
201+ } else if (huart -> instance == UART2_BASE ) {
202+ hal_rcu_periph_clk_enable (RCU_UART2 );
160203 } else {
161204 return ; /* Not support! */
162205 }
163206
207+ hal_uart_deinit (huart -> instance );
164208 hal_uart_setbaud (huart -> instance , huart -> init .baud );
209+ hal_uart_setparam (huart -> instance , & huart -> init );
165210
166211 if (huart -> init .mode != UART_MODE_TX ) {
167212 hal_uart_control (huart -> instance , UART_RX_ENABLE , HAL_ENABLE );
0 commit comments