diff --git a/examples/flashFormatter/flashFormatter.ino b/examples/flashFormatter/flashFormatter.ino index 8eeba84..4683a56 100644 --- a/examples/flashFormatter/flashFormatter.ino +++ b/examples/flashFormatter/flashFormatter.ino @@ -16,11 +16,59 @@ void setup() { Serial.begin(9600); while(!Serial); - if(!flashFormatter.checkandFormatPartition()){ - Serial.println("Failed to format partition"); - } else { - Serial.println("Partition formatted successfully"); + /* WARNING! Running this sketch all the content of the QSPI flash may be erased. + * The sketch will check if the QSPI flash is formatted with an ArduinoCloud + * compatible partitioning. Otherwise, it will format the QSPI flash with the + * default scheme. + * + * If you want to keep the content of the QSPI flash, do not run this sketch. + * + * ArduinoCloud compatible partitioning consist of: + * - 1st partition: WiFi firmware and certificates + * - 2nd partition: OTA data. Minimum size 5MB. + * - 3rd partition: Key Value Store data. Minimum size 1MB. + */ + + Serial.println("\nWARNING! Running this sketch all the content of the QSPI flash may be erased."); + Serial.println("Do you want to proceed? Y/[n]"); + + if (true == waitResponse()) { + if(!flashFormatter.checkAndFormatPartition()){ + Serial.println("Failed to check / format flash"); + } else { + Serial.println("Flash checked / formatted successfully"); + } } + else { + Serial.println("Operation canceled"); + } + + Serial.println("It's now safe to reboot or disconnect your board."); } void loop() { } + +bool waitResponse() { + bool confirmation = false; + bool proceed = false; + while (confirmation == false) { + if (Serial.available()) { + char choice = Serial.read(); + switch (choice) { + case 'y': + case 'Y': + confirmation = true; + proceed = true; + break; + case 'n': + case 'N': + confirmation = true; + proceed = false; + break; + default: + continue; + } + } + } + return proceed; +} diff --git a/src/flashFormatter/FlashFormatterBase.h b/src/flashFormatter/FlashFormatterBase.h index 5cc21d4..f8f83be 100644 --- a/src/flashFormatter/FlashFormatterBase.h +++ b/src/flashFormatter/FlashFormatterBase.h @@ -11,7 +11,7 @@ class FlashFormatterClass { public: virtual ~FlashFormatterClass() = default; - virtual bool checkandFormatPartition() { + virtual bool checkAndFormatPartition() { if(checkPartition()){ return true; } diff --git a/src/flashFormatter/H7FlashFormatter.cpp b/src/flashFormatter/H7FlashFormatter.cpp index 1c48887..005d95c 100644 --- a/src/flashFormatter/H7FlashFormatter.cpp +++ b/src/flashFormatter/H7FlashFormatter.cpp @@ -58,9 +58,19 @@ bool MBEDH7FlashFormatter::checkPartition() bool MBEDH7FlashFormatter::formatPartition() { _root->erase(0x0, _root->get_erase_size()); + /* Default partitioning of OPTA boards includes a 4th partition for PLC ide runtime + * This partition is not used in the context of ArduinoCloud and is not needed, + * but we try to preserve the default partitioning for compatibility. + */ +#if defined(ARDUINO_OPTA) + mbed::MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1024 * 1024); + mbed::MBRBlockDevice::partition(_root, 2, 0x0B, 1024 * 1024, 6 * 1024 * 1024); + mbed::MBRBlockDevice::partition(_root, 3, 0x0B, 6 * 1024 * 1024, 7 * 1024 * 1024); +#else mbed::MBRBlockDevice::partition(_root, 1, 0x0B, 0, 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); +#endif if(_ota_data_fs.mount(&_ota_data) != 0) { if(_ota_data_fs.reformat(&_ota_data) != 0) {