Skip to content

Commit 1ca5356

Browse files
author
David Saada
committed
In internal KVStore default configuration, give the app space to grow
1 parent 90fd6cd commit 1ca5356

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

features/storage/kvstore/conf/kv_config.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,27 @@ int _storage_config_TDB_INTERNAL()
547547
return MBED_ERROR_FAILED_OPERATION;
548548
}
549549
internal_start_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash.get_sector_size(FLASHIAP_APP_ROM_END_ADDR));
550+
551+
// Give the application a couple of spare sectors to grow (if there are such)
552+
bd_size_t spare_size_for_app = 0;
553+
bd_addr_t curr_addr = internal_start_address;
554+
bd_addr_t flash_end_address = flash.get_flash_start() + flash.get_flash_size();
555+
556+
int spare_sectors_for_app = 2;
557+
int min_sectors_for_storage = 2;
558+
for (int i = 0; i < spare_sectors_for_app + min_sectors_for_storage - 1; i++) {
559+
bd_size_t sector_size = flash.get_sector_size(curr_addr);
560+
curr_addr += sector_size;
561+
if (curr_addr >= flash_end_address) {
562+
spare_size_for_app = 0;
563+
break;
564+
}
565+
if (i < spare_sectors_for_app) {
566+
spare_size_for_app += sector_size;
567+
}
568+
}
569+
internal_start_address += spare_size_for_app;
570+
550571
flash.deinit();
551572
}
552573

0 commit comments

Comments
 (0)