diff --git a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino index b3ecbf222..a30762511 100644 --- a/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino +++ b/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -79,8 +79,12 @@ void setup() { } Serial.println("Do you want to perform a full erase of the QSPI flash before proceeding? Y/[n]"); - if (true == waitResponse()) { + Serial.println("Note: Full flash erase can take up to one minute."); + bool fullErase = waitResponse(); + if (fullErase == true) { + 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()); @@ -93,7 +97,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(); @@ -106,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(); } @@ -115,8 +119,12 @@ void setup() { flashWiFiFirmwareAndCertificates(); } + if (fullErase && restore) { + flashWiFiFirmwareMapped(); + } + 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(); @@ -140,7 +148,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(); @@ -158,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; @@ -200,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() { }