Thanks to visit codestin.com
Credit goes to github.com

Skip to content

QSPIFormat: add function to restore memory mapped firmware #1062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();

Expand All @@ -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();
}
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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;

Expand Down Expand Up @@ -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() {

}