这应该是重映射时钟吧?如果是那只有在需要重映射的时候才开启。例如:
if(UART1_PinReMap==0) //USART1引脚不重映射
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //使能端口A时钟
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure); //PA10-RXD1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure); //PA9-TXD1为推挽复用输出
}
else if(UART1_PinReMap==1) //USART1引脚重映射到B口
{
RCC->APB2ENR = RCC->APB2ENR | 0x01; //使能复用功能时钟
AFIO->MAPR = AFIO->MAPR | (UART1_PinReMap << 2); //设置USART1的复用使能位
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); //使能端口B时钟
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure); //PB7-RXD1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure); //PB6-TXD1为推挽复用输出
}
|