I used this sketch to create partitions 2, 3 and 4, leaving partition 1 (WiFi) untouched:
#include "QSPIFBlockDevice.h"
#include "MBRBlockDevice.h"
#include "FATFileSystem.h"
QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000);
mbed::MBRBlockDevice ota_data(&root, 2);
mbed::MBRBlockDevice user_data(&root, 3);
mbed::MBRBlockDevice tdb_data(&root, 4);
mbed::FATFileSystem ota_data_fs("fs");
mbed::FATFileSystem user_data_fs("user");
void setup() {
int err;
Serial.begin(115200);
while (!Serial);
mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1 * 1024 * 1024, 6 * 1024 * 1024);
mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 6 * 1024 * 1024, 10 * 1024 * 1024);
mbed::MBRBlockDevice::partition(&root, 4, 0x0B, 10 * 1024 * 1024, 14 * 1024 * 1024);
err = ota_data_fs.reformat(&ota_data);
if (err) {
Serial.println("Error formatting ota partition");
return;
}
err = user_data_fs.reformat(&user_data);
if (err) {
Serial.println("Error formatting user partition");
return;
}
Serial.println("It's now safe to reboot or disconnect your board.");
}
void loop() {
}
No, it's just the object created from the class. This is basically all you need to do once the tdb partition exists:
#include <QSPIFBlockDevice.h>
#include <MBRBlockDevice.h>
#include <TDBStore.h>
QSPIFBlockDevice root;
mbed::MBRBlockDevice tdb_data(&root, 4);
mbed::TDBStore config(&tdb_data);
const char tdb_WiFiSID[] = "WiFiSID";
char wifiSid[20];
void setup() {
config.init();
config.get(tdb_WiFiSID, &wifiSid, sizeof(wifiSid));
}
void loop() {
// put your main code here, to run repeatedly:
}
I use all fixed lengths. It's a bit wasteful but there's more space in the partition than I could ever need. I just use the null terminator in char [] to determine actual length.
One reason I went for tdb over kv was I couldn't (like yourself) work out where /kv/ was created. Each platform has its own implementation with the global api and the examples I'd seen suggested it was using the internal flash (on some boards anyway). I'd seen some posts of those using kv that had lost or corrupted data. I feared sketches were overwriting the /kv/. I may dig into the /kv/ implementation on the GIGA when I get the urge but tdb is ideal for me with this board.
p.s. If you add this to your sketch you can see the partitions on your PC when USB connected.
#include <PluggableUSBMSD.h>
USBMSD MassStorage(&root);