1查看datasheet,直接搜索USART3,就可以知道其映射关系了。
2代码
#define ISP_UART_PORT USART3
#define ISP_UART_IRQ USART3_IRQn
#define ISP_UART_RCC RCC_APB1Periph_USART3
#define ISP_UART_IRQHANDLER USART3_IRQHandler
#define ISP_UART_REMAP GPIO_FullRemap_USART3
#define ISP_RX_PORT GPIOD
#define ISP_RX_PIN GPIO_Pin_9
#define ISP_TX_PORT GPIOD
#define ISP_TX_PIN GPIO_Pin_8
static void isp_uart_init(uint32_t baudrate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB1PeriphClockCmd(ISP_UART_RCC, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = ISP_RX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(ISP_RX_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = ISP_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(ISP_TX_PORT, &GPIO_InitStructure);
GPIO_PinRemapConfig(ISP_UART_REMAP, ENABLE);
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(ISP_UART_PORT, &USART_InitStructure); // 此处使能了CR1的TE和 RE
USART_ITConfig(ISP_UART_PORT, USART_IT_RXNE, ENABLE);
USART_Cmd(ISP_UART_PORT, ENABLE);
NVIC_SetPriority(ISP_UART_IRQ, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 6, 0));
NVIC_EnableIRQ(ISP_UART_IRQ);
}