This project is a test system for embedded firmware. It shows how to test an STM32 firmware automatically at four levels: unit tests, system tests on a host simulation, software-in-the-loop (SIL) in an emulator, and hardware-in-the-loop (HIL) on the real board, with a Raspberry Pi 4 as the test agent. All levels run from one command each, and in GitHub Actions CI.
- 7 LEDs on pins PC0..PC6 light up one after another, 1 second each. After PC6 the sequence starts again at PC0.
- The green board LED LD2 (PA5) toggles on every step.
- The blue button B1 (PC13) changes the direction. Presses shorter than 30 ms are ignored (debounce).
- UART commands (115200 baud, over the ST-LINK USB port):
rreverse,ffaster,sslower,ppause/resume,?status. - On every step the firmware sends a status line. The tests read these lines:
BOOT led_seq 1.0.0 STEP 0 DIR + PERIOD 1000 T 0 STEP 1 DIR + PERIOD 1000 T 1000
| Level | What is tested | Tools | Where in the code |
|---|---|---|---|
| Unit | C logic on the PC, with a fake board | Unity, gcc, gcovr | tests/unit/ |
| Host system | Black-box tests against a PC simulation of the firmware | pytest | tests/system/ (target host) |
| SIL | The real led_seq.elf in an emulated STM32F4 |
Renode, Robot Framework | tests/sil/ |
| HIL | The real board, controlled and measured by a Raspberry Pi 4 | pytest, lgpio, pyserial, st-flash | tests/system/ (target pi), docs/WIRING.md |
The code is in nucleo_led/App/. The logic (led_seq.c, button.c,
app.c) does not use the HAL. All hardware access goes through 6 functions
in board.h. There are three versions of these functions:
| File | Used for |
|---|---|
nucleo_led/App/board_stm32.c |
the real board (HAL) |
tests/unit/fake_board.c |
unit tests |
tests/system/targets/host_sim.c |
system tests on the PC |
This is why the same logic can run on the board and on a normal PC.
.github/workflows/ci.ymlruns on every push, on GitHub's servers: unit tests, firmware build, host system tests, SIL..github/workflows/hil.ymlruns HIL on the Raspberry Pi (a self-hosted runner). It runs on demand only: Actions > hil > Run workflow.
sudo apt update
sudo apt install -y git build-essential cmake ninja-build \
gcc-arm-none-eabi libnewlib-arm-none-eabi \
python3-pytest python3-serial python3-venv gcovr curlFor SIL, install Renode 1.16 and its Python packages:
cd ~
curl -LO https://github.com/renode/renode/releases/download/v1.16.0/renode-1.16.0.linux-portable-dotnet.tar.gz
mkdir renode && tar xzf renode-1.16.0.linux-portable-dotnet.tar.gz -C renode --strip-components=1
python3 -m venv ~/renode-venv && source ~/renode-venv/bin/activate
pip install -r renode/tests/requirements.txt pytest pyserial
echo 'export PATH="$HOME/renode:$PATH"' >> ~/.bashrcTo change the board configuration or to debug on the board, you also need STM32CubeMX and STM32CubeIDE from st.com. You don't need them to run the tests.
From the repository root:
make unit # unit tests
make coverage # unit tests + coverage report (tests/unit/build/coverage/index.html)
make fw # build the firmware: build-fw/led_seq.elf and .bin
make host # system tests on the PC simulation (about 40 s)
source ~/renode-venv/bin/activate
make sil # SIL tests in Renode (report: sil-results/report.html)make help shows all targets.
- Connect the Nucleo to the Raspberry Pi as shown in docs/WIRING.md. Plug the Nucleo's USB cable into the Pi.
- On the Pi (Raspberry Pi OS, 64-bit), get the code and install the tools once:
git clone https://github.com/<your-user>/embedded-test-automation.git cd embedded-test-automation bash scripts/setup_pi.sh # then log out and in again
- Build, flash and test:
make fw make hil
make hilflashes the board withst-flashand runs the system tests against the real hardware.
nucleo_led/ CubeMX + CubeIDE project
App/ our code: led_seq, button, app, board.h, board_stm32.c
Core/, Drivers/ generated by CubeMX (HAL)
CMakeLists.txt, cmake/ firmware build without the IDE (used by CI)
tests/unit/ Unity tests + fake board
tests/system/ pytest black-box tests, targets: host simulation, Raspberry Pi
tests/sil/ Renode platform + Robot Framework tests
scripts/setup_pi.sh makes a fresh Raspberry Pi a test agent
.github/workflows/ ci.yml (GitHub servers), hil.yml (Raspberry Pi, on demand)
docs/ wiring