A beginner-friendly STM32 project that demonstrates how to interface a 7-segment display using STM32 HAL (Hardware Abstraction Layer) in STM32CubeIDE.
This repository focuses on:
- Clean GPIO configuration using HAL
- Clear segment-to-pin mapping
- Logical digit control (0–9)
- Industry-style embedded project structure
To display digits 0 → 9 on a 7-segment display by controlling individual LED segments using STM32 GPIO pins via HAL APIs.
This project builds a strong foundation for:
- GPIO fundamentals
- Display interfacing concepts
- Transitioning from Arduino-style coding to professional STM32 workflows
By completing this project, you will understand:
- How a 7-segment display works internally
- How STM32 GPIO pins control external hardware
- How HAL abstracts register-level complexity
- Pin planning and wiring best practices
- Embedded logic mapping (digit → segment pattern)
- STM32 Board (e.g., STM32F446RE Nucleo)
- Single-digit 7-segment display
- 220Ω–330Ω resistors (7 numbers)
- Breadboard & jumper wires
- STM32CubeIDE
- STM32 HAL drivers
- ST-Link (onboard or external)
⚠️ Display Type Assumption: COMMON CATHODE (If you use a Common Anode display, logic must be inverted)
| Segment | Description | STM32 GPIO | Nucleo Pin |
|---|---|---|---|
| a | Top | PA0 | D7 |
| b | Top-Right | PA1 | D8 |
| c | Bottom-Right | PA2 | D9 |
| d | Bottom | PA3 | D10 |
| e | Bottom-Left | PA4 | D11 |
| f | Top-Left | PA5 | D12 |
| g | Middle | PA6 | D13 |
Common Cathode Pin → GND
- Digital-only pins (no analog confusion)
- Physically continuous on Nucleo boards
- Cleaner breadboard wiring
- Beginner-friendly visibility
This is intentional hardware design, not random pin picking.
Each segment must use a resistor.
STM32 Pin → 220Ω → Segment Pin
Skipping resistors risks:
- Burning LED segments
- Permanent STM32 GPIO damage
Configure PA0–PA6 as:
- Mode:
GPIO_Output - Output Type:
Push-Pull - Pull-up/Pull-down:
No Pull - Speed:
Low / Medium
HAL will generate the GPIO init code automatically.
| GPIO State | Segment |
|---|---|
| HIGH (1) | ON |
| LOW (0) | OFF |
Each number (0–9) is represented by a bit pattern, deciding which segments turn ON.
Example:
- Digit 0 → a b c d e f ON
- Digit 1 → b c ON
- Digit 8 → all segments ON
The logic is implemented cleanly using HAL GPIO writes.
- Initialize HAL
- Configure system clock
- Initialize GPIO pins
- Select digit pattern
- Set GPIO pins accordingly
- Delay
- Repeat
| Issue | Likely Cause |
|---|---|
| Nothing lights | COM pin not grounded |
| Wrong number | Segment wiring mismatch |
| Inverted logic | Using Common Anode |
| Dim display | Missing resistors |
Core/
├── Src/
│ └── main.c
└── Inc/
└── main.h
Simple. Clean. Beginner-friendly.
- Button-controlled digit increment/decrement
- Multi-digit multiplexing
- Timer-based display refresh
- Register-level version (HAL → Bare-metal)
This project is licensed under the MIT License. You are free to use, modify, and distribute it.