AutoHIL is a hardware-in-the-loop validation bench for a microcontroller-based embedded device. A Python test runner communicates with firmware over USB serial, injects software faults, validates sensor and state behavior, measures latency, and generates pass/fail reports.
The MVP models a small embedded safety controller. The board reads a potentiometer as a fake analog sensor, reads a push button as an emergency input, drives a green LED in normal mode, drives a red LED in fault or safe mode, and accepts newline-terminated serial commands from a laptop.
Embedded validation work is more than firmware that blinks an LED. This project demonstrates the engineering loop used on real hardware programs:
- A device under test with ADC, GPIO, LED outputs, state, and fault handling.
- A host-side test controller that drives the device over USB serial.
- JSON telemetry that can be parsed by automated tests.
- Fault injection and recovery checks.
- Latency measurement and CSV/JSON reports.
Version 1 targets the NUCLEO-F401RE as the recommended MVP board. An ESP32 dev board or another STM32 Nucleo can be used later if the board abstraction functions in firmware/src/board_config.h are mapped to that platform.
Required MVP hardware:
- 1 NUCLEO-F401RE board
- Onboard green LD2 LED on
PA5 - 1 external red LED connected to
PB5through a220 ohmor330 ohmresistor to GND - Onboard B1 user button on
PC13 - 1 potentiometer connected to
PA0 / ADC1_IN0 - USB cable for serial communication
- Breadboard and jumper wires
CAN, I2C, SPI, RTOS, PCB, dashboard, and wireless features are intentionally out of scope for this MVP.
The NUCLEO-F401RE MVP mapping is:
| Function | Pin |
|---|---|
| Green LED | Onboard LD2 on PA5 |
| Red LED | External LED on PB5 |
| Button | Onboard B1 on PC13 |
| Potentiometer | Middle pin to PA0 / ADC1_IN0 |
| Serial | USART2 ST-LINK VCP, PA2 TX, PA3 RX, 115200 baud |
See docs/wiring_f401re.md for exact F401RE wiring and docs/wiring.md for the generic wiring notes.
Create a Python environment and install dependencies:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtOn Linux/macOS:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtThe firmware is written as portable C modules under firmware/src. Board-specific UART, GPIO, ADC, and timing functions are declared in board_config.h.
Important files:
firmware/src/autohil_app.c # reusable app init/poll loop
firmware/src/command_parser.c # serial command dispatch
firmware/src/fault_manager.c # state, faults, LEDs, button safe mode
firmware/src/sensor.c # ADC sensor read and voltage conversion
firmware/src/telemetry.c # JSON response formatting
firmware/src/timing.c # timing wrappers
firmware/src/board_config.h # hardware abstraction API
firmware/targets/stm32_f401re/board_config_stm32.c
firmware/src/main.c is only a portable harness. When using STM32CubeIDE, keep CubeIDE's generated Core/Src/main.c and call autohil_app_init() / autohil_app_poll_once() from it.
Detailed CubeIDE steps are in docs/stm32cubeide_setup.md. The command protocol is documented in firmware/protocol.md.
Bring the board up in this order:
- Flash basic
PA5LED blink. - Test USART2
PINGin a serial terminal. - Run the Python
PINGsmoke test. - Only then wire the potentiometer and external red LED.
The first real milestone is: Python sends PING, STM32 returns newline-terminated JSON, Python prints PASS.
See docs/bringup_sequence.md for the full sequence.
Windows example:
python hil_runner/main.py --port COM3Linux/macOS example:
python hil_runner/main.py --port /dev/ttyACM0You can also set an environment variable:
$env:AUTOHIL_PORT="COM3"
python hil_runner/main.pyThe runner executes:
PINGGET_STATUSGET_SENSORINJECT_FAULT SENSOR_FAILCLEAR_FAULTS
It prints a pass/fail summary and writes CSV and JSON reports to reports/.
Hardware tests:
pytest tests --port COM3If no port is provided through --port or AUTOHIL_PORT, the hardware tests skip cleanly.
Hardware-free mock serial tests:
python -m pytest tests/test_serial_client_mock.py -vThese tests validate the Python serial client without a physical STM32 board.
Reports are saved as:
reports/run_YYYY_MM_DD_HHMMSS.csvreports/run_YYYY_MM_DD_HHMMSS.json
Each row includes timestamp, test name, command, expected result, actual result, pass/fail status, latency, fault mode, and notes.
Resume bullets and skills are in docs/resume_bullets.md.
Wrong COM port:
- On Windows, check Device Manager for the ST-LINK Virtual COM Port.
- Try
python hil_runner/main.py --port COM3, replacingCOM3with the actual port.
No serial response:
- Confirm USART2 is enabled in asynchronous mode at
115200. - Confirm the board is connected through the ST-LINK USB connector.
- Confirm firmware responses are newline-terminated through
board_uart_write_line(). - Confirm the AutoHIL loop was merged into the generated CubeIDE
main.cafter HAL initialization.
Invalid JSON:
- Do not print debug logs on the same UART used by AutoHIL.
- Confirm every firmware response is a single JSON object followed by a newline.
ADC always reads 0 or 4095:
- Confirm the potentiometer side pins are connected to
3.3VandGND. - Confirm the middle wiper pin is connected to
PA0. - Confirm CubeIDE configured
PA0asADC1_IN0.
Button logic inverted:
- The adapter expects B1 on
PC13to read pressed asGPIO_PIN_SET. - If your project reads the opposite, set
AUTOHIL_BUTTON_ACTIVE_LOWto1before compilingboard_config_stm32.c.
Red LED not turning on:
- Confirm the LED anode path is
PB5 -> resistor -> LED anode, and LED cathode goes toGND. - Confirm
PB5is configured as GPIO output. - Flip the LED orientation if needed.
HIGH_LATENCY test timing out:
- The firmware intentionally delays that response by at least
100 ms. - Keep the Python timeout at
2.0seconds or higher. - If using a terminal, test
INJECT_FAULT HIGH_LATENCYdirectly before running pytest.
- Version 2: Add I2C sensor validation.
- Version 3: Add SPI self-test.
- Version 4: Add CAN telemetry node.
- Version 5: Add a simple dashboard with graphs.
- Version 6: Design a custom PCB test fixture.