作者:无风
转自:http://blog.youkuaiyun.com/zhenghangming/article/details/7554578
REMAP用途:
1 在RCC设置中开启RCC_APB2Periph_AFIO
2 在GPIO中开启 remap的目标端口
3 GPIO_PinRemapConfig(GPIO_XX,ENABLE);
举例:
void GPIO_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB |RCC_APB2Periph_AFIO , ENABLE); //记得必须开启RCC_APB2Periph_AFIO时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_USART2 , ENABLE); //对USART2进行引脚映射,映射到PD得5,6脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //USART2 TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure); //A端口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //USART2 RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用开漏输入
GPIO_Init(GPIOD, &GPIO_InitStructure); //A端口
}
STM32F2系列不用REMAP,而用GPIO_PinAFConfig()来实现管脚功能配置