How shellever/sa5-ultra works
Project Type and Purpose
• tinySA is an embedded firmware project for a handheld, battery‑powered spectrum analyzer built around an STM32 microcontroller (F072 or F303).
• It uses ChibiOS as its RTOS, FatFs for filesystem access, drivers for RF front‑ends (Si4432/Si446x), display (ILI9341 LCD), audio codec (TLV320AIC3204), and USB DFU for firmware updates.
• There is also a small Python‑based PC companion tool under the python/ directory.
File Structure Analysis
Top‑level components:
• Third‑party libraries:
– ChibiOS/ (RTOS kernel + HAL)
– FatFs/ (FAT filesystem)
• Board‑specific code:
– NANOVNA_STM32_F072/ and NANOVNA_STM32_F303/ subdirs (board configuration, MCU settings, Makefile snippets)
• HAL drivers and peripherals (/*.c, *.h):
– adc.c, hal_adc_lld.c
– spi.h
– si4432.c/.h, si4468.c + radio_config_*.h
– si5351.c/.h (clock generator)
– ili9341.c (LCD)
– tlv320aic3204.c (audio)
– rtc.c
– usbcfg.c/.h (USB DFU)
• Application layer:
– main.c (system init, thread startup)
– sa_core.c/.h (sweep engine + DSP)
– sa_cmd.c (command interface)
– plot.c, waterfall.c (data visualization)
– ui.c (menu system, user input)
– vna_browser.c (data export over USB)
• Build & config:
– Makefile, board linker scripts (STM32F072xB.ld, STM32F303xC.ld), chconf.h, halconf.h, mcuconf.h
• Python companion:
– python/nanovna.py, requirements.txt
Key Architectural Insights from README
• Real‑time sampling sweeps across RF bands using the Si445x front‑end, digitized by the ADC
• Data is processed and drawn to an ILI9341 LCD in real time (sweep plots, waterfall)
• ChibiOS threads isolate peripherals, DSP, UI, and USB
• Firmware is built with GCC‑ARM and flashed via DFU
Components
a. Hardware Layer
• STM32 MCU (F072 or F303)
• RF front‑end (Si4432/Si446x) + matching network
• Clock generator (Si5351)
• ADC (internal ADC peripheral)
• LCD display (ILI9341 via SPI)
• Audio codec (TLV320AIC3204 via I²S/SPI)
• USB interface (DFU device)
• Battery & power management (optional block)
b. Software Layer
• ChibiOS RTOS:
• Kernel + Thread scheduler
• HAL drivers (ADC, SPI, I²C, USB, RTC)
• Drivers & Abstraction:
• Radio driver (si446x.h/c + radio_config headers)
• Driver (ili9341.c)
• Audio driver (tlv320aic3204.c)
• Filesystem (FatFs) – used only if an SD card is present (optional)
• Application Threads:
• Sweep Engine Thread (sa_core.c)
• UI Thread (ui.c + chprintf)
• Plotting Thread (plot.c)
• Waterfall Thread (waterfall.c)
• USB Command/DFU Thread (usbcfg.c + vna_browser.c)
• Configuration Layer
• chconf.h, halconf.h, mcuconf.h
c. External Tools
• DFU Utility (host side)
• Python nanovna.py (USB‑based PC interface)
Interactions & Data Flows
• Control Flow: UI → commands → Sweep Engine → configures front‑end clock & radio registers
• Data Flow: ADC samples → DSP → Plot/Waterfall buffers → Display driver → LCD
• USB Flow: PC (Python) ↔ USB DFU & VNA browser interface → firmware update or data export
Architectural Patterns & Principles
• Layered architecture: HAL → drivers → RTOS services → application threads → UI
• Thread‑based concurrency for real‑time tasks
• Separation of concerns: RF sweep logic isolated from UI and display drawing
• Configurable builds: board‑specific directories for F072 vs. F303