This page is the summary of me reading the reference manual, If there are missing info or incorrect info, please contact me at [email protected]
GPIO Main Features
- Set as output (we’ll use push-pull, basically just means it’ll drive a 1 and 0 constantly)
- GPIOx_ODR will reflect the status of the output, we can read and write this easily to check the status of whichever pin
- To set/reset, we can just use ODR, but it’s much faster to just go through BSRR. More info on that below
- Set as input to have floating, pull up/down or analog input. We can set this
- Data is captured every clock cycle
- Set as Alternate Function (for example, GPIOA5 could be a UART pin (it’s NOT, just example))
- GPIO will use AHB clock, which is equal to SYSCLK (in the SYSCLK ticket we set the prescaler to 1)
- We have GPIO ports A→K
Alternate Function
- Each IO port has a multiplexer with 16 different AF inputs. We can configure this via GPIO_AFRL (pin 0-7) and GPIO_AFRH (pin 8-15)
- Set the Pins to AF mode via GPIO_MODER
- Then configure the pin as normal
- For more information, there’s a whole process on how to set pins to AF’s on the datasheet
Input / Output
Below are the registers used to configure GPIO
- GPIOx_MODER - Select the mode we want to use
- GPIOx_OTYPER - output type if we choose output
- GPIOx_OSPEEDR - choose output speed
- GPIOx_PUPDR - choose pull up or pull down for “default” starting state
- Pin will be left floating if not used
- PD - 10, pin will be LOW when idle
- PU - 01, pin will be HIGH when idle
- This is pretty important for input pins as they can definitely be idle
- For output, since we’re doing push-pull, it will never be idle