Conversation
…into fix/eraseSectorTiming
Contributor
There was a problem hiding this comment.
Pull request overview
I read the AGENTS.md.
This PR aims to reduce SPI flash logging latency spikes by pre-erasing the next sector immediately after each buffer flush, so sector erase time can overlap with buffer fill time.
Changes:
- Add
preparedSectorNumber_tracking and pre-erase logic inDataSaverSPI::flushBuffer(). - Add a unit test asserting the next sector is erased before the write crosses a sector boundary.
- Reduce flakiness in
GroundLevelEstimatornoise test by increasing samples/epsilon.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/data_handling/DataSaverSPI.cpp |
Implements “pre-erase next sector after flush” behavior and tracks prepared sectors. |
include/data_handling/DataSaverSPI.h |
Adds preparedSectorNumber_ member and <limits> include. |
test/test_datasaver_spi/test_DataSaverSPI.cpp |
Adds a regression test for pre-erasing the next sector at the sector boundary. |
test/test_ground_level_estimator/main.cpp |
Increases sample count and tolerance to reduce test flakiness. |
.gitignore |
Ignores .codex. |
Mayday-01
approved these changes
Apr 3, 2026
Contributor
Mayday-01
left a comment
There was a problem hiding this comment.
I see nothing that breaks would break MARTHA or dynamically allocate resources. That said, I noticed on lines 36 and 54 of src/data_handling/DataSaverSPI.cpp that a repeated if structure occurs that could probably be a function in the DataSaverSPI.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Sector erasing in
DataSaverSPInow triggers after each flush to prep for the next flush. This eliminates the 50 ms latency spike caused by the sector erase blocking the buffer flush. As long as the 256 byte flush buffer isn't filled within 50 ms, the eraseSector can happen without causing latency spikes, otherwise this fixes still reduces the latency by no less than 10 ms.Summary of Changes
DataSaverSPItracks which sector has been preparedDataSaverSPIwill prep the next sector has soon as the buffer filling the previous sector is written rather than waiting for the first flush of the new sectorGroundLevelEstimatortest less flaky my increasing the epsilon and number of samplesMotivation
Testing
Check all that apply:
Checklist