High Altitude Balloon ELEC327 Flight Computer
This repo has flight computer firmware for a high altitude balloon. The target hardware is a custom pcb built around the mspm0g3507 microcontroller, with a bme680 environmental sensor, an external uart gps module, an sx1276 or rfm95w lora radio, and a microsd card.
Repo Layout
- Firmware: flight software for the custom pcb (primary)
- Firmware-poc: bench bring-up harness for the launchpad (start here)
- PCB: kicad schematic and pcb layout files
System Architecture
Hardware
- mcu: mspm0g3507
- environmental sensor: bme680 over i2c
- gps: external breakout over uart
- lora radio: rfm95w or sx1276 over spi
- storage: microsd over spi
- debug uart: cp2102n usb bridge over uart
The lora radio and microsd share the same spi bus. The bme680 uses software i2c and gps uses software uart because pcb v1 routing does not match the validated hardware peripheral pin pairs for the mspm0.
Firmware POC (firmware-poc)
The POC is a minimal bring-up harness. It does not include a state machine or flight logic. Its job is to confirm each peripheral can initialize and run over the correct spi and i2c wiring on the launchpad before trusting the custom pcb.
Firmware-poc can test these breakout boards:
Data Flow:
- Launchpad boots
- SPI init then lora register read to confirm version equals 0x12
- SPI init then microsd mount and fat32 open
- I2C scan to confirm bus is alive
- Loop every n seconds:
- Lora mode transmits one csv packet over 915 mhz
- SD mode appends one csv row to hab_log.csv and flushes
The firmware-poc/feather/feather_m0/feather_m0.ino runs on an adafruit feather m0 rfm95 as the ground station receiver and prints decoded packets to the serial monitor.
Flight Firmware (firmware)
The flight firmware has two layers: a portable application layer and a hardware-specific platform layer. The application layer does not touch registers directly. It calls platform hooks so the same logic can run on a host pc stub or on real hardware.
Layer 1 Application (portable):
- src/main.c: startup, boot, periodic tick entry
- src/hab_app.c: mission state machine and scheduler
- src/hab_gps.c: nmea sentence parser to structured gps fix
- src/hab_bme680.c: bme680 driver wrapper
- src/hab_lora_sx1276.c: sx1276 configuration and transmit
- src/hab_sd_fatfs.c: fatfs csv append and flush
- src/hab_math.c: pressure altitude calculation and filtering
- src/hab_protocol.c: formats telemetry and log csv strings
- include/hab_types.h: shared data structs, states, event flags
- include/hab_config.h: timing constants, thresholds, pin assignments
Layer 2 Platform (hardware-specific):
- src/platform/platform_mspm0_ccs.c: mspm0 clock, gpio, timer, and peripheral init
- src/platform/diskio_mspm0.c: fatfs disk i/o over spi for microsd
- src/platform_stub.c: host simulation platform for development and testing
- include/hab_platform.h: callback interface used by the application layer
Data Flow for One Tick
The scheduler runs every tick (default 1 hz) in this order:
- Timer tick fires
- Read bme680 for temperature, pressure, and humidity
- Read gps for latitude, longitude, altitude, and time
- Run hab_math to compute pressure altitude and apply filter
- Run hab_app to update the mission state machine
- states: BOOT, SELF_TEST, GPS_ACQUIRE, FLIGHT_IDLE, FLIGHT_ACTIVE, EVENT_ACTIVE, FAULT
- Run hab_protocol to format one full sd csv record
- Run hab_sd_fatfs to append the record to microsd and flush
- Every 5 seconds, run hab_protocol to format a short lora packet
- Run hab_lora_sx1276 to transmit at 915 mhz
- MCU sleeps until the next tick
The SD card gets a richer record every second. The lora radio sends a compact summary every 5 seconds to the ground station.
Mission States
- BOOT: hardware initializing
- SELF_TEST: peripheral connectivity check
- GPS_ACQUIRE: waiting for a valid gps fix
- FLIGHT_IDLE: fix acquired, waiting for launch detection
- FLIGHT_ACTIVE: ascending with full logging and telemetry
- EVENT_ACTIVE: altitude threshold crossed, event mode
- FAULT: a sensor or peripheral failed
Build
Both firmware and firmware-poc target TI Code Composer Studio (CCS). Import the folder as a CCS project and build. The MSPM0 SDK must be installed through CCS.
Third-party libraries used:
- Fatfs for microsd filesystem
- Bosch bme68x sensorapi for the bme680 driver