STM32

Time:2021-4-10

GPIOx_CRL(x=A~E)

Address offset: the initial address of the port configuration plus the offset address is the address of the special register

GPIO general I / O 8 working modes




1. Floating input mode:

(1) When gpiox_ CRL or gpiox_ When the CNF [1:0] bit of CRH register is set to 01 and the mode [1:0] bit is set to 00

(2) Default mode after STM32 reset

2. Input pull-up mode

(1) Enable pull-up switch in input circuit based on floating input mode

(2) Output data register (gpiox_ The corresponding bit of ODR pin is set to 1 to enable the pull-up function

3. Input the drop-down mode

4. Analog input mode

5. Open drain universal output mode

The output of GPIO is driven by an inverter composed of a PMOS and an NMOS. The drain in open drain circuit refers to the drain stage of MOS

(1) Control I / O pin open drain output high level:

Method 1: gpiox_ The corresponding position of bsrr is 1

Method 2: set gpiox directly_ The corresponding bit of ODR is 1

Effect: when the MOS control line outputs low level, the NMOS transistor is cut off (PMOS is not activated), the pin is in high resistance state, and there is no current flow.

(2) Control I / O pin open drain output low level:

Method 1: gpiox_ Bsrr or gpiox_ BRR pin is set to 1

Method 2: set gpiox directly_ The corresponding bit of PDR is 0

Effect: the NMOS on (PMOS not activated) pin is in a low level state, allowing current to flow in from the pin.

6. Push pull general output mode:




(1) Control I / O open drain output high level:

Method 1. Gpox_ The corresponding position of bsrr is 1

Method 2: set gpiox directly_ The corresponding bit of ODR is 1


Effect: PMOS control line outputs low level. At this time, PMOS is on. At the same time, NMOS outputs low level. At this time, NMOS is cut off. Finally, I / O pin is in high level state. If a loop is formed, current can flow out from the pin


(2) Control I / O pin open drain output low level:

Method 1: gpiox_ Bsrr or gpiox_ BRR pin is set to 1

Method 2: set gpiox directly_ The corresponding bit of ODR is 0


Effect: the PMOS control line outputs high level. At this time, the PMOS is cut off. At the same time, the NMOS controller outputs high level. At this time, the NMOS is on, and the final I / O pin is at low level. If a loop is formed, current can flow from the pin

7. Push pull multiplexing function output mode:

An I / O pin can be used as an ordinary IO interface, and can also be used as a special function pin of other peripherals. Some pins may have four or five functions that cannot be used. The pin reuse is a special function pin, and the pin status is determined by the peripheral.

8. Output mode of open drain multiplexing function:


Each function module of STM32 MCU has its own clock system, so if you want to call the function module of STM32 MCU, you must first configure the corresponding clock, and then operate the corresponding function module. Port remapping is the same

STM32 can use three different system clocks sysclk: HSE external crystal / ceramic resonator, HSI external crystal / ceramic resonator, PLL clock