|
| 1 | +# elkanamol/console — STM32U585 Multi-Threaded Sensor Console |
| 2 | + |
| 3 | +**Short project summary** |
| 4 | + |
| 5 | +Manual-control Zephyr RTOS console for STM32U585 (BlackPill), featuring Zbus message bus, supervisor FSM, SSD1306 OLED display thread, and diagnostic sensor monitoring. See [docs/DESIGN_DES.md](docs/DESIGN_DES.md) for full architecture and task roadmap. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +**Phase 1: Manual button/shell control (OFF ↔ ACTIVE ↔ SLEEP)** |
| 12 | + |
| 13 | +- Zbus message bus for thread coordination |
| 14 | +- Supervisor FSM for state transitions |
| 15 | +- SSD1306 OLED display thread: updates automatically in ACTIVE, manual override via shell |
| 16 | +- Internal/external sensor reads (BME280, MPU6050, ADC) |
| 17 | +- All state transitions are user-initiated (button/shell) |
| 18 | + |
| 19 | +See [docs/DESIGN_DES.md](docs/DESIGN_DES.md) for details. |
| 20 | + |
| 21 | +## Features |
| 22 | + |
| 23 | +This project is a Zephyr RTOS application for STM32U585 that provides: |
| 24 | + |
| 25 | +- USB CDC ACM shell console |
| 26 | +- Interrupt-driven button handling with software debounce |
| 27 | +- LED auto-blink timer that runs independently of shell activity |
| 28 | +- Internal sensor reads via Zephyr sensor API (temperature, VREF, VBAT) |
| 29 | +- External I2C sensor reads (BME280, MPU6050) |
| 30 | +- Periodic sensor sampling via a dedicated work queue |
| 31 | + |
| 32 | +Code organization (key directories): |
| 33 | + |
| 34 | +- `src/app`: application state + pure app logic |
| 35 | +- `src/sensors`: internal/external sensor modules |
| 36 | +- `src/shell`: shell commands + shell parsing logic |
| 37 | +- `src/hal`: Zephyr HAL wrappers used for host-side unit testing |
| 38 | + |
| 39 | +## Requirements |
| 40 | + |
| 41 | +- STM32U585 board (BlackPill STM32U585CI or compatible) |
| 42 | +- Zephyr SDK/toolchain for firmware build + flash |
| 43 | +- Python virtual environment at `../.venv` |
| 44 | +- Ruby + Ceedling for host-side unit tests |
| 45 | +- `gcovr` (Python package) for coverage reports |
| 46 | + |
| 47 | +## Building and Running |
| 48 | + |
| 49 | +Firmware build / flash (example): |
| 50 | + |
| 51 | +```bash |
| 52 | +source ../.venv/bin/activate |
| 53 | +# Build |
| 54 | +west build -p always -b blackpill_u585ci -d build/console |
| 55 | +# Flash (after successful build) |
| 56 | +west flash -d build/console |
| 57 | +``` |
| 58 | + |
| 59 | +Shell connection (example): |
| 60 | + |
| 61 | +```bash |
| 62 | +minicom -D /dev/ttyACM0 -b 115200 |
| 63 | +``` |
| 64 | + |
| 65 | +VS Code tasks are available for common workflows (build/flash/monitor/test). |
| 66 | + |
| 67 | +## Shell Commands |
| 68 | + |
| 69 | +### Display commands |
| 70 | + |
| 71 | +- `display on` — turn the SSD1306 OLED on (ACTIVE only) |
| 72 | +- `display off` — turn the display off |
| 73 | +- `display write "text"` — write a single line to the display |
| 74 | +- `display status` — show display state |
| 75 | + |
| 76 | +### LED commands |
| 77 | + |
| 78 | +- `led on` |
| 79 | +- `led off` |
| 80 | +- `led toggle` |
| 81 | + |
| 82 | +### Button commands |
| 83 | + |
| 84 | +- `button info` — show button stats |
| 85 | +- `button reset` — reset button counters |
| 86 | + |
| 87 | +### Sensor commands |
| 88 | + |
| 89 | +- `sensor temp` — read internal temperature |
| 90 | +- `sensor vref` — read internal VREF |
| 91 | +- `sensor vbat` — read VBAT |
| 92 | +- `sensor all` — show latest environmental data |
| 93 | +- `sensor bme280` — read external BME280 |
| 94 | +- `sensor mpu6050` — read external MPU6050 |
| 95 | + |
| 96 | +### Notes on display behavior |
| 97 | + |
| 98 | +- The display thread subscribes to sensor data and `display` commands. |
| 99 | +- In `ACTIVE` mode the display updates automatically on new sensor data (data-driven). |
| 100 | +- In `OFF` and `SLEEP` the display remains off; `display on` can force it on for diagnostics. |
| 101 | +- Manual display commands override rendering but do not change the system FSM state. |
| 102 | + |
| 103 | +## TDD Methodology (Current) |
| 104 | + |
| 105 | +Development follows **Red → Green → Refactor** with Ceedling + Unity + CMock: |
| 106 | + |
| 107 | +1. Add failing unit test(s) |
| 108 | +2. Implement smallest production change |
| 109 | +3. Refactor while tests remain green |
| 110 | +4. Run `ceedling test:all` |
| 111 | +5. Run Zephyr firmware build to prevent regressions |
| 112 | + |
| 113 | +## Unit Testing and Coverage |
| 114 | + |
| 115 | +Run unit tests (host-side Ceedling): |
| 116 | + |
| 117 | +```bash |
| 118 | +source ../.venv/bin/activate |
| 119 | +export PATH="$HOME/.local/share/gem/ruby/3.2.0/bin:$PATH" |
| 120 | +ceedling test:all |
| 121 | +``` |
| 122 | + |
| 123 | +Generate coverage (clean run recommended): |
| 124 | + |
| 125 | +```bash |
| 126 | +source ../.venv/bin/activate |
| 127 | +export PATH="$HOME/.local/share/gem/ruby/3.2.0/bin:$PATH" |
| 128 | +ceedling clobber |
| 129 | +ceedling gcov:all |
| 130 | +``` |
| 131 | + |
| 132 | +Optional: produce full HTML/XML report: |
| 133 | + |
| 134 | +```bash |
| 135 | +ceedling gcov:all report:gcov |
| 136 | +``` |
| 137 | + |
| 138 | +> Note: coverage generation can take several minutes; results are printed to the runner console. |
| 139 | +
|
| 140 | +## CI |
| 141 | + |
| 142 | +GitHub Actions workflow: `.github/workflows/ceedling-ci.yml` |
| 143 | + |
| 144 | +- Runs `ceedling test:all` |
| 145 | +- Runs `ceedling gcov:all` |
| 146 | +- Coverage is emitted to runner logs (no CI artifact upload) |
| 147 | + |
| 148 | +## Project Status |
| 149 | + |
| 150 | +Phase 1 is focused on manual control (OFF ↔ ACTIVE ↔ SLEEP). Current highlights: |
| 151 | + |
| 152 | +- Zbus and message definitions: ✅ |
| 153 | +- Central sensor thread (BME280 + MPU6050) and I2C mutex: ✅ |
| 154 | +- Supervisor FSM (button-driven): ✅ |
| 155 | +- Display thread (SSD1306): ✅ (data-driven updates in ACTIVE; manual override via shell) |
| 156 | +- Internal ADC sensors (temp, VREF, VBAT): partial — next task (TG 4.4) |
| 157 | + |
| 158 | +See [docs/DESIGN_DES.md](docs/DESIGN_DES.md) for full task order and future Phase 2/3 work (IMU interrupts, GPS). |
| 159 | + |
| 160 | +## Project Notes |
| 161 | + |
| 162 | +- Internal sensor readings are intended for diagnostics, not precision calibration. |
| 163 | +- LED auto-blink starts at boot (500 ms period). |
| 164 | +- Button debounce window is 50 ms. |
| 165 | +- Periodic sampling runs through Zephyr work queue infrastructure. |
0 commit comments