![ARTERY AT32F421 GPIO User Manual Download Page 14](http://html1.mh-extra.com/html/artery/at32f421-gpio/at32f421-gpio_user-manual_2977597014.webp)
AT32F421 GPIO user guide
2020.07.30
14
Rev.1.0.0
Analog mode
When the user needs to use ADC or COMP channel as input, it is necessary to configure the
corresponding pins as analog mode. Refer to the following configuration example of analog mode.
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_x;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_NOPULL; /*
None, pull-up or pull-down
*/
GPIO_Init(GPIOy, &GPIO_InitStructure);
Alternate function mode
1. Regardless of the peripheral mode used, the I/O must be configured as alternate function so
that the system can use I/O correctly (input or output)
2. The I/O pin is connected to the corresponding peripheral through a multiplexer, which allows
only one peripheral’s alternate function to be connected to the I/O pin at a time in order to
avoid conflicts between peripherals that share the same I/O pin. Each I/O pin has a multiplexer
featuring 16-channel alternate function input/output (AF0 to AF15) configured by the
GPIO_PinAFConfig () function.
— After reset, all I/Os are connected to the system alternate function 0 (AF0).
— Configure AF1 to AF7 to map peripherals’ alternate functions
3. In addition to these flexible I/O alternate function structures, each peripheral can also be
mapped to other different I/O pins. The number of peripheral I/O functions for different
packages can be optimized. For example, USART2_TX can be mapped to PA2 or PA14 pin.
4. Configuration procedure
— Use the GPIO_PinAFConfig() function to connect the pin to the desired peripheral alternate
function, for example, configure PA0 as TMR1_ETR input
GPIO_PinAFConfig(GPIOA, GPIO_PinsSource0, GPIO_AF_4);
— Use the GPIO_Init() function to configure I/O pins:
-
Use the following method to configure the desired pin in alternate function mode
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
-
Use the following pins to select type, pull-up, pull-down and output speed.
GPIO_Pull, GPIO_OutType and GPIO_MaxSpeed.
The subsequent sections provide common configuration examples of several peripherals
according to the above-mentioned procedures.
USART I/O alternate function mode configuration
/* Enable AHB interface clock of GPIOA*/
RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_GPIOA, ENABLE);