Skip to content

Clean only the named target, and drop dead Spektrum RPM code - #11909

Open
Raffi1202 wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
Raffi1202:chore/build-and-dead-code
Open

Raffi1202 wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
Raffi1202:chore/build-and-dead-code

Conversation

@Raffi1202

@Raffi1202 Raffi1202 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Problem

#6135 (stronnag): after make MATEKF405 WINGFC MATEKF722, running make clean_MATEKF405 removed the hex files of all three targets, and the following make MATEKF722 was a full rebuild instead of a no-op. #11298 (error414): getMotorAveragePeriod() in src/main/telemetry/srxl.c carries RPM code under USE_ESC_SENSOR_TELEMETRY / USE_DSHOT_TELEMETRY that calls getEscSensorData(ESC_SENSOR_COMBINED); none of these exist in INAV, the block was copied from Betaflight. Fixes #6135, fixes #11298.

Cause

cmake/stm32.cmake:444-446 on maintenance-10.x defines clean_<name> as COMMAND ${generator_cmd} clean with WORKING_DIRECTORY ${CMAKE_BINARY_DIR}, i.e. the generator's global clean; <name> is never used. The same block sits in cmake/at32.cmake:434-436, cmake/rp2350.cmake:430-432 and cmake/sitl.cmake:175-177.
src/main/telemetry/srxl.c:187-221: the two guards are defined nowhere in the tree, so only the #else branch (line 220, return SPEKTRUM_RPM_UNUSED;) was ever compiled. getEscSensorData() at line 192 does not exist; INAV has escSensorGetData() / getEscTelemetry() (src/main/sensors/esc_sensor.h:48-49).

Change

Adds add_clean_target() to cmake/main.cmake and the script cmake/clean_target.cmake, run with cmake -P so it is generator-independent. stm32, at32, rp2350 and sitl call it with their executables and output files (hex/bin/uf2/exe, plus bootloader and combined hex where built); the helper adds each executable's binary, map file, the target's generated settings files and the *.o / *.obj / *.d files under CMakeFiles/<exe>.dir, keeping the directory so the Makefile generator's build.make survives. stm32.cmake now also captures main_bin_filename. srxl.c drops the two dead branches, MICROSEC_PER_MINUTE, SPEKTRUM_MIN_RPM, SPEKTRUM_MAX_RPM and the sensors/esc_sensor.h include; getMotorAveragePeriod() still returns SPEKTRUM_RPM_UNUSED to srxlFrameRpm().

Test

Not run on hardware or in a local build. Cause verified by reading the lines above on maintenance-10.x; The upstream "Build firmware" run for 119a245 is awaiting approval: https://github.com/iNavFlight/inav/actions/runs/34513105859. CI configures with -G Ninja only and never invokes a clean_<target>, so a green build confirms configure and compile, not the clean itself.

Flash / RAM

Not measured yet. The upstream firmware CI has not been released for this PR, so no size report exists.

Docs

No documentation change needed: docs/development/Building in Linux.md:148-157 already describes make clean_MATEKF405 as cleaning a single target; this change makes that description true.

Raphael Hunziker added 2 commits September 10, 2026 20:08
clean_<target> ran the generator clean in the build directory, so it wiped
every target instead of the one that was named. Remove the artefacts of that
target instead: its binary, map file, object files, generated settings and
the hex/bin files built from it.

Neither "make clean" nor "ninja clean" can be limited to a single target, so
the paths are removed by a small cmake script. That keeps the behaviour
identical for the Makefile and the Ninja generator. The object directory
itself is kept, because the Makefile generator stores the build rules of the
target (build.make, DependInfo.cmake, ...) next to the object files and
without them the next build fails until cmake is run again.

at32, rp2350 and sitl carried the same code and now share add_clean_target()
with stm32.

Fixes iNavFlight#6135
getMotorAveragePeriod() was guarded by USE_ESC_SENSOR_TELEMETRY and
USE_DSHOT_TELEMETRY. Neither of them exists in INAV, so only the #else
branch was ever compiled. The guarded code also calls getEscSensorData(),
a Betaflight API; INAV has escSensorGetData() and getEscTelemetry().

The function stays, srxlFrameRpm() still calls it and reports the RPM field
as unused. Only the branches go, together with the defines and the
esc_sensor.h include that nothing else used.

Fixes iNavFlight#11298
@Raffi1202
Raffi1202 marked this pull request as ready for review September 11, 2026 15:49
@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

Copy link
Copy Markdown

PR Summary by Qodo

Scope clean targets and remove dead Spektrum RPM telemetry code

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

Grey Divider

AI Description

• Restricts clean_ to artifacts belonging only to the named firmware target.
• Centralizes generator-independent cleanup across STM32, AT32, RP2350, and SITL builds.
• Removes unreachable Spektrum SRXL RPM telemetry branches referencing unsupported APIs.
Diagram

graph TD
  PLAT["Platform targets"] -->|"registers"| HELPER["Clean helper"] -->|"passes paths"| SCRIPT["Cleanup script"] -->|"removes outputs"| ART["Target artifacts"]
  SRXL["SRXL telemetry"] -->|"emits"| RPM["Unused RPM marker"]
Loading
High-Level Assessment

The centralized CMake-script approach is appropriate because generator-native clean targets are global, generator-specific implementations would duplicate logic, and deleting complete object directories would break subsequent Makefile builds. Preserving build metadata while removing compiler outputs provides consistent behavior across supported generators; Makefile and Ninja CI should confirm artifact coverage.

Files changed (7) +84 / -103

Bug fix (6) +83 / -62
at32.cmakeScope AT32 cleanup to target-specific artifacts +9/-15

Scope AT32 cleanup to target-specific artifacts

• Replaces the generator-wide clean command with the shared cleanup helper. Main and optional bootloader executables, HEX/BIN outputs, and the combined image are registered for removal.

cmake/at32.cmake

clean_target.cmakeAdd generator-independent artifact cleanup script +26/-0

Add generator-independent artifact cleanup script

• Adds a build-time CMake script that removes explicit files and recursively deletes only '.o', '.obj', and '.d' compiler outputs. Object directories and generator-owned build metadata remain intact for subsequent Makefile builds.

cmake/clean_target.cmake

main.cmakeCentralize named-target cleanup registration +34/-0

Centralize named-target cleanup registration

• Adds 'add_clean_target()' to collect firmware outputs, map files, generated settings, and object directories. The helper creates an excluded custom target that invokes the shared cleanup script without depending on Make or Ninja commands.

cmake/main.cmake

rp2350.cmakeAdopt scoped cleanup for RP2350 targets +3/-16

Adopt scoped cleanup for RP2350 targets

• Replaces global generator cleanup with the shared helper, registering the executable and its HEX, BIN, and UF2 outputs.

cmake/rp2350.cmake

sitl.cmakeAdopt scoped cleanup for SITL targets +1/-16

Adopt scoped cleanup for SITL targets

• Routes SITL clean targets through the shared helper and limits removal to the selected executable and output file.

cmake/sitl.cmake

stm32.cmakeScope STM32 cleanup and include binary outputs +10/-15

Scope STM32 cleanup and include binary outputs

• Captures the main BIN filename and registers main firmware artifacts with the shared cleanup helper. Bootloader, bootloader-compatible, and combined outputs are included only when that target configuration produces them.

cmake/stm32.cmake

Refactor (1) +1 / -41
srxl.cRemove unreachable Spektrum RPM telemetry branches +1/-41

Remove unreachable Spektrum RPM telemetry branches

• Removes unused ESC sensor dependencies, RPM conversion constants, and branches guarded by unsupported feature macros. The still-used period function now directly returns the SRXL unused-RPM sentinel.

src/main/telemetry/srxl.c

@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 switch off images and animations for a plain-text comment

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@sensei-hacker sensei-hacker added this to the 10.0 milestone Sep 20, 2026
@b14ckyy b14ckyy linked an issue Sep 22, 2026 that may be closed by this pull request
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.

[cmake] make clean_TARGET cleans all targets

2 participants