Skip to content

fix: keep examples from persisting parameter changes - #14

Merged
X-F-R merged 2 commits into
mainfrom
fix/examples-ram-only
Oct 28, 2026
Merged

X-F-R merged 2 commits into
mainfrom
fix/examples-ram-only

Conversation

@X-F-R

@X-F-R X-F-R commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Keeps the examples from persisting or leaving behind parameter changes. 05_ff_tune no longer calls save_params(); 07_vel_jitter_trace restores the ff_mask it changes for the A/B run.

Changes

  • examples/05_ff_tune.cpp: remove save_params(); write FF parameters to RAM only. Update the docstring, output and examples/README.md.
  • examples/07_vel_jitter_trace.cpp: restore the original ff_mask on scope exit, including exceptions and early returns; update the docstring.

No other example calls a persistence API.

Testing

$ cmake -S . -B /tmp/litearm-cpp-full -DCMAKE_BUILD_TYPE=Release
$ cmake --build /tmp/litearm-cpp-full -j2
$ ctest --test-dir /tmp/litearm-cpp-full --output-on-failure
100% tests passed, 0 tests failed out of 29
1 skipped: test_protocol_sync (needs LITEARM_FW_DIR)

grep -rnE 'save_params|reset_factory|save_tool|model\(\)\.commit|CMD_PARAM_SAVE' examples/ returns only comments in 05_ff_tune.cpp; no calls.

Issues

None.

thetooler added 2 commits October 26, 2026 18:57
05_ff_tune.cpp called save_params() after writing FF parameters, which
persists them to flash irreversibly. Remove the call and state in the
docstring, output and README that the example only writes RAM.
07_vel_jitter_trace wrote ff_mask for the A/B run and only printed a
hint to restore it by hand. A RAM parameter change left behind changes
the next session's feedforward. Restore the original mask on scope
exit, including exceptions and early returns.
@yd-sl
yd-sl self-requested a review October 26, 2026 11:25
@X-F-R
X-F-R requested a review from cao-xiao-hao October 28, 2026 03:17

@cao-xiao-hao cao-xiao-hao left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved. Built and ran the suite on the PR head (207bc49):

$ cmake -S . -B /tmp/litearm-cpp-pr14 -DCMAKE_BUILD_TYPE=Release
$ cmake --build /tmp/litearm-cpp-pr14 -j4
$ ctest --test-dir /tmp/litearm-cpp-pr14 --output-on-failure
100% tests passed out of 29
1 skipped: test_protocol_sync (needs LITEARM_FW_DIR)

Checked:

  • 05_ff_tune no longer calls save_params(). grep -nE 'save_params|reset_factory|save_tool' over examples/ matches only the comments that explain why the example stays in RAM.
  • FfMaskRestore::remember() is called before set_ff_mask(), so a write that throws after the frame has already gone out is still restored. The destructor swallows restore failures, so it cannot mask the primary exception, and it runs on both early return and stack unwinding.
  • The guard is constructed after cart_supported() and before enable(), so every path that can write the mask is covered.
  • get_ff_mask() returns int (include/litearm/arm.hpp:417); the static_cast<uint32_t> is valid and the mask is not sign-extended.
  • examples/README.md now states the RAM-only behavior, matching the code.

The restore behavior has no regression test — there is no existing harness that runs the example scripts, only test_example_args for _common.cpp. Not blocking, but worth covering if such a harness is added.

@X-F-R
X-F-R merged commit d476d5c into main Oct 28, 2026
1 check passed
@X-F-R
X-F-R deleted the fix/examples-ram-only branch October 28, 2026 06:09
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.3.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released Shipped in a release label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants