This application note explains how to control GPIO in FreeRTOS.
The FreeRTOS demo application illustrates the corresponding APIs through controlling of the LEDs and Push-Buttons available on the carrier board.
1. Understanding FreeRTOS GPIO Interfaces
1.1. FreeRTOS GPIO Implementation
The FreeRTOS BSP makes use of the STM32CubeH7 software component to provide a device driver for the STM32H7 GPIO. The driver is configured (enabled / disabled) at the BSP build time, using the HAL_GPIO_MODULE_ENABLED
configuration option, defined in the stm32h7xx_hal_conf.h
file.
1.2. FreeRTOS GPIO C-Binding API
The GPIO driver implements the following C-binding API:
Function | Description | Comments |
| Initialise GPIO pins in a specified GPIO port |
|
| Reset a GPIO pin to default settings |
|
| Read state of a GPIO pin |
|
| Set or clear a GPIO pin |
|
| Toggle specified GPIO pins |
The GPIO_InitTypeDef
data structure used in the HAL_GPIO_Init
interface has the following definition:
typedef struct { uint32_t Pin; /* GPIO pins to be configured */ uint32_t Mode; /* Operating mode for the selected pins */ uint32_t Pull; /* Pull-up or Pull-Down activation for the selected pins */ uint32_t Speed; /* Speed for the selected pins */ uint32_t Alternate;/* Peripheral to be connected to the selected pin */ } GPIO_InitTypeDef;
1.3. FreeRTOS LED and Push-Button Tasks
The FreeRTOS demos application provides two threads illustrating use of the GPIO API from a FreeRTOS application. Specifically:
The LED Thread implements a blink pattern on the LED residing on the STM32H750 system-on-module (blink LED at 0.5Hz rate).
The Push-Buttons Thread waits for one of the two user push-buttons residing on the STM32H7-BSB carrier board (BTN1 and BTN2) to change its state. As soon as a push-button has been pressed, the thread lilts the corresponding LED residing on the STM32H7-BSB carrier board (LED1 and LED2, respectively). As soon as a push-button has been released, the thread unlits the corresponding LED. Implementation of this thread is interrupt-driven.