77 * Date Author Notes
88 * 2021-08-05 mazhiyuan first version
99 */
10+ #include "board.h"
1011#include <mm32_device.h>
1112#include <rtdevice.h>
1213#include "drv_uart.h"
@@ -177,84 +178,13 @@ void UART3_IRQHandler(void)
177178}
178179#endif /* BSP_USING_UART3 */
179180
180- #ifdef BSP_USING_UART1
181- static void UART1PINconfigStepA (void )
182- {
183- /* Enable UART clock */
184- RCC_APB2PeriphClockCmd (RCC_APB2Periph_UART1 , ENABLE );
185- RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOA , ENABLE );
186- }
187-
188- static void UART1PINconfigStepB (void )
189- {
190- GPIO_InitTypeDef GPIO_InitStructure ;
191- /* Configure USART Rx/tx PIN */
192- GPIO_InitStructure .GPIO_Pin = GPIO_Pin_9 ;
193- GPIO_InitStructure .GPIO_Speed = GPIO_Speed_High ;
194- GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP ;
195- GPIO_Init (GPIOA , & GPIO_InitStructure );
196- GPIO_InitStructure .GPIO_Pin = GPIO_Pin_10 ;
197- GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IPU ;
198- GPIO_Init (GPIOA , & GPIO_InitStructure );
199- GPIO_PinAFConfig (GPIOA , GPIO_PinSource9 , GPIO_AF_7 );
200- GPIO_PinAFConfig (GPIOA , GPIO_PinSource10 , GPIO_AF_7 );
201- }
202- #endif
203-
204- #ifdef BSP_USING_UART2
205- static void UART2PINconfigStepA (void )
206- {
207- /* Enable UART clock */
208- RCC_APB1PeriphClockCmd (RCC_APB1Periph_UART2 , ENABLE );
209- RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOA , ENABLE );
210- }
211-
212- static void UART2PINconfigStepB (void )
213- {
214- GPIO_InitTypeDef GPIO_InitStructure ;
215- /* Configure USART Rx/tx PIN */
216- GPIO_InitStructure .GPIO_Pin = GPIO_Pin_2 ;
217- GPIO_InitStructure .GPIO_Speed = GPIO_Speed_High ;
218- GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP ;
219- GPIO_Init (GPIOA , & GPIO_InitStructure );
220- GPIO_InitStructure .GPIO_Pin = GPIO_Pin_3 ;
221- GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IPU ;
222- GPIO_Init (GPIOA , & GPIO_InitStructure );
223- GPIO_PinAFConfig (GPIOA , GPIO_PinSource2 , GPIO_AF_7 );
224- GPIO_PinAFConfig (GPIOA , GPIO_PinSource3 , GPIO_AF_7 );
225- }
226- #endif
227-
228- #ifdef BSP_USING_UART3
229- static void UART3PINconfigStepA (void )
230- {
231- /* Enable UART clock */
232- RCC_APB1PeriphClockCmd (RCC_APB1Periph_UART3 , ENABLE );
233- RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOC , ENABLE );
234- }
235-
236- static void UART3PINconfigStepB (void )
237- {
238- GPIO_InitTypeDef GPIO_InitStructure ;
239- /* Configure USART Rx/tx PIN */
240- GPIO_InitStructure .GPIO_Pin = GPIO_Pin_10 ;
241- GPIO_InitStructure .GPIO_Speed = GPIO_Speed_High ;
242- GPIO_InitStructure .GPIO_Mode = GPIO_Mode_AF_PP ;
243- GPIO_Init (GPIOC , & GPIO_InitStructure );
244- GPIO_InitStructure .GPIO_Pin = GPIO_Pin_11 ;
245- GPIO_InitStructure .GPIO_Mode = GPIO_Mode_IPU ;
246- GPIO_Init (GPIOC , & GPIO_InitStructure );
247- GPIO_PinAFConfig (GPIOC , GPIO_PinSource10 , GPIO_AF_7 );
248- GPIO_PinAFConfig (GPIOC , GPIO_PinSource11 , GPIO_AF_7 );
249- }
250- #endif
251-
252181int rt_hw_uart_init (void )
253182{
254183 struct mm32_uart * uart ;
255184 struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT ;
256185#ifdef BSP_USING_UART1
257- UART1PINconfigStepA ();
186+ mm32_msp_uart_init ((void * )UART1 );
187+
258188 uart = & uart1 ;
259189 uart -> uart = UART1 ;
260190 uart -> irq = UART1_IRQn ;
@@ -265,11 +195,11 @@ int rt_hw_uart_init(void)
265195 rt_hw_serial_register (& serial1 , "uart1" ,
266196 RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
267197 uart );
268- UART1PINconfigStepB ();
269198#endif /* BSP_USING_UART1 */
270199
271200#ifdef BSP_USING_UART2
272- UART2PINconfigStepA ();
201+ mm32_msp_uart_init ((void * )UART2 );
202+
273203 uart = & uart2 ;
274204 uart -> uart = UART2 ;
275205 uart -> irq = UART2_IRQn ;
@@ -280,11 +210,11 @@ int rt_hw_uart_init(void)
280210 rt_hw_serial_register (& serial2 , "uart2" ,
281211 RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
282212 uart );
283- UART2PINconfigStepB ();
284213#endif /* BSP_USING_UART2 */
285214
286215#ifdef BSP_USING_UART3
287- UART3PINconfigStepA ();
216+ mm32_msp_uart_init ((void * )UART3 );
217+
288218 uart = & uart3 ;
289219 uart -> uart = UART3 ;
290220 uart -> irq = UART3_IRQn ;
@@ -295,7 +225,6 @@ int rt_hw_uart_init(void)
295225 rt_hw_serial_register (& serial3 , "uart3" ,
296226 RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX ,
297227 uart );
298- UART3PINconfigStepB ();
299228#endif /* BSP_USING_UART3 */
300229
301230 return 0 ;
0 commit comments