Build System
Complete reference for building NanoVNA-H firmware.
Prerequisites
Section titled “Prerequisites”Toolchain
Section titled “Toolchain”| Tool | Version | Purpose |
|---|---|---|
arm-none-eabi-gcc | 8.x recommended | ARM cross-compiler |
make | 3.81+ | Build automation |
dfu-util | 0.9+ | USB DFU flashing |
Installation
Section titled “Installation”Arch Linux:
sudo pacman -S arm-none-eabi-gcc arm-none-eabi-newlib dfu-util makeUbuntu/Debian:
sudo apt install gcc-arm-none-eabi libnewlib-arm-none-eabi dfu-util makemacOS (Homebrew):
brew install --cask gcc-arm-embeddedbrew install dfu-utilChibiOS Extraction
Section titled “ChibiOS Extraction”ChibiOS is distributed as a compressed archive, not a git submodule.
cd NanoVNA-H7z x ChibiOS.7zThis creates the ChibiOS/ directory containing the RTOS source.
Build Commands
Section titled “Build Commands”Basic Build
Section titled “Basic Build”# Build for NanoVNA-H (STM32F072, default)make
# Build for NanoVNA-H4 (STM32F303)make TARGET=F303
# Clean build artifactsmake clean
# Flash via DFUmake flashOutput Files
Section titled “Output Files”| Target | Output | Size |
|---|---|---|
| F072 | build/H.bin | ~110 KB |
| F303 | build/H4.bin | ~130 KB |
Makefile Targets
Section titled “Makefile Targets”| Target | Description |
|---|---|
all | Build firmware (default) |
clean | Remove build directory |
flash | Flash via DFU |
dfu | Reset device to DFU mode |
TAGS | Generate etags file |
Target Selection
Section titled “Target Selection”# Default targetifeq ($(TARGET),) TARGET = F072endif| TARGET | MCU | Output |
|---|---|---|
| F072 | STM32F072xB | H.bin |
| F303 | STM32F303xC | H4.bin |
Compiler Flags
Section titled “Compiler Flags”Optimization
Section titled “Optimization”USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer \ -falign-functions=16 --specs=nano.specs -fstack-usage -std=c11USE_OPT += -ffast-math -fsingle-precision-constant| Flag | Purpose |
|---|---|
-O2 | Optimization level 2 |
-fno-inline-small-functions | Reduce code size |
-ggdb | Debug symbols for GDB |
-fomit-frame-pointer | Free up a register |
-falign-functions=16 | Align functions for performance |
--specs=nano.specs | Use newlib-nano (smaller libc) |
-fstack-usage | Generate stack usage reports |
-std=c11 | C11 standard |
-ffast-math | Aggressive floating-point optimization |
-fsingle-precision-constant | Use float instead of double |
Link Time Optimization
Section titled “Link Time Optimization”USE_LTO = yesLTO is enabled by default, allowing cross-module optimization. This reduces code size but increases build time.
Garbage Collection
Section titled “Garbage Collection”USE_LINK_GC = yesRemoves unused functions and data from the final binary.
Target-Specific Settings
Section titled “Target-Specific Settings”MCU = cortex-m0UDEFS = -DARM_MATH_CM0 -DVERSION=\"$(VERSION)\"LDSCRIPT = NANOVNA_STM32_F072/STM32F072xB.ld- No FPU (software floating-point)
- Cortex-M0 instruction set
- 128 KB flash, 16 KB RAM
MCU = cortex-m4USE_FPU = hardUDEFS = -DARM_MATH_CM4 -DVERSION=\"$(VERSION)\" -DNANOVNA_F303LDSCRIPT = NANOVNA_STM32_F303/STM32F303xC.ld- Hard FPU (hardware floating-point)
- Cortex-M4 instruction set with DSP
- 256 KB flash, 40 KB RAM
User Defines
Section titled “User Defines”# Target-specific definesUDEFS = -DARM_MATH_CM4 -DVERSION=\"$(VERSION)\" -DNANOVNA_F303
# RTC clock sourceUDEFS += -DVNA_AUTO_SELECT_RTC_SOURCE# Or use external 32.768 kHz crystal:# UDEFS += -DVNA_USE_LSE
# Optional features# UDEFS += -D__VNA_Z_RENORMALIZATION__# UDEFS += -D__VNA_FAST_LINES__Source Files
Section titled “Source Files”Main Application
Section titled “Main Application”CSRC = usbcfg.c \ main.c common.c si5351.c tlv320aic3204.c \ dsp.c plot.c ui.c lcd.c \ data_storage.c hardware.c vna_math.cCSRC += fonts/numfont16x22.c \ fonts/Font5x7.c \ fonts/Font6x10.c \ fonts/Font7x11b.c \ fonts/Font11x14.cFatFS (SD Card)
Section titled “FatFS (SD Card)”CSRC += FatFs/ff.c \ FatFs/ffunicode.cChibiOS
Section titled “ChibiOS”CSRC = $(STARTUPSRC) \ $(KERNSRC) \ $(PORTSRC) \ $(OSALSRC) \ $(HALSRC) \ $(PLATFORMSRC) \ $(BOARDSRC) \ $(STREAMSSRC)ChibiOS Integration
Section titled “ChibiOS Integration”Include Files
Section titled “Include Files”# F072include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f0xx.mkinclude $(CHIBIOS)/os/hal/ports/STM32/STM32F0xx/platform.mkinclude NANOVNA_STM32_F072/board.mkinclude $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk
# F303include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f3xx.mkinclude $(CHIBIOS)/os/hal/ports/STM32/STM32F3xx/platform.mkinclude NANOVNA_STM32_F303/board.mkinclude $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mkStack Configuration
Section titled “Stack Configuration”# Main thread stackUSE_PROCESS_STACKSIZE = 0x200 # 512 bytes
# Exception/interrupt stackUSE_EXCEPTIONS_STACKSIZE = 0x100 # 256 bytesVersion String
Section titled “Version String”VERSION = "$(shell git describe --tags)"The version is embedded in the firmware and displayed by the version and info commands.
Example: 1.2.44
Flashing
Section titled “Flashing”DFU Mode Entry
Section titled “DFU Mode Entry”- Hardware: Hold BOOT0 jumper while powering on
- Menu:
CONFIG>EXPERT SETTINGS>DFU - Shell:
reset dfucommand
Flash Command
Section titled “Flash Command”make flash# Equivalent to:dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D build/H.bin| Option | Meaning |
|---|---|
-d 0483:df11 | ST DFU device ID |
-a 0 | Alt setting 0 (internal flash) |
-s 0x08000000:leave | Start address, exit DFU after |
-D build/H.bin | Download this file |
Debug Configuration
Section titled “Debug Configuration”OpenOCD
Section titled “OpenOCD”openocd -f NanoVNA_DAP.cfgThe NanoVNA_DAP.cfg file configures OpenOCD for CMSIS-DAP debugging.
GDB Connection
Section titled “GDB Connection”arm-none-eabi-gdb build/H.elf(gdb) target remote localhost:3333(gdb) monitor reset halt(gdb) loadBuild Output
Section titled “Build Output”After building, examine the output:
# Check binary sizearm-none-eabi-size build/H.elf
# Example output: text data bss dec hex filename 108544 1024 8192 117760 1cc00 build/H.elf| Section | Content |
|---|---|
text | Code and constants (flash) |
data | Initialized variables (flash + RAM) |
bss | Uninitialized variables (RAM) |
Troubleshooting
Section titled “Troubleshooting”Linker Error: Flash Overflow
Section titled “Linker Error: Flash Overflow”region `flash0' overflowed by XXXXX bytesSolutions:
- Disable unused features in
nanovna.h - Reduce optimization: change
-O2to-Os - Remove debug commands
Compiler Version Issues
Section titled “Compiler Version Issues”HardFault exception on startupSolution: Use GCC 8.x specifically. Install from ARM’s website if your distribution has a different version.
DFU Not Detected
Section titled “DFU Not Detected”dfu-util: No DFU capable USB device availableSolutions:
- Verify device is in DFU mode (BOOT0 held)
- Check USB connection
- Linux: add udev rule for DFU device
- Check
lsusbfor0483:df11
Build From Clean
Section titled “Build From Clean”make cleanrm -rf buildmake TARGET=F072 # or F303Docker Build
Section titled “Docker Build”For reproducible builds with correct toolchain version:
FROM ubuntu:20.04RUN apt-get update && apt-get install -y \ gcc-arm-none-eabi \ libnewlib-arm-none-eabi \ make \ p7zip-fullWORKDIR /buildCOPY . .RUN 7z x ChibiOS.7z && makedocker build -t nanovna-build .docker run --rm -v $(pwd)/build:/build/build nanovna-build