Skip to content

Build SITL and RP2350 with their flash size, and fail the build when a target has none - #12282

Open
sensei-hacker wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
sensei-hacker:sitl-mcu-flash-size-10x
Open

sensei-hacker wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
sensei-hacker:sitl-mcu-flash-size-10x

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

This is the maintenance-10.x version of #12281 (release/9.1). It also fixes RP2350.

Problem

target/common.h turns features on and off with #if (MCU_FLASH_SIZE > 512) and #if (MCU_FLASH_SIZE <= 512). Two targets on this branch don't define MCU_FLASH_SIZE in time:

  • SITL defines MCU_FLASH_SIZE 2048 in target.h, but platform.h includes target/common.h first, so the define comes too late.
  • RP2350 only has TARGET_FLASH_SIZE 4096, which nothing reads.

The preprocessor treats an undefined macro as 0, so both have been built as 512 KB boards, with no warning.

  • SITL was missing CLI help text, auto transition, SIM telemetry, 34 channels, FFPV VTX, SUMD and SmartPort master, and had Spektrum serial RX removed. Its target.h already re-enables mixer profiles, geozones and MAVLink by hand, which are workarounds for this same problem.
  • RP2350 was missing all of the above, plus MAVLink, a second mixer profile and geozones.

Changes

  • cmake: passes MCU_FLASH_SIZE for SITL (2048) and RP2350 (4096), the same way it does for every STM32 and AT32 MCU. The two definitions that had no effect are removed from target.h.
  • target/common.h: now fails with #error when MCU_FLASH_SIZE is not defined, so a target can no longer be built as a 512 KB board by accident.
  • target/common_post.h: turns off USE_HOTT_TEXTMODE on any target without USE_TELEMETRY_HOTT, because text mode is part of HoTT telemetry. SITL and RP2350 both turn off HoTT telemetry, so once they had their real flash size they got text mode without it, and the link failed.
  • Unit tests: src/test/unit/platform.h defines MCU_FLASH_SIZE 512. That keeps the feature set the unit tests were already built with.

RP2350 reviewers: this turns on the >512 KB feature set for RP2350. The build uses about 135 KB of the 520 KB RAM (.data + .bss) and about 600 KB of the 4 MB flash. MAX_MIXER_PROFILE_COUNT goes from 1 to 2, which changes the mixer profile parameter group, so settings saved on an RP2350 board may be reset to defaults after updating.

Testing

  • Builds: SITL, MATEKF411 (512 KB), MATEKF722, MATEKH743, NEUTRONRCF435MINI and RP2350_PICO (including the .uf2) all build. None of the logs show an overflow.
  • Unit tests: make check passes 635 of 635.
  • Running SITL: CLI help now prints each command's description, for example aux - configure modes. The build without this change prints only the command names.
  • Missing size: preprocessing target/common.h without MCU_FLASH_SIZE stops at the new #error.
  • Not tested on hardware: RP2350_PICO has only been built. It has not run on a board.

…a target has none

common.h turns features on and off by MCU_FLASH_SIZE. SITL defined it
in target.h, which platform.h includes after common.h, and RP2350 only
had an unused TARGET_FLASH_SIZE. The preprocessor reads an undefined
macro as 0, so both were built as 512 KB boards: SITL had no CLI help
text, 34 channels, MAVLink or auto transition. cmake now passes
MCU_FLASH_SIZE for SITL (2048) and RP2350 (4096), as it does for every
other MCU, and common.h stops the build if a target has none. The unit
tests keep the 512 KB feature set they were built with.

With the flash size right, SITL and RP2350 get USE_HOTT_TEXTMODE but
not HoTT telemetry, which text mode is part of; HoTT text mode is now
dropped for any target without HoTT telemetry.
@sensei-hacker sensei-hacker added this to the 10.0 milestone Dec 6, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Build SITL and RP2350 with their flash size; fail build when missing

🐞 Bug fix ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• SITL and RP2350 now define MCU_FLASH_SIZE, enabling their full feature sets.
• common.h fails the build with #error when a target does not define MCU_FLASH_SIZE.
• HoTT text mode is disabled on any target without HoTT telemetry.
Merge Risk 🟢 Low

Blast radius 🔴 High 💥 4 capabilities

  • 4 affected capabilities span independent functional scopes: RP2350 flight-controller firmware integration, RP2350 flight-controller telemetry integration, SITL flight simulation integration, SITL telemetry integration.
  • The changed CMake definition feeds the shared target feature-selection rules for the RP2350 firmware build; this is one end-to-end firmware configuration behavior rather than separate capabilities for CMake and the header.
  • The SITL CMake definition independently controls the shared target feature-selection branch for simulator builds, producing a distinct simulation capability from the RP2350 firmware artifact.
  • The rule governs the HoTT text-mode portion of the RP2350 telemetry integration.
  • The target explicitly disables HoTT telemetry, so the changed combination is not reachable in the current target configuration.
  • The rule independently governs the HoTT text-mode portion of the SITL integration.
  • SITL target configuration explicitly disables HoTT telemetry, so the changed text-mode-only combination is not reachable there.
Sources

cmake/sitl.cmake[92-94]

set(SITL_DEFINITIONS
    SITL_BUILD
    MCU_FLASH_SIZE=2048

src/main/target/common.h[20-23]

// The preprocessor reads an undefined MCU_FLASH_SIZE as 0, which would quietly build a target as a 512 KB board
#ifndef MCU_FLASH_SIZE
#error "MCU_FLASH_SIZE (KiB) must be defined by the MCU's cmake file"
#endif

src/main/target/common_post.h[33-36]

// HoTT text mode is part of HoTT telemetry
#if !defined(USE_TELEMETRY_HOTT)
# undef USE_HOTT_TEXTMODE
#endif

src/main/target/RP2350_PICO/target.h[137-140]

#undef USE_MSP_OVER_TELEMETRY
#undef USE_TELEMETRY_FRSKY_HUB
#undef USE_TELEMETRY_HOTT
#undef USE_TELEMETRY_SMARTPORT

src/main/target/SITL/target.h[110-113]

#undef USE_MSP_OVER_TELEMETRY
#undef USE_TELEMETRY_FRSKY_HUB
#undef USE_TELEMETRY_HOTT
#undef USE_TELEMETRY_SMARTPORT
Behavioral complexity 🟢 Low 🧩 Straightforward

  • Before, target builds could obtain flash size from target headers or silently behave as 512 KiB when the macro was absent.
  • After, CMake supplies explicit values and common.h rejects omission.
  • The new correctness condition is that each target's CMake definition must match its supported flash capacity; the threshold rule itself is direct.
Sources

cmake/sitl.cmake[92-94]

set(SITL_DEFINITIONS
    SITL_BUILD
    MCU_FLASH_SIZE=2048

src/main/target/common.h[20-23]

// The preprocessor reads an undefined MCU_FLASH_SIZE as 0, which would quietly build a target as a 512 KB board
#ifndef MCU_FLASH_SIZE
#error "MCU_FLASH_SIZE (KiB) must be defined by the MCU's cmake file"
#endif
Potential damage 🟡 Medium 🩹 Recoverable

  • If the value or its use is wrong, optional telemetry, receiver, mixer, GPS-related, or similar firmware features can be omitted, or the expanded image can fail to build.
  • Correcting the definition and rebuilding restores the affected artifact; no persistent state or external effect is implicated.
  • A corrected rebuild restores the compile-time feature set; a firmware deployment using the wrong artifact would require redeployment.
Sources

src/main/target/common.h[20-23]

// The preprocessor reads an undefined MCU_FLASH_SIZE as 0, which would quietly build a target as a 512 KB board
#ifndef MCU_FLASH_SIZE
#error "MCU_FLASH_SIZE (KiB) must be defined by the MCU's cmake file"
#endif
Assessed commit 199c926
Diagram

graph TD
  A["cmake sitl.cmake / rp2350.cmake"] --> B["MCU_FLASH_SIZE define"] --> C["common.h #error guard"] --> D["common.h feature gates"] --> E["common_post.h HoTT text mode"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Define MCU_FLASH_SIZE in target.h before including common.h
  • ➕ Keeps the value next to the other target settings
  • ➕ No cmake change needed
  • ➖ Depends on include order, which already broke SITL once
  • ➖ Inconsistent with the STM32 and AT32 pattern
  • ➖ Silent 512 KB fallback remains unless a guard is added anyway

Recommendation: Keep the cmake-level definition with the #error guard. It matches how every STM32 and AT32 MCU already gets its flash size, and the guard turns a silent 512 KB fallback into a build failure. Moving the define into each target.h would only work if it came before the common.h include, which is the ordering bug that caused this PR, so it stays fragile.

Files changed (7) +13 / -4

Enhancement (1) +5 / -0
common.hFail build when MCU_FLASH_SIZE is undefined +5/-0

Fail build when MCU_FLASH_SIZE is undefined

• Adds an #ifndef guard that raises #error if MCU_FLASH_SIZE is missing, so a target cannot silently build as a 512 KB board.

src/main/target/common.h

Bug fix (1) +5 / -0
common_post.hDisable HoTT text mode without HoTT telemetry +5/-0

Disable HoTT text mode without HoTT telemetry

• Undefines USE_HOTT_TEXTMODE when USE_TELEMETRY_HOTT is not defined, because text mode depends on HoTT telemetry. This fixes the link failure on SITL and RP2350.

src/main/target/common_post.h

Tests (1) +1 / -0
platform.hSet MCU_FLASH_SIZE 512 for unit tests +1/-0

Set MCU_FLASH_SIZE 512 for unit tests

• Defines MCU_FLASH_SIZE 512 before common.h in the unit test platform header, so the tests keep the 512 KB feature set they already used.

src/test/unit/platform.h

Other (4) +2 / -4
rp2350.cmakePass MCU_FLASH_SIZE=4096 to RP2350 build +1/-0

Pass MCU_FLASH_SIZE=4096 to RP2350 build

• Adds MCU_FLASH_SIZE=4096 to RP2350_DEFINITIONS so common.h selects the >512 KB feature set for RP2350.

cmake/rp2350.cmake

sitl.cmakePass MCU_FLASH_SIZE=2048 to SITL build +1/-0

Pass MCU_FLASH_SIZE=2048 to SITL build

• Adds MCU_FLASH_SIZE=2048 to SITL_DEFINITIONS so SITL gets its full feature set on the command line, before any header is read.

cmake/sitl.cmake

target.hRemove unused TARGET_FLASH_SIZE define +0/-2

Remove unused TARGET_FLASH_SIZE define

• Deletes TARGET_FLASH_SIZE 4096, which nothing read. The flash size now comes from cmake.

src/main/target/RP2350_PICO/target.h

target.hRemove ineffective MCU_FLASH_SIZE define +0/-2

Remove ineffective MCU_FLASH_SIZE define

• Deletes the MCU_FLASH_SIZE 2048 define, which came after common.h and had no effect. The cmake definition replaces it.

src/main/target/SITL/target.h

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant