Pin configuration

Depending on the logic of the GPIO controller, the pins can be activated all together, separately, or in groups. In order to implement a driver to set up the pins and use them as needed, it is possible to refer to the datasheet of the microcontroller, or any example implementation provided by the silicon vendor.

In the case of the STM32F4, general-purpose I/O pins are divided in groups. Each group is connected to a separate clock gate, so, to use the pins associated to a group, the clock gate must be enabled. The following code will distribute the clock source to the GPIO controller for the group D:

#define AHB1_CLOCK_ER (*(volatile uint32_t *)(0x40023840))#define GPIOD_AHB1_CLOCK_ER (1 << 3)AHB1_CLOCK_ER |= GPIOD_AHB1_CLOCK_ER; ...

Get Embedded Systems Architecture now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.