From ea25933097ff93be995aa6a20048850d85157b14 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Mon, 23 Sep 2024 14:03:08 +0200 Subject: [PATCH 1/5] erasing MBR table before creating a new partitioning scheme --- .../STM32H747_System/examples/QSPIFormat/QSPIFormat.ino | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index 8d2b537dc..a1f5cf50b 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -60,6 +60,13 @@ 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); From 12f765595bfe8f7b05133b16c2e576f1770038b8 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Mon, 23 Sep 2024 15:43:28 +0200 Subject: [PATCH 2/5] added an additional parition for provisioning in QSPIFormat sketch --- .../examples/QSPIFormat/QSPIFormat.ino | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index a1f5cf50b..13b62b2c2 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -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(); @@ -69,12 +72,14 @@ void setup() { 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); + mbed::MBRBlockDevice::partition(&root, 4, 0x0B, 14 * 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 } @@ -83,7 +88,7 @@ void setup() { Serial.println("Error formatting WiFi partition"); return; } - + err = ota_data_fs.reformat(&ota_data); if (err) { Serial.println("Error formatting OTA partition"); From 24b22ffc7d97ace339cbd3f1b0bfe147b31b36c8 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 12 Mar 2025 11:17:50 +0100 Subject: [PATCH 3/5] QSPIFormat: Added confirmation request before reformatting fs --- .../examples/QSPIFormat/QSPIFormat.ino | 34 +++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index 13b62b2c2..899557ed1 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -83,14 +83,29 @@ void setup() { // 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; } @@ -107,8 +122,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; } From 9e05f2be36eb832a91691b06cf0d34469d1c0203 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 12 Mar 2025 11:18:14 +0100 Subject: [PATCH 4/5] removed trailing spaces --- libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index 899557ed1..ee6ebb28e 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 From 345747c5fc5aef20e29b887a99d210913bc19c99 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Wed, 12 Mar 2025 15:17:12 +0100 Subject: [PATCH 5/5] fixup! added an additional parition for provisioning in QSPIFormat sketch --- libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index ee6ebb28e..01b336f2a 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -74,7 +74,6 @@ void setup() { if(default_scheme) { mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 13 * 1024 * 1024); mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 13 * 1024 * 1024, 14 * 1024 * 1024); - mbed::MBRBlockDevice::partition(&root, 4, 0x0B, 14 * 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);