Use small memory space for KVStore

Hello everyone,

I work along @ladislas and we try to use KVStore to store some data into the flash of the MCU.

Our long term goal is to store the number of reboots and other small relevant information by placing them into a KVStore located between the bootloader and the application.

The first step is to use KVStore using a small memory space, but by running examples given in the KVStore global API [Link] and TDBStore [Link], we cannot go below a space usage of 512KB which represents 2 sectors of our MCU, a STM32F769BI [Source]. Needless to say, this is too much for some bytes of data.

A first approach is to set the size directly in mbed_app.json.
However the examples only work when the internal_size property is equal to 0x80000, but not below.

"target.features_add": ["STORAGE"],
"storage.storage_type": "TDB_INTERNAL",
"storage_tdb_internal.internal_size": "0x80000",
"storage_tdb_internal.internal_base_address": "0x08040000"

Another approach is to use SlicingBlockDevice and to define sizes directly in code.
But again, if the block device given to TDBStore is less than 2 sectors, the example doesn’t work anymore.

auto main() -> int
{
	auto flash_sectors_bd = FlashIAPBlockDevice {0x08040000, 0x80000};
	mbed::SlicingBlockDevice sliced_bd[2] = {SlicingBlockDevice(&flash_sectors_bd, 0x00000, 0x40000),
											 SlicingBlockDevice(&flash_sectors_bd, 0x40000, 0x80000)};

	auto tdb = TDBStore {&sliced_bd[0]};

	kv_store_api_example(&tdb, "tdb"); // Does not work
	
	return 0;
}

N.B. The kv_store_api_example function above is the same as the one given in example [Link].

The examples perfectly work in both of the above approaches when the size is 512KB, but fails when it is smaller.

How can we configure the KVStore for a smaller functional size (less than 2 sectors)?

Thank you a lot!

Yann

2 Likes