Skip to content

Commit 55a50dc

Browse files
authored
Flash formatter fix
* Fix default partitioning for OPTA boards * FlashFormatter: add warning about sketch execution * FlashFormatterClass: fix function naming
1 parent 2e2facc commit 55a50dc

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

examples/flashFormatter/flashFormatter.ino

+52-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,59 @@ void setup() {
1616
Serial.begin(9600);
1717
while(!Serial);
1818

19-
if(!flashFormatter.checkandFormatPartition()){
20-
Serial.println("Failed to format partition");
21-
} else {
22-
Serial.println("Partition formatted successfully");
19+
/* WARNING! Running this sketch all the content of the QSPI flash may be erased.
20+
* The sketch will check if the QSPI flash is formatted with an ArduinoCloud
21+
* compatible partitioning. Otherwise, it will format the QSPI flash with the
22+
* default scheme.
23+
*
24+
* If you want to keep the content of the QSPI flash, do not run this sketch.
25+
*
26+
* ArduinoCloud compatible partitioning consist of:
27+
* - 1st partition: WiFi firmware and certificates
28+
* - 2nd partition: OTA data. Minimum size 5MB.
29+
* - 3rd partition: Key Value Store data. Minimum size 1MB.
30+
*/
31+
32+
Serial.println("\nWARNING! Running this sketch all the content of the QSPI flash may be erased.");
33+
Serial.println("Do you want to proceed? Y/[n]");
34+
35+
if (true == waitResponse()) {
36+
if(!flashFormatter.checkAndFormatPartition()){
37+
Serial.println("Failed to check / format flash");
38+
} else {
39+
Serial.println("Flash checked / formatted successfully");
40+
}
2341
}
42+
else {
43+
Serial.println("Operation canceled");
44+
}
45+
46+
Serial.println("It's now safe to reboot or disconnect your board.");
2447
}
2548

2649
void loop() { }
50+
51+
bool waitResponse() {
52+
bool confirmation = false;
53+
bool proceed = false;
54+
while (confirmation == false) {
55+
if (Serial.available()) {
56+
char choice = Serial.read();
57+
switch (choice) {
58+
case 'y':
59+
case 'Y':
60+
confirmation = true;
61+
proceed = true;
62+
break;
63+
case 'n':
64+
case 'N':
65+
confirmation = true;
66+
proceed = false;
67+
break;
68+
default:
69+
continue;
70+
}
71+
}
72+
}
73+
return proceed;
74+
}

src/flashFormatter/FlashFormatterBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class FlashFormatterClass {
1212
public:
1313
virtual ~FlashFormatterClass() = default;
14-
virtual bool checkandFormatPartition() {
14+
virtual bool checkAndFormatPartition() {
1515
if(checkPartition()){
1616
return true;
1717
}

src/flashFormatter/H7FlashFormatter.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,19 @@ bool MBEDH7FlashFormatter::checkPartition()
5858

5959
bool MBEDH7FlashFormatter::formatPartition() {
6060
_root->erase(0x0, _root->get_erase_size());
61+
/* Default partitioning of OPTA boards includes a 4th partition for PLC ide runtime
62+
* This partition is not used in the context of ArduinoCloud and is not needed,
63+
* but we try to preserve the default partitioning for compatibility.
64+
*/
65+
#if defined(ARDUINO_OPTA)
66+
mbed::MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1024 * 1024);
67+
mbed::MBRBlockDevice::partition(_root, 2, 0x0B, 1024 * 1024, 6 * 1024 * 1024);
68+
mbed::MBRBlockDevice::partition(_root, 3, 0x0B, 6 * 1024 * 1024, 7 * 1024 * 1024);
69+
#else
6170
mbed::MBRBlockDevice::partition(_root, 1, 0x0B, 0, 1024 * 1024);
6271
mbed::MBRBlockDevice::partition(_root, 2, 0x0B, 1024 * 1024, 13 * 1024 * 1024);
6372
mbed::MBRBlockDevice::partition(_root, 3, 0x0B, 13 * 1024 * 1024, 14 * 1024 * 1024);
73+
#endif
6474

6575
if(_ota_data_fs.mount(&_ota_data) != 0) {
6676
if(_ota_data_fs.reformat(&_ota_data) != 0) {

0 commit comments

Comments
 (0)