Skip to content

Commit

Permalink
Fix flash wear leveling sector calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Diff-fusion committed Jan 2, 2025
1 parent 172c349 commit 3f0b5d3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ bool backing_store_init(void) {

// Work out how many sectors we want to use, working backwards from the end of the flash
flash_sector_t last_sector = desc->sectors_count - WEAR_LEVELING_EFL_OMIT_LAST_SECTOR_COUNT;

// skip sectors that are past the actual flash size
while (flashGetSectorOffset(flash, last_sector) >= flash_size) {
last_sector--;
}

for (flash_sector_t i = 0; i < last_sector; ++i) {
first_sector = last_sector - i - 1;
if (flashGetSectorOffset(flash, first_sector) >= flash_size) {
last_sector = first_sector;
continue;
}
counter += flashGetSectorSize(flash, first_sector);
if (counter >= (WEAR_LEVELING_BACKING_SIZE)) {
sector_count = last_sector - first_sector;
Expand Down

0 comments on commit 3f0b5d3

Please sign in to comment.