GPIO MCAL Module
Supported STM32 families: F4 · G4 · H5 · U5
Not supported: H7, L4
Overview
The GPIO (General Purpose Input/Output) MCAL module provides a hardware abstraction layer for configuring and controlling MCU pins and ports.
It offers unified APIs to manage pin direction, mode, speed, pull resistors, alternate functions, and digital I/O levels.
This module is shared across all branches.
Each branch represents a different STM32 MCU family, and switching between families is done by checking out the corresponding branch.
Features
- Initialization and deinitialization of GPIO driver
- Port-level enable/disable control
- Pin configuration:
- Mode (Input, Output, Alternate, Analog)
- Speed
- Output type (Push-pull / Open-drain)
- Alternate function mapping
- Pull-up / Pull-down configuration
- Pin state control:
- Set / Clear / Toggle pin
- Read pin level
- Define active/inactive states
- Periodic task function for background handling (if required)
- Module version query
Public API
Module Management
gpio_ModuleVersion_t Gpio_Get_ModuleVersion(void);
gpio_RequestState_t Gpio_Init(gpio_Config_t *gpioConfig);
void Gpio_Deinit(void);
void Gpio_Task(void);
Port Control
gpio_RequestState_t Gpio_Set_PortActive (gpio_PortId_t portId);
gpio_RequestState_t Gpio_Set_PortInactive (gpio_PortId_t portId);
gpio_RequestState_t Gpio_Get_PortState (gpio_PortId_t portId, gpio_FunctionState_t * const portState);
Pin Configuration
gpio_RequestState_t Gpio_Set_PinMode (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinMode_t pinType);
gpio_RequestState_t Gpio_Get_PinMode (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinMode_t * const pinType);
gpio_RequestState_t Gpio_Set_PinSpeed (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinSpeed_t pinSpeed);
gpio_RequestState_t Gpio_Get_PinSpeed (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinSpeed_t * const pinSpeed);
gpio_RequestState_t Gpio_Set_PinOutType (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinOutputType_t pinOutType);
gpio_RequestState_t Gpio_Get_PinOutType (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinOutputType_t * const pinOutType);
gpio_RequestState_t Gpio_Set_PinAltFunction (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_AltFunction_t altFunc);
gpio_RequestState_t Gpio_Get_PinAltFunction (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_AltFunction_t * const altFunc);
gpio_RequestState_t Gpio_Set_PinPull (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinPullCfg_t pullCfg);
gpio_RequestState_t Gpio_Get_PinPull (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinPullCfg_t * const pullCfg);
Pin State Control
gpio_RequestState_t Gpio_Toggle_PinLevel (gpio_PortId_t portId, gpio_PinId_t pinId);
gpio_RequestState_t Gpio_Set_PinLevel (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinLevel_t pinLevel);
gpio_RequestState_t Gpio_Get_PinLevel (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinLevel_t * const pinLevel);
gpio_RequestState_t Gpio_Set_PinStateActive (gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinLevel_t pinActiveLevel);
gpio_RequestState_t Gpio_Set_PinStateInactive(gpio_PortId_t portId, gpio_PinId_t pinId, gpio_PinLevel_t pinActiveLevel);
Usage Notes
- Before calling any pin or port functions,
Gpio_Init()must be executed. - Port must be set active before pins within that port can be configured or toggled.
- Active/Inactive states can be defined per pin to abstract logical level (e.g.
Active = High,Inactive = Low). - The
Gpio_Task()function can be used if background processing or state checks are required. - Alternate functions are MCU-family dependent and differ across branches.
🛠 CMake Integration
- Include
Gpio_Libin your CMake library. - Include
Gpio_Port.hin your project. - Link against the Gpio module implementation files.
- Configure the module as needed for your hardware.
License
This project is licensed under the Creative Commons Attribution–NonCommercial 4.0 International (CC BY-NC 4.0).
You are free to use, modify, and share this work for non-commercial purposes, provided appropriate credit is given.
See LICENSE.md for full terms or visit creativecommons.org/licenses/by-nc/4.0.
Authors
- Mr.Nobody — embedbits.com
Contributions are welcome! Please open a pull request.