diff --git a/features/storage/kvstore/conf/kv_config.cpp b/features/storage/kvstore/conf/kv_config.cpp index bdb681962c..cfa2f96cb2 100644 --- a/features/storage/kvstore/conf/kv_config.cpp +++ b/features/storage/kvstore/conf/kv_config.cpp @@ -180,13 +180,19 @@ int _calculate_blocksize_match_tdbstore(BlockDevice *bd) { bd_size_t size = bd->size(); bd_size_t erase_size = bd->get_erase_size(); + bd_size_t page_size = bd->get_program_size(); bd_size_t number_of_sector = size / erase_size; - - if (number_of_sector < 2) { + bd_size_t number_of_page = size / page_size; + if (number_of_sector < TDBStore::STORE_SECTORS) { tr_warning("KV Config: There are less than two sectors - TDBStore will not work."); return -1; } + if (number_of_page < TDBStore::STORE_PAGES) { + tr_warning("KV Config: There are less than ten pages sectors - TDBStore will not work."); + return -1; + } + if (number_of_sector % 2 != 0) { tr_warning("KV Config: Number of sectors is not an even number. Consider changing the BlockDevice size"); @@ -586,9 +592,9 @@ int _create_internal_tdb(BlockDevice **internal_bd, KVStore **internal_tdb, bd_s return MBED_ERROR_FAILED_OPERATION ; } - //Check if TDBStore has at least 2 sector. + //Check if TDBStore has at least 2 sectors or 10 pages. if (_calculate_blocksize_match_tdbstore(*internal_bd) != MBED_SUCCESS) { - tr_error("KV Config: Can not create TDBStore with less then 2 sector."); + tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages."); return MBED_ERROR_INVALID_ARGUMENT; } @@ -754,9 +760,9 @@ int _storage_config_tdb_external_common() return MBED_ERROR_FAILED_OPERATION ; } - //Check that there is at least 2 sector for the external TDBStore + //Check that there is at least 2 sectors for the external TDBStore if (_calculate_blocksize_match_tdbstore(kvstore_config.external_bd) != MBED_SUCCESS) { - tr_error("KV Config: Can not create TDBStore with less then 2 sector."); + tr_error("KV Config: Can not create TDBStore with less then 2 sectors or 10 pages."); return MBED_ERROR_INVALID_SIZE; } diff --git a/features/storage/kvstore/tdbstore/TDBStore.cpp b/features/storage/kvstore/tdbstore/TDBStore.cpp index 877f5da56c..f367283887 100644 --- a/features/storage/kvstore/tdbstore/TDBStore.cpp +++ b/features/storage/kvstore/tdbstore/TDBStore.cpp @@ -1438,11 +1438,6 @@ int TDBStore::get_default_flash_addresses(bd_addr_t *start_address, bd_size_t *s return MBED_ERROR_INITIALIZATION_FAILED; } - // Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger) - // For each area: must be a minimum of 1 page of reserved and 2 pages for master record - static const int STORE_SECTORS = 2; - static const int STORE_PAGES = 10; - // Let's work from end of the flash backwards bd_addr_t curr_addr = flash.get_flash_start() + flash.get_flash_size(); bd_size_t sector_space = 0; diff --git a/features/storage/kvstore/tdbstore/TDBStore.h b/features/storage/kvstore/tdbstore/TDBStore.h index f5c1b8be90..519891d923 100644 --- a/features/storage/kvstore/tdbstore/TDBStore.h +++ b/features/storage/kvstore/tdbstore/TDBStore.h @@ -37,6 +37,13 @@ public: static const uint32_t RESERVED_AREA_SIZE = 64; + // Use the last 2 sectors or 10 pages of flash for the TDBStore by default (whichever is larger) + // For each area: must be a minimum of 1 page of reserved and 2 pages for master record + /** Minimum number of internal flash sectors required for TDBStore */ + static const int STORE_SECTORS = 2; + /** Minimum number of internal flash pages required for TDBStore */ + static const int STORE_PAGES = 10; + /** * @brief Class constructor *