初始化
void UART_Print_Init(uint32_t bound)
{
GPIO_InitType GPIO_InitStructure;
USART_InitType USART_InitStructure;
/*Enable the UART Clock*/
#if defined (AT32F421xx)
RCC_AHBPeriphClockCmd(AT32_PRINT_UARTTX_GPIO_RCC | AT32_PRINT_UARTRX_GPIO_RCC, ENABLE);
#else
RCC_APB2PeriphClockCmd(AT32_PRINT_UARTTX_GPIO_RCC | AT32_PRINT_UARTRX_GPIO_RCC, ENABLE);
#endif
AT32_PRINT_UART_RCC_CLK_FUNC;
/* Configure the UART1 TX pin */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pins = AT32_PRINT_UARTTX_PIN;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
#if !defined (AT32F421xx)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
#else
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OutType = GPIO_OutType_PP;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_NOPULL;
#endif
GPIO_Init(AT32_PRINT_UARTTX_GPIO, &GPIO_InitStructure);
/* Configure the UART1 RX pin */
GPIO_InitStructure.GPIO_Pins = AT32_PRINT_UARTRX_PIN;//PA10
#if !defined (AT32F421xx)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_PD;
#else
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_NOPULL;
#endif
GPIO_Init(AT32_PRINT_UARTRX_GPIO, &GPIO_InitStructure);
#if defined (AT32F421xx)
GPIO_PinAFConfig(GPIOA, GPIO_PinsSource9, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinsSource10, GPIO_AF_1);
#endif
/*Configure UART param*/
USART_StructInit(&USART_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(AT32_PRINT_UART, &USART_InitStructure);
USART_INTConfig(AT32_PRINT_UART, USART_INT_RDNE, ENABLE);
USART_Cmd(AT32_PRINT_UART, ENABLE);
}
|