diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index 8d2b537dc..01b336f2a 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -3,7 +3,7 @@ #include "LittleFileSystem.h" #include "FATFileSystem.h" -#ifndef CORE_CM7 +#ifndef CORE_CM7 #error Format QSPI flash by uploading the sketch to the M7 core instead of the M4 core. #endif @@ -11,7 +11,8 @@ QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); mbed::MBRBlockDevice wifi_data(&root, 1); mbed::MBRBlockDevice ota_data(&root, 2); -mbed::MBRBlockDevice user_data(&root, 3); +mbed::MBRBlockDevice kvstore_data(&root, 3); +mbed::MBRBlockDevice user_data(&root, 4); mbed::FATFileSystem wifi_data_fs("wlan"); mbed::FATFileSystem ota_data_fs("fs"); mbed::FileSystem * user_data_fs; @@ -47,11 +48,13 @@ void setup() { Serial.println("Available partition schemes:"); Serial.println("\nPartition scheme 1"); Serial.println("Partition 1: WiFi firmware and certificates 1MB"); - Serial.println("Partition 2: OTA and user data 13MB"); + Serial.println("Partition 2: OTA and user data 12MB"); + Serial.println("Partition 3: Provisioning KVStore 1MB"); Serial.println("\nPartition scheme 2"); Serial.println("Partition 1: WiFi firmware and certificates 1MB"); Serial.println("Partition 2: OTA 5MB"); - Serial.println("Partition 3: User data 8MB"), + Serial.println("Partition 3: Provisioning KVStore 1MB"); + Serial.println("Partition 4: User data 7MB"), Serial.println("\nDo you want to use partition scheme 1? Y/[n]"); Serial.println("If No, partition scheme 2 will be used."); bool default_scheme = waitResponse(); @@ -60,25 +63,48 @@ void setup() { Serial.println("Do you want to proceed? Y/[n]"); if (true == waitResponse()) { + if (root.init() != QSPIF_BD_ERROR_OK) { + Serial.println(F("Error: QSPI init failure.")); + return; + } + + root.erase(0x0, root.get_erase_size()); + mbed::MBRBlockDevice::partition(&root, 1, 0x0B, 0, 1024 * 1024); if(default_scheme) { - mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 14 * 1024 * 1024, 14 * 1024 * 1024); - mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 14 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 13 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 13 * 1024 * 1024, 14 * 1024 * 1024); // use space from 15.5MB to 16 MB for another fw, memory mapped } else { mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 6 * 1024 * 1024); - mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 6 * 1024 * 1024, 14 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 6* 1024 * 1024, 7 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 4, 0x0B, 7 * 1024 * 1024, 14 * 1024 * 1024); // use space from 15.5MB to 16 MB for another fw, memory mapped } - int err = wifi_data_fs.reformat(&wifi_data); - if (err) { + bool reformat = true; + + if(!wifi_data_fs.mount(&wifi_data)) { + Serial.println("\nPartition 1 already contains a filesystem, do you want to reformat it? Y/[n]"); + wifi_data_fs.unmount(); + + reformat = waitResponse(); + } + + if (reformat && wifi_data_fs.reformat(&wifi_data)) { Serial.println("Error formatting WiFi partition"); return; } - - err = ota_data_fs.reformat(&ota_data); - if (err) { + + reformat = true; + if(!ota_data_fs.mount(&ota_data)) { + Serial.println("\nPartition 2 already contains a filesystem, do you want to reformat it? Y/[n]"); + ota_data_fs.unmount(); + + reformat = waitResponse(); + } + + if (reformat && ota_data_fs.reformat(&ota_data)) { Serial.println("Error formatting OTA partition"); return; } @@ -95,8 +121,15 @@ void setup() { user_data_fs = new mbed::FATFileSystem("user"); } - err = user_data_fs->reformat(&user_data); - if (err) { + reformat = true; + if(!user_data_fs->mount(&user_data)) { + Serial.println("\nPartition 3 already contains a filesystem, do you want to reformat it? Y/[n]"); + user_data_fs->unmount(); + + reformat = waitResponse(); + } + + if (reformat && user_data_fs->reformat(&user_data)) { Serial.println("Error formatting user partition"); return; }