From 9a837b88642db0b460989ae8fdb8b6bbbffa029d Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 12 May 2025 21:25:09 +0200 Subject: [PATCH 1/3] QSPIFormat: add more feedback about full erase --- libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index b3ecbf222..74f4fcf71 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -79,8 +79,11 @@ void setup() { } Serial.println("Do you want to perform a full erase of the QSPI flash before proceeding? Y/[n]"); + Serial.println("Note: Full flash erase can take up to one minute."); if (true == waitResponse()) { + Serial.println("Full erase started, please wait..."); root->erase(0x0, root->size()); + Serial.println("Full erase completed."); } else { // Erase only the first sector containing the MBR root->erase(0x0, root->get_erase_size()); From 750849f2b2f7814dbad56a629ab34c359ea9efa7 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 12 May 2025 21:25:41 +0200 Subject: [PATCH 2/3] QSPIFormat: style fixes --- .../STM32H747_System/examples/QSPIFormat/QSPIFormat.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index 74f4fcf71..900b9c6ba 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -96,7 +96,7 @@ void setup() { // use space from 15.5MB to 16 MB for another fw, memory mapped bool reformat = true; - if(!wifi_data_fs.mount(&wifi_data)) { + 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(); @@ -119,7 +119,7 @@ void setup() { } reformat = true; - if(!ota_data_fs.mount(&ota_data)) { + 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(); @@ -143,7 +143,7 @@ void setup() { } reformat = true; - if(!user_data_fs->mount(&user_data)) { + if (!user_data_fs->mount(&user_data)) { Serial.println("\nPartition 4 already contains a filesystem, do you want to reformat it? Y/[n]"); user_data_fs->unmount(); From 6d9c5d9eccf62b6b0c8ce51b7e87c2397ab0ba53 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 12 May 2025 22:18:24 +0200 Subject: [PATCH 3/3] QSPIFormat: add function to restore memory mapped firmware --- .../examples/QSPIFormat/QSPIFormat.ino | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index 900b9c6ba..a30762511 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -80,7 +80,8 @@ void setup() { Serial.println("Do you want to perform a full erase of the QSPI flash before proceeding? Y/[n]"); Serial.println("Note: Full flash erase can take up to one minute."); - if (true == waitResponse()) { + bool fullErase = waitResponse(); + if (fullErase == true) { Serial.println("Full erase started, please wait..."); root->erase(0x0, root->size()); Serial.println("Full erase completed."); @@ -109,7 +110,7 @@ void setup() { } bool restore = true; - if (reformat) { + if (reformat || fullErase) { Serial.println("\nDo you want to restore the WiFi firmware and certificates? Y/[n]"); restore = waitResponse(); } @@ -118,6 +119,10 @@ void setup() { flashWiFiFirmwareAndCertificates(); } + if (fullErase && restore) { + flashWiFiFirmwareMapped(); + } + 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]"); @@ -161,10 +166,11 @@ void setup() { Serial.println("It's now safe to reboot or disconnect your board."); } +const uint32_t file_size = 421098; +extern const unsigned char wifi_firmware_image_data[]; + void flashWiFiFirmwareAndCertificates() { - extern const unsigned char wifi_firmware_image_data[]; FILE* fp = fopen("/wlan/4343WA1.BIN", "wb"); - const uint32_t file_size = 421098; uint32_t chunck_size = 1024; uint32_t byte_count = 0; @@ -203,6 +209,26 @@ void flashWiFiFirmwareAndCertificates() { fclose(fp); } +void flashWiFiFirmwareMapped() { + uint32_t chunck_size = 1024; + uint32_t byte_count = 0; + const uint32_t offset = 15 * 1024 * 1024 + 1024 * 512; + + Serial.println("Flashing memory mapped WiFi firmware"); + printProgress(byte_count, file_size, 10, true); + while (byte_count < file_size) { + if (byte_count + chunck_size > file_size) + chunck_size = file_size - byte_count; + int ret = root->program(wifi_firmware_image_data, offset + byte_count, chunck_size); + if (ret != 0) { + Serial.println("Error writing memory mapped firmware"); + break; + } + byte_count += chunck_size; + printProgress(byte_count, file_size, 10, false); + } +} + void loop() { }