目录
端口复用配置过程
GPIO端口时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
复用外设时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
端口模式配置 GPIO_Init()函数
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
查表《STM32中文参考手册》表格
USART 串口引脚GPIO 配置
USARTx_TX 全双工模式 推挽复用输出
半双工同步模式 推挽复用输出
USARTx_RX 全双工模式 浮空输入或带上拉输入
半双工同步模式 未用,可作为通用I/O
USARTx_CK 同步模式 推挽复用输出
USARTx_RTS 硬件流量控制 推挽复用输出
USARTx_CTS 硬件流量控制 浮空输入或带上拉输入
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //
GPIO_Init(GPIOA, &GPIO_InitStructure); //
端口重映射
void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState)