This project is a custom Hardware Abstraction Layer (HAL) for the STM32F4 microcontroller series, specifically designed for the STM32F446RE. It provides direct, register-level control without relying on the STM32 HAL or CMSIS libraries. Built for learning purposes and to show what is going on underneath the hood.
- GPIO – Configure, read, write, and set alternate functions.
- RCC – Enable peripheral clocks manually.
- SPI – Master mode, full-duplex SPI support.
- Systick – Microsecond and millisecond delay functionality.
- TIM – Timer initialization and basic configuration.
- UART – Transmit, receive, and configure UART communication.
Hal_Library/
├── core/ # Contains main.c
├── src/ # All peripheral source files (hal_gpio.c, etc.)
├── include/ # Public headers (hal_gpio.h, etc.)
│ └── registers/ # Peripheral register mappings (stm32f4_gpio.h, etc.)
├── platform/stm32f4/ # Contains Startup file and linker script
├── build/ # Build artifacts (generated)
├── Makefile # Build system
└── README.md # This file
arm-none-eabi-gccstlink-tools(providesst-flashandst-utilfor ST-Link programming/debugging)
Install with:
sudo apt install gcc-arm-none-eabi stlink-tools| Command | Description |
|---|---|
make |
Compiles all source files and links the ELF |
make clean |
Removes the build/ directory |
make flash |
Flashes the .bin to STM32 via ST-Link |
make debug |
Launches st-util and opens GDB |
- Ensure the STM32 is connected via ST-Link and powered on.
- Flashing uses
st-flash. The address0x08000000is the flash start. - You may need
sudodepending on udev rules:
sudo make flash- Connect your board via USB ST-Link.
- Start
st-utilmanually. - Launch GDB (use
gdb-multiarchif needed):
gdb-multiarch build/main.elf- In GDB:
(gdb) target extended-remote :4242
(gdb) monitor reset halt
(gdb) continue
Optional GDB commands:
step(single instruction)next(steps through)break <function>(set breakpoint)info registers(shows registers)x/10i $pc(disassemble instructions at PC)
To view the generated documentation in your browser, use the helper script:
./open_docs.shIf the documentation hasn’t been generated yet, run:
doxygen Doxyfile- Output HTML goes to
docs/html/index.htmlby default.
-
Cause: Wrong path to startup file.
-
Fix: Update
STARTUPvariable inMakefile:STARTUP = platform/stm32f4/startup.s
- Cause: The linker can't find your
main()function. - Fix: Ensure
core/main.cis included inSRC_DIRor explicitly added.
-
Cause: ST-Link utilities not installed.
-
Fix:
sudo apt install stlink-tools
This HAL was built for educational purposes and kept intentionally minimal. Contributions, testing, and refactors are welcome. This library avoids all vendor dependencies for clarity and control.
MIT License – Use and modify freely.