Skip to content

About

STM32 NUCLEO-F446RE firmware tested at four levels: Unity unit tests with 100 % coverage, a pytest host simulation, SIL in Renode with Robot Framework, and HIL on a Raspberry Pi 4 test agent. Runs in GitHub Actions CI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

Embedded test automation for STM32 firmware

ci

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.

The firmware under test

  • 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): r reverse, f faster, s slower, p pause/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
    

Test levels

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.

CI (GitHub Actions)

  • .github/workflows/ci.yml runs on every push, on GitHub's servers: unit tests, firmware build, host system tests, SIL.
  • .github/workflows/hil.yml runs HIL on the Raspberry Pi (a self-hosted runner). It runs on demand only: Actions > hil > Run workflow.

How to run the tests

1. Install the tools (Ubuntu 24.04)

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 curl

For 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"' >> ~/.bashrc

To 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.

2. Run the tests on your PC

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.

3. Run the tests on the real board (HIL)

  1. Connect the Nucleo to the Raspberry Pi as shown in docs/WIRING.md. Plug the Nucleo's USB cable into the Pi.
  2. 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
  3. Build, flash and test:
    make fw
    make hil
    make hil flashes the board with st-flash and runs the system tests against the real hardware.

Project layout

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

About

STM32 NUCLEO-F446RE firmware tested at four levels: Unity unit tests with 100 % coverage, a pytest host simulation, SIL in Renode with Robot Framework, and HIL on a Raspberry Pi 4 test agent. Runs in GitHub Actions CI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages