用的外设功能。这样一来,应用程序可为每个 I/O 选择任何一个可用功能。由于 AF 选择信号由复用功能输入和复用功能输出共用,所以只需为每个 I/O 的复用功能输入/输出选择一个通道即可。
外部中断线/唤醒线
所有端口都具有外部中断功能。要使用外部中断线,必须将端口配置为输入模式。具体参考Example
详细介绍
1. GPIOx_MODER(GPIO 端口模式寄存器)
2. GPIOx_OTYPER(GPIO 端口输出类型寄存器)
3. GPIOx_OSPEEDR(GPIO 端口输出速度寄存器)
4. GPIOx_PUPDR(GPIO 端口上拉/下拉寄存器)
5. GPIOx_IDR(GPIO 端口输入数据寄存器)
6. GPIOx_ODR(GPIO 端口输出数据寄存器)
7. GPIOx_BSRR(GPIO 端口置位/复位寄存器)
8. GPIOx_LCKR(GPIO 端口配置锁定寄存器)
9. GPIOx_AFRL(GPIO 复用功能低位寄存器)
10. GPIOx_AFRH(GPIO 复用功能高位寄存器)
HAL库相关驱动API
HAL_GPIO_ReadPin
C /** * @brief Reads the specified input port pin. * @param GPIOx where x can be (A..K) to select the GPIO peripheral for STM32F429X device or * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. * @param GPIO_Pin specifies the port bit to read. * This parameter can be GPIO_PIN_x where x can be (0..15). * @retval The input port pin value. */ GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) { GPIO_PinState bitstatus;
/* Check the parameters */ assert_param(IS_GPIO_PIN(GPIO_Pin));
C /** * @brief Sets or clears the selected data port bit. * * @note This function uses GPIOx_BSRR register to allow atomic read/modify * accesses. In this way, there is no risk of an IRQ occurring between * the read and the modify access. * * @param GPIOx where x can be (A..K) to select the GPIO peripheral for STM32F429X device or * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. * @param GPIO_Pin specifies the port bit to be written. * This parameter can be one of GPIO_PIN_x where x can be (0..15). * @param PinState specifies the value to be written to the selected bit. * This parameter can be one of the GPIO_PinState enum values: * @arg GPIO_PIN_RESET: to clear the port pin * @arg GPIO_PIN_SET: to set the port pin * @retval None */ void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) { /* Check the parameters */ assert_param(IS_GPIO_PIN(GPIO_Pin)); assert_param(IS_GPIO_PIN_ACTION(PinState));
C /** * @brief Toggles the specified GPIO pins. * @param GPIOx Where x can be (A..K) to select the GPIO peripheral for STM32F429X device or * x can be (A..I) to select the GPIO peripheral for STM32F40XX and STM32F427X devices. * @param GPIO_Pin Specifies the pins to be toggled. * @retval None */ void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin) { uint32_t odr;
/* Check the parameters */ assert_param(IS_GPIO_PIN(GPIO_Pin));
/* get current Output Data Register value */ odr = GPIOx->ODR;
/* Set selected pins that were at low level, and reset ones that were high */ GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin); }