Flash Memory Layout
Reference for the flash memory layout used to store calibration data and device configuration.
Overview
Section titled “Overview”NanoVNA-H stores persistent data in on-chip flash memory:
- Calibration data (
properties_t): Sweep settings and calibration coefficients - Configuration data (
config_t): Device settings and color palette
Data is stored at the end of flash, leaving room for firmware at the beginning.
Memory Maps
Section titled “Memory Maps”STM32F072xB Flash Layout
| Address Range | Size | Content |
|---|---|---|
0x08000000 - 0x0801BFFF | 112 KB | Firmware code |
0x0801C000 - 0x0801D7FF | 6 KB | Property slot 0 |
0x0801D800 - 0x0801EFFF | 6 KB | Property slot 1 |
0x0801F000 - 0x080207FF | 6 KB | Property slot 2 |
0x08020800 - 0x08021FFF | 6 KB | Property slot 3 |
0x08022000 - 0x080237FF | 6 KB | Property slot 4 |
0x08023800 - 0x08023FFF | 2 KB | Configuration |
Constants:
#define FLASH_START_ADDRESS 0x08000000#define FLASH_TOTAL_SIZE (128*1024) // 131072 bytes#define FLASH_PAGESIZE 0x800 // 2048 bytes
#define SAVEAREA_MAX 5 // 5 calibration slots#define SAVE_CONFIG_SIZE 0x00000800 // 2 KB config#define SAVE_PROP_CONFIG_SIZE 0x00001800 // 6 KB per propertySTM32F303xC Flash Layout
| Address Range | Size | Content |
|---|---|---|
0x08000000 - 0x0801FFFF | 128 KB | Firmware code |
0x08020000 - 0x08023FFF | 16 KB | Property slot 0 |
0x08024000 - 0x08027FFF | 16 KB | Property slot 1 |
0x08028000 - 0x0802BFFF | 16 KB | Property slot 2 |
0x0802C000 - 0x0802FFFF | 16 KB | Property slot 3 |
0x08030000 - 0x08033FFF | 16 KB | Property slot 4 |
0x08034000 - 0x08037FFF | 16 KB | Property slot 5 |
0x08038000 - 0x0803BFFF | 16 KB | Property slot 6 |
0x0803C000 - 0x0803FFFF | 16 KB | Configuration |
Constants:
#define FLASH_START_ADDRESS 0x08000000#define FLASH_TOTAL_SIZE (256*1024) // 262144 bytes#define FLASH_PAGESIZE 0x800 // 2048 bytes
#define SAVEAREA_MAX 7 // 7 calibration slots#define SAVE_CONFIG_SIZE 0x00000800 // 2 KB config#define SAVE_PROP_CONFIG_SIZE 0x00004000 // 16 KB per propertyAddress Calculation
Section titled “Address Calculation”The save area starts at the end of flash:
// Total save area size#define SAVE_FULL_AREA_SIZE (SAVE_CONFIG_SIZE + SAVEAREA_MAX * SAVE_PROP_CONFIG_SIZE)
// Configuration address (at very end)#define SAVE_CONFIG_ADDR (FLASH_START_ADDRESS + FLASH_TOTAL_SIZE - SAVE_CONFIG_SIZE)
// Properties start address (before config)#define SAVE_PROP_CONFIG_ADDR (FLASH_START_ADDRESS + FLASH_TOTAL_SIZE - SAVE_FULL_AREA_SIZE)F072 Calculations
Section titled “F072 Calculations”SAVE_FULL_AREA_SIZE = 0x800 + 5 * 0x1800 = 0x7800 (30 KB)SAVE_CONFIG_ADDR = 0x08000000 + 0x20000 - 0x800 = 0x0801F800SAVE_PROP_CONFIG_ADDR = 0x08000000 + 0x20000 - 0x7800 = 0x08018800F303 Calculations
Section titled “F303 Calculations”SAVE_FULL_AREA_SIZE = 0x800 + 7 * 0x4000 = 0x1C800 (114 KB)SAVE_CONFIG_ADDR = 0x08000000 + 0x40000 - 0x800 = 0x0803F800SAVE_PROP_CONFIG_ADDR = 0x08000000 + 0x40000 - 0x1C800 = 0x08023800properties_t Storage
Section titled “properties_t Storage”Each calibration slot stores a complete properties_t structure.
Structure Size
Section titled “Structure Size”| Target | SWEEP_POINTS_MAX | _cal_data size | Total size |
|---|---|---|---|
| F072 | 101 | 4,040 bytes | ~5 KB |
| F303 | 401 | 16,040 bytes | ~17 KB |
Calibration Data Layout
Section titled “Calibration Data Layout”float _cal_data[CAL_TYPE_COUNT][SWEEP_POINTS_MAX][2];| Cal Type | Index | Description |
|---|---|---|
| CAL_LOAD | 0 | 50 ohm load measurement |
| CAL_OPEN | 1 | Open circuit measurement |
| CAL_SHORT | 2 | Short circuit measurement |
| CAL_THRU | 3 | Through connection measurement |
| CAL_ISOLN | 4 | Isolation measurement |
Each entry stores complex data: [0] = real, [1] = imaginary.
config_t Storage
Section titled “config_t Storage”Configuration is stored in a single 2 KB area.
Structure Contents
Section titled “Structure Contents”| Field | Size | Description |
|---|---|---|
magic | 4 | CONFIG_MAGIC (0x434f4e56) |
_harmonic_freq_threshold | 4 | Harmonic mode threshold |
_IF_freq | 4 | IF frequency offset |
_touch_cal[4] | 8 | Touch calibration corners |
_vna_mode | 2 | Mode flags |
_dac_value | 2 | DAC output value |
_vbat_offset | 2 | Battery voltage offset |
_bandwidth | 2 | Default bandwidth setting |
_lever_mode | 1 | Lever control mode |
_brightness | 1 | LCD brightness (F303) |
_lcd_palette[32] | 64 | Color palette |
_serial_speed | 4 | USART baud rate |
_xtal_freq | 4 | TCXO frequency |
_measure_r | 4 | Reference impedance |
_band_mode | 1 | Band selection |
_reserved[3] | 3 | Reserved |
checksum | 4 | Data integrity check |
Magic Numbers
Section titled “Magic Numbers”#define CONFIG_MAGIC 0x434f4e56 // "CONV" - Config#define PROPERTIES_MAGIC 0x434f4e54 // "CONT" - PropertiesWhen loading data:
- Check magic value matches expected
- Verify checksum
- If either fails, use defaults
Flash Operations
Section titled “Flash Operations”Writing Data
Section titled “Writing Data”Flash memory requires erasing before writing. The erase granularity is one page (2 KB).
// Erase pages at addressvoid flash_erase_pages(uint32_t page_address, uint32_t size);
// Write data (must be erased first)void flash_program_half_word_buffer(uint16_t* dst, uint16_t *data, uint16_t size);Save Sequence
Section titled “Save Sequence”- Calculate checksum of data
- Erase required flash pages
- Write data in 16-bit half-words
- Verify write completed
Recall Sequence
Section titled “Recall Sequence”- Read magic value
- If magic matches, verify checksum
- Copy data to RAM structure
- If verification fails, return error
Save/Recall Commands
Section titled “Save/Recall Commands”Shell Commands
Section titled “Shell Commands”| Command | Action |
|---|---|
save <n> | Save to slot n (0-4 or 0-6) |
recall <n> | Load from slot n |
saveconfig | Save configuration |
clearconfig | Reset configuration |
Menu Access
Section titled “Menu Access”Save: CAL > SAVE > slot number
Recall: CAL > RECALL > slot number
Linker Script Configuration
Section titled “Linker Script Configuration”The linker script reserves flash for storage.
F072 (STM32F072xB.ld)
Section titled “F072 (STM32F072xB.ld)”MEMORY{ flash0 : org = 0x08000000, len = 112K /* Firmware */ flash7 : org = 0x0801C000, len = 16K /* Reserved for storage */ ...}F303 (STM32F303xC.ld)
Section titled “F303 (STM32F303xC.ld)”MEMORY{ flash0 : org = 0x08000000, len = 128K /* Firmware */ flash7 : org = 0x08020000, len = 128K /* Reserved for storage */ ...}Data Recovery
Section titled “Data Recovery”If configuration becomes corrupted:
- From menu:
CONFIG>EXPERT SETTINGS>CLEAR CONFIG - From shell:
clearconfigcommand - Hardware reset: Hold BOOT0 during power-on, reflash firmware
Flash Wear Considerations
Section titled “Flash Wear Considerations”STM32 flash has limited write cycles (~10,000 per page).
Best practices:
- Avoid excessive saves during development
- Use
saveconfigsparingly - Calibration rarely changes, so wear is minimal
- If flash fails, the page may become read-only