Skip to content

Erase last page of program memory range - #100

Open
rob-lake wants to merge 2 commits into
bessman:mainfrom
rob-lake:fix-erase-last-page
Open

rob-lake wants to merge 2 commits into
bessman:mainfrom
rob-lake:fix-erase-last-page

Conversation

@rob-lake

Copy link
Copy Markdown

Fixes #99.

erase() built page boundaries with range(start, end, erase_size) and erased each consecutive pair. range excludes end, so the final page (end - erase_size, end) was never erased, although flash() still writes to it.

Changes:

  • Iterate over page start addresses and erase (page_start, page_start + erase_size) for each one, so all N pages in [start, end) are erased. total_pages is now N, so the progress bar is correct.
  • The BadAddress workaround still erases (page_start - erase_size, end), the same range as before.
  • Raise ValueError up front if the range is not a multiple of erase_size, the same check erase_flash makes. Before, a trailing partial page was silently skipped.
  • Remove the pairwise backport, which is no longer used.

Tests:

  • New unit tests for erase() (with erase_flash and print_progress monkeypatched): all pages are erased including the last, the number of erase commands equals the number of pages, progress ends at 100 %, a misaligned range is rejected, and the BadAddress workaround still covers the range through end. All of them fail on current main.
  • The three test_cli[...] recordings now include the extra ERASE_FLASH command for page 0x2A000 and its SUCCESS response. I don't have the test device, so I spliced these in by hand rather than re-recording them. The bytes follow the recorded response to the previous page's erase, but you may want to re-record with pytest --record -k test_cli.

Local results: pytest 23 passed, and black, isort and mypy --strict are clean. ruff check . shows 7 findings with ruff 0.17.1 (CPY001 on every module and RUF036 in main), and current main shows the same 7.

Note: tox -e test runs pytest --replay, but pytest-reserial 0.6 dropped --replay (replay is now the default), so that command fails with a fresh install. I ran coverage run -m pytest instead and left tox.ini alone.

🤖 Generated with Claude Code

`erase` built page boundaries with `range(start, end, erase_size)` and
erased each consecutive pair. Since `range` excludes `end`, the final
pair `(end - erase_size, end)` was never produced, so the last page of
the program memory range was left unerased but still written to.

Iterate over page start addresses instead, so that every page in
`[start, end)` is erased. Reject ranges which are not a multiple of the
erase size up front, as `erase_flash` does.

The test_cli recordings are updated with the additional erase command
and its SUCCESS response for the final page.

This branch has not been deployed

No deployments
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.

Last page of program memory range is never erased

1 participant