Tuesday, August 9, 2016

Stm32 Peripheral Drivers from Scartch : GPIO register overview

Stm32 Peripheral Drivers from Scartch : GPIO register overview

GPIO register overview

This is a brief overview of the GPIO registers. The video below will cover everything I am going to explain here with the slight difference that this text is more thought out and the video is impromptu. Nonetheless we're off to the races.

The STM32F1 series offers several GPIO ports starting from  GPIOA...through...GPIOG each port consists of 16 Pins indexed from 0-15. Depending on the specific F1 chip you have you may not have all 7 ports, for example my chip is a 48 pin package like the image below and as you can observe I do not have all Ports A through G. Make sure you google a Pinout of your specific chip for reference and save the image to keep handy. If you are using the same board I showed you off of ebay this is your pinout. 

GPIO Registers:



Name: GPIO Control Register LOW and GPIO Control Register HIGH 

Function: Used to configure the GPIO pins to input / output , speed and pull up/down internal resistors.


How to use it: The GPIO ControlRegister LOW and Control Register HIGH are the registers used to to configure the specific pin you are using.  They are identical in function so I have only included the picture of the LOW register above. As you can see above bits 0 and 1 are labeled MODE 0 , bits 2 and 3 are labeled CNF 0 . This pattern repeats through the entire register. The 0 in the label denotes the Pin it will configure, so MODE0 will configure the mode for pin 0 and CNF0 will also configure Pin0. This means that for every pin  there are 4 configuration bits:  2 for MODE and 2 for CNF , since each pin requires 4 bits this means this 32 bit register can only configure 8 pins before running out of space, this is why we have the other register the Control Register  HIGH. The difference is the LOW register will configure pins 0 - 7 and the HIGH register will configure pins 8- 15 . I hope this makes sense and if not feel free to ask questions via comments.


Name: GPIO Input Data Register 

Function: Used to read inputs on the pin.

This register is straight forward. When you set  your pin as input it is because a sensor or some other circuitry is inputting some sort of signal on your pin. This register is used to read the input. The bit and pin mapping is also straight forward. Bit 0 is equivalent to pin 0 and so on. 

Post a Comment

Whatsapp Button works on Mobile Device only

Start typing and press Enter to search