Skip to content

steami: Add config zone in F103 internal flash gap#4

Merged
nedseb merged 3 commits into
release_letssteamfrom
feat/internal-config-zone
Mar 19, 2026
Merged

steami: Add config zone in F103 internal flash gap#4
nedseb merged 3 commits into
release_letssteamfrom
feat/internal-config-zone

Conversation

@nedseb
Copy link
Copy Markdown

@nedseb nedseb commented Mar 17, 2026

Summary

Closes #2

Adds 3 new I2C commands to read/write a 1 KB config zone stored in the STM32F103 internal flash (gap between bootloader and interface firmware at 0x0800BC00).

Command Code Payload Description
WRITE_CONFIG 0x30 offset(2) + len(1) + data(N) Write to config zone (read-modify-write)
READ_CONFIG 0x31 offset(2) Read 256 bytes from config zone
CLEAR_CONFIG 0x32 none Erase the entire 1 KB config zone

Key properties

  • Survives firmware updates: the gap is between bootloader (never touched) and interface (reflashed by user)
  • Survives clear_flash: data file erase does not affect the config zone
  • No USB crash risk: uses internal flash (not W25Q64 SPI), no bus contention with DAPLink VFS
  • Instant reads: config zone is memory-mapped, read is a simple memcpy
  • Atomic writes: erase + program in a single operation with shadow buffer to preserve existing data

Files changed

  • steami_config.c/.h — new: internal flash config zone driver
  • steami_i2c.c/.h — register new commands in is_command_valid() and get_argument_byte_number()
  • steami32.c — add task handlers and I2C command documentation

Use cases

  • Board revision number (for screen driver selection)
  • Board name (classroom identification)
  • Sensor calibration data (temperature, magnetometer, accelerometer)
  • Boot counter

Test plan

  • CLEAR_CONFIG erases zone (all 0xFF)
  • WRITE_CONFIG + READ_CONFIG round-trip
  • Write at arbitrary offset
  • Write preserves existing data (read-modify-write)
  • clear_flash does NOT erase config
  • Read second 256-byte page
  • Large write (28 bytes)
  • Multiple sequential writes
  • Existing flash operations (READ_SECTOR, WHO_AM_I) still work
  • USB stability after 10 write/read stress cycles

Add WRITE_CONFIG (0x30), READ_CONFIG (0x31) and CLEAR_CONFIG (0x32)
I2C commands that read/write a 1 KB config zone in the bootloader/IF
gap at 0x0800BC00. This area survives firmware updates and
clear_flash operations, suitable for board revision, name, and
sensor calibration data.
@nedseb nedseb self-assigned this Mar 17, 2026
@nedseb nedseb requested a review from Copilot March 17, 2026 12:34
@nedseb nedseb added the enhancement New feature or request label Mar 17, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an internal-flash “config zone” for the STeaMi STM32F103 interface firmware and exposes it over the existing I2C command protocol, using the 1KB BL/IF gap at 0x0800BC00.

Changes:

  • Introduces a new internal-flash config driver (steami_config_*) to read/write/erase a 1KB page.
  • Adds three new I2C commands (WRITE_CONFIG/READ_CONFIG/CLEAR_CONFIG) to the command enum, validation, and argument sizing.
  • Implements new task handlers and updates the I2C command documentation in steami32.c.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
source/board/steami/steami_i2c.h Adds new I2C command IDs for config operations.
source/board/steami/steami_i2c.c Registers new commands as valid and defines their fixed argument lengths.
source/board/steami/steami_config.h Defines config zone address/size and the public read/write/erase API.
source/board/steami/steami_config.c Implements internal flash read-modify-write and page erase for the config zone.
source/board/steami/steami32.c Wires new commands into the command handler/task loop and documents them.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread source/board/steami/steami32.c Outdated
Comment thread source/board/steami/steami32.c Outdated
Comment thread source/board/steami/steami_config.h Outdated
Comment thread source/board/steami/steami_config.h
- Document WRITE_CONFIG fixed 31-byte payload in command table.
- Reject WRITE_CONFIG when data_len exceeds payload (bad_parameter).
- Derive config zone address/size from daplink_addr.h macros.
- Add compile-time assert to prevent config/IF overlap.
@nedseb
Copy link
Copy Markdown
Author

nedseb commented Mar 18, 2026

All 4 review comments addressed in 9bc76dd:

  1. Command table — Updated WRITE_CONFIG to document fixed 31-byte payload (offset 2B + len 1B + data max 28B, zero-padded).

  2. Silent truncation — WRITE_CONFIG now rejects with bad_parameter error when data_len exceeds available payload instead of silently truncating.

  3. Hard-coded constantsSTEAMI_CONFIG_ADDR and STEAMI_CONFIG_SIZE now derived from daplink_addr.h macros (DAPLINK_ROM_BL_START + DAPLINK_ROM_BL_SIZE and DAPLINK_SECTOR_SIZE). Added _Static_assert to verify no overlap with interface firmware.

  4. Issue steami: Add config zone in F103 internal flash gap. #2 mismatch — Issue steami: Add config zone in F103 internal flash gap. #2 has been updated to reflect the internal flash implementation instead of W25Q64.

@nedseb
Copy link
Copy Markdown
Author

nedseb commented Mar 18, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9bc76ddd02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread source/board/steami/steami_config.h Outdated
@nedseb
Copy link
Copy Markdown
Author

nedseb commented Mar 19, 2026

Fixed in 76ace49. Replaced _Static_assert (C11) with COMPILER_ASSERT macro from compiler.h for C99 compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

steami: Add config zone in F103 internal flash gap.

2 participants