Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

37 Commits

Folders and files

Repository files navigation

cuis-fc — STM32H753ZI + FreeRTOS

Firmware scaffold for the CU InSpace flight computer, targeting an STM32H753ZIT6 on a NUCLEO-H753ZI. It builds, flashes, and runs the FreeRTOS scheduler at 480 MHz. A heartbeat task blinks LD1 (green) at 1 Hz: a steady blink means the scheduler is alive, a frozen LED means a hang or fault. On top of that sits the static-fire stand's firmware: the Sensor HAT and power board, commanded by hand from the launch box over a LoRa link. See The static-fire stand.

New to this? Read docs/how-it-works.md first: the build chain, flash chain, boot sequence and code layout, explained from fundamentals.

Free toolchain throughout: GNU Arm Embedded + CMake + Ninja + OpenOCD. No STM32CubeIDE, no STM32CubeCLT, and no ST account needed to build or flash. CubeMX is used only to regenerate clock and pin configuration.


Prerequisites

Hardware: a NUCLEO-H753ZI board and a USB data cable (the onboard ST-LINK handles both power and flashing — no external programmer needed).

Software: four things on PATH: arm-none-eabi-gcc, cmake (≥3.22), ninja, and openocd. Plus arm-none-eabi-gdb if you want to debug.

macOS
brew install --cask gcc-arm-embedded
brew install cmake ninja open-ocd
Linux (Debian / Ubuntu)
sudo apt update
sudo apt install cmake ninja-build openocd gdb-multiarch

Install the toolchain from Arm directly

ARCH=$(uname -m)   # x86_64 on a PC, aarch64 on a Raspberry Pi / Jetson
curl -LO "https://developer.arm.com/-/media/Files/downloads/gnu/14.2.rel1/binrel/arm-gnu-toolchain-14.2.rel1-$ARCH-arm-none-eabi.tar.xz"
sudo tar xJf arm-gnu-toolchain-14.2.rel1-$ARCH-arm-none-eabi.tar.xz -C /opt
echo "export PATH=\"/opt/arm-gnu-toolchain-14.2.rel1-$ARCH-arm-none-eabi/bin:\$PATH\"" >> ~/.bashrc

Linux-specific notes:

  • Debian/Ubuntu ship gdb-multiarch, not arm-none-eabi-gdb. The workspace settings already point VS Code's debugger at it on Linux.
  • The openocd package already installs a udev rule (/lib/udev/rules.d/60-openocd.rules) that gives the plugdev group access to the ST-LINK. Make sure you're in it, and in dialout for the ST-LINK's serial port (/dev/ttyACM0):
    sudo usermod -aG plugdev,dialout $USER
    Log out and back in, then unplug and replug the board. Without this OpenOCD reports LIBUSB_ERROR_ACCESS.
Windows

Install each tool with winget from PowerShell:

winget install Kitware.CMake                  # CMake: generates the build
winget install Ninja-build.Ninja              # Ninja: runs the build
winget install Arm.GnuArmEmbeddedToolchain    # arm-none-eabi-gcc + gdb
winget install xpack-dev-tools.openocd-xpack  # OpenOCD: flashing and debugging

CMake installs for all users, so Windows asks for administrator approval, and it adds itself to PATH. Prefer a manual install? Download the Windows x64 installer (.msi) from cmake.org/download and pick "Add CMake to the system PATH" during setup. Any CMake 3.22 or newer works.

Windows-specific notes:

  • No USB driver needed on Windows 10/11. The NUCLEO-H753ZI's STLINK-V3 carries its own WinUSB descriptors, so Windows sets it up on first plug-in. (ST's STSW-LINK009 driver is only required for older ST-LINK/V2 probes or Windows 7/8.)
  • Open a new terminal after installing, and fully quit and reopen VS Code: PATH changes only reach programs started afterwards. Then check that all four are found:
    cmake --version
    ninja --version
    arm-none-eabi-gcc --version
    openocd --version
    If one isn't found, add its bin folder to PATH by hand. The usual culprit is the Arm toolchain: its installer has an "Add path to environment variable" checkbox that is off by default.

VS Code extensions are recommended automatically from .vscode/extensions.json: cmake-tools, clangd, cortex-debug, and the mcu-debug views. If you also have ST's STM32 extensions installed, the workspace settings switch off their duplicate clangd and automatic IntelliSense setup for this project.


Build

git clone --recurse-submodules git@github.com:CU-in-Space/flightComputerRTOS.git
cd flightComputerRTOS
cmake --preset debug
cmake --build --preset debug

Already cloned without submodules? git submodule update --init --recursive.

Command Result
cmake --preset debug Configure, -Og -g3
cmake --preset release Configure, -Os -g
cmake --build --preset debug Build → build/debug/cuis-fc.{elf,hex,bin}
cmake --build --preset release Build → build/release/…
cmake --preset test && cmake --build --preset test && ctest --preset test Host unit tests for src/app (needs a normal C compiler)
cmake -E rm -rf build Clean everything

Identical on all three platforms — the presets pin Ninja and the toolchain file, so there is no make vs nmake vs msbuild divergence. In VS Code, ⇧⌘B (Ctrl+Shift+B) runs the debug build.

Every build ends by printing how much flash and RAM it uses. Most of the RAM is the FreeRTOS heap (configTOTAL_HEAP_SIZE).


Flash and debug

cmake --build --preset debug --target flash

This runs OpenOCD, which erases, programs, verifies (** Verified OK **) and resets the board. It is the same on every platform, and the same OpenOCD config is used for debugging.

Another option needs no tools at all: the NUCLEO mounts as a USB drive (NOD_H753ZI), and copying build/debug/cuis-fc.bin onto it flashes the board. Handy for getting a build onto someone's board quickly; no verification, no debug.

Or press F5 in VS Code — that builds, flashes and breaks at main. While debugging:

  • XPERIPHERALS shows every peripheral register by name (ADC1 → CR → ADEN…), from debug/STM32H753.svd. The quickest way to check what a HAL call actually did to the hardware.
  • RTOS lists every FreeRTOS task with its state, priority, and stack size and peak use.
  • LIVE WATCH keeps updating expressions while the chip runs (right-click a variable → Add to Live Watch), so you can watch a sensor reading without halting.

The other everyday actions are VS Code tasks (Terminal → Run Task): Flash (debug), Flash (release), Reset board and Clean. Snippets for the repeated patterns — halok, rtostask, xtaskcreate, mspinit — live in .vscode/stm32.code-snippets.

All probe settings live in openocd/nucleo-h753zi.cfg so the command above is the same on every platform.


The static-fire stand

Power board → Sensor HAT → Nucleo is one stand. There are two, numbered 1 and 2, and one launch box. Each stand reads its sensors, drives its valves, logs to its SD card, and follows the launch box's switches over the radio. There is no built-in sequence: the operator at the launch box runs the test by hand.

Task Priority What it does
interlock 5 checks the battery voltage every 10 ms. Outside 6.9–13.3 V nothing may be on, and the HAT's pins go high impedance
actuator 4 owns the 4 solenoids, 4 servos and the stepper. Takes commands from a queue every 10 ms
pt, tc, lc 3 pressures (1 kHz), thermocouples (10 Hz), load cells (one at about 1 kHz, one at 10 Hz)
radio 2 the link to the launch box: makes the outputs that drive valves follow its switch positions, answers with telemetry, goes safe on SAFE or after 60 s without it
remote 2 runs the command lines that arrive over the radio
console 2 the same commands, typed at the ST-LINK serial port (115200 8N1). Up and down bring back the last 16 lines typed there
datalog 2 writes every sample to the SD card whenever the HAT has power, until log stop: a new file every hour, flushed every 200 ms, each starting with a boot line (boot count, reset reason, firmware, stand, any crash), a health record every second, and everything printed. A 32 GB card holds about three weeks
log 1 printf output to the serial port

Commands, at the serial console or sent from the launch box:

Command
help list commands
status interlock, battery and every actuator
radio the link: when the launch box was last heard and how strongly, its last STATE, packets received and sent, and the ones that weren't taken: damaged, on another protocol version, or not this link's
radio send transmit one telemetry packet, to test the transmitter
radio watch a line for every packet heard, until a key is pressed (serial console only)
off every actuator off
safe every actuator to its abort position: a valve goes where RADIO_VALVE_ABORT in src/app/radio_link.h says, everything else off
sol <1-4 or name> <on|off> a solenoid. Several asked on at once switch on 100 ms apart, SOL1 first, so their full-current peaks don't overlap; off is immediate
srv <1-4 or name> <us|off> a servo's pulse width. Each servo walks there at 2000 µs a second from where its arm is: the last pulse sent (kept through off and resets). After a power cycle that's unknown, so the first pulse jumps straight to the target
stp home | zero | stop | go <step> | jog <steps> the stepper
pt, tc, lc one reading. Add stream for a running display (serial console only)
lc tare <1|2>, lc cal <1|2> <N> zero a load cell; calibrate it with a known load. The cell is its number or name. Both are kept in flash
log, log start, log stop the data log on the SD card, decoded by tools/hat_log.py. It starts by itself at power-up; log stop (before pulling the card) holds until log start or a reboot
stand, stand 2 which stand this is, and what's wired to it: every name and valve. stand 2 changes the number (serial console only)

Names and valves are one table for both stands, src/app/stand_table.c. To change one, edit the table, run the host tests (they check it) and flash. Names show in every print and in the log's CSV columns, and work in commands: sol vent on. The only thing a stand saves is its number, in the HAT's flash, so stand 2 needs the battery in.

The radio link is described in docs/radio-link.md. Its settings and packets are one header, src/app/radio_link.h. The launch box sketch (lunch-box/launch_box/) uses a copy of it: change it here, then copy it there.

Before a static fire

  1. Fill in src/app/stand_table.c: a name for each sensor, and for every output that drives a valve or an igniter, which one. Run the host tests and flash both stands. At the second one type stand 2, once. stand lists what a stand has. Check RADIO_VALVE_ABORT in src/app/radio_link.h is where each valve must go on an abort.
  2. Set E22_TX_POWER_DBM in src/drivers/e22.h for the range (it ships at bench power), build and flash. radio prints the setting.
  3. At each stand: FAT32 card in, battery on, antenna on. status shows ENABLED, radio shows listening.
  4. Launch box on, key off: each stand prints radio: link up. safe at each console and look at the valves: that's the abort.
  5. Nothing to type for the data log: each stand records from power-up. If someone typed log stop, the launch box arming (its key going in) starts it again, or log start at a console. For a record on a laptop too, start python3 tools/ground.py with the ground link plugged in; it records until you quit it.
  6. ARM plug in last, before leaving the stand. Run the test from the launch box. Its abort button is the abort; so is 60 s without the launch box.
  7. log stop at each stand, or stop in ground.py for both. Then python3 tools/hat_log.py S1_nnnn.BIN --out <folder>. ground.py's runs.csv says which files each stand wrote while it ran.

Layout

CMakeLists.txt                  build definition
CMakePresets.json               debug / release / test presets
cmake/arm-none-eabi-gcc.cmake   toolchain file (CPU flags live here)
openocd/nucleo-h753zi.cfg       probe + target settings
debug/STM32H753.svd             register map for the debugger's peripheral view
include/FreeRTOSConfig.h        kernel configuration
include/stm32h7xx_hal_conf.h    HAL module enables, HSE_VALUE
include/ffconf.h                FatFs options
linker/STM32H753ZI_FLASH.ld     memory map
src/main.c                      startup ordering, heartbeat task, FreeRTOS hooks
src/tasks/                      one file per task (interlock, actuators, console, radio, remote commands, PT, TC, load cell, SD data log, debug log, flight stubs)
src/app/                        plain-C logic, unit-tested on the host (test/); the log's and the radio link's formats; stand_table.c, the names and valves of both stands
src/drivers/                    one peripheral or chip each (ADCs, solenoid PWM, servo PWM, stepper, SPI4, MAX31856, W25Q128, ADS1220, SD card, E22 radio module)
src/board/                      HAT/power-board pin map
src/system_clock.c              SystemClock_Config + MPU_Config  (from CubeMX, + ADC clock)
src/stm32h7xx_hal_msp.c         peripheral MSP init              (from CubeMX)
src/gpio.c                      every port clock, plain outputs  (hand-written)
src/usart.c                     peripheral init                  (from CubeMX)
src/stm32h7xx_it.c              core fault handlers              (hand-written)
cubemx/fc.ioc                   CubeMX source of truth for the above
docs/radio-link.md              the radio link, for whoever programs the launch box
lib/                            pinned vendor submodules
tools/hat_log.py                decodes an SD-card log (S1_nnnn.BIN) into CSV files
tools/ground.py                 the laptop's ground station: logs telemetry to CSV, sends commands
tools/ground_link/              the ground station's radio: a Nano + RFM95 sketch

Every .c file under src/, including subfolders, is compiled automatically, so new modules and anything copied out of CubeMX need no build-file edits.

Submodule Version
FreeRTOS-Kernel V11.3.1
cmsis_core v5.9.0_20250520
cmsis_device_h7 v1.10.7
stm32h7xx_hal_driver v1.11.6

Troubleshooting

ST-LINK error (DEV_CONNECT_ERR) / USBDeviceOpen: unknown error (0xe00002d8) — something else holds the probe, or the probe is wedged. In order:

  1. Kill ST's shared-access daemon, which CubeMX spawns and leaves running: pkill -f stlink-server. It will grab the probe again next time you open the .ioc, so expect to repeat this after CubeMX sessions.
  2. Close any VS Code debug session or stray openocd (pkill openocd).
  3. Unplug the USB cable, wait 5 s, replug. A failed flash can leave the ST-LINK enumerated but non-functional -- the giveaway is that the NOD_H753ZI drive stops appearing under /Volumes (macOS) or in your file manager.

mode (transport) not supported by device, init mode failed (unable to connect to the target), LIBUSB_ERROR_OTHER, or the NOD_H753ZI drive vanishing mid-copy — try a different USB cable first. A marginal cable produced every one of these during bring-up, on both OpenOCD and STM32CubeProgrammer, and they disappeared with a new cable. Other telltales: the probe shows up with a missing or garbled serial number (system_profiler SPUSBHostDataType on macOS, lsusb -v on Linux), or the NOD_H753ZI drive never mounts. Plug straight into the computer, not through a hub or dongle.

jtag status contains invalid mode value - communication failure during programming — the SWD link dropped mid-write. Check the cable first (above). Otherwise firmware already on the chip may have changed the clocks or entered low power while OpenOCD was attaching: hold the black RESET button while the flash command starts, or drop adapter speed in openocd/nucleo-h753zi.cfg to 480.

arm-none-eabi-gcc was not found on PATH or in the usual install folders — CMake can't see the compiler. Run arm-none-eabi-gcc --version in a new terminal: if that fails too, the toolchain isn't on PATH (see your platform's install notes). If it works there but not in VS Code, quit VS Code completely and reopen it. Then delete build/ and configure again. As a last resort, point CMake at the compiler directly: cmake --preset debug -DARM_GCC=<full path to arm-none-eabi-gcc>.

The CMAKE_C_COMPILER: … is not a full path to an existing compiler tool (Windows) — an older version of cmake/arm-none-eabi-gcc.cmake dropped the .exe from the compiler's path. Pull the latest code, delete build/, and configure again.

LIBUSB_ERROR_ACCESS (Linux) — you're not in the plugdev group, or haven't logged out and back in since joining it; see the Linux section.

OpenOCD sees no board (Windows) — check that the probe shows up in Device Manager with no warning icon. If not, try another cable (above). If a tool such as Zadig has replaced the ST-LINK's driver, uninstall that device in Device Manager (tick "delete the driver") and replug to get the built-in WinUSB driver back.

Only 1 MB of flash visible — you are using target/stm32h7x.cfg instead of the dual-bank config. Use openocd/nucleo-h753zi.cfg.

Duplicate symbol SysTick_Handler — you pasted CubeMX's stm32h7xx_it.c wholesale. Take only the peripheral IRQ handlers from it.

implicit declaration of HAL_... — the CubeMX firmware package is newer than the pinned stm32h7xx_hal_driver. Bump the submodule tag.


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages