GPIO口复用配置和直接作为IO口配置类似
以串口1 USART1为例
先配置GPIO口时钟,
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
再配置内置外设时钟,
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
之后配置GPIO口工作模式
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//复用推挽模式
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//浮空输入模式
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_Init(GPIOA,&GPIO_InitStructure);