|
| 1 | +/* |
| 2 | + Portenta C33 - QSPI Flash format |
| 3 | +
|
| 4 | + The sketch formats the board QSPI flash as follow: |
| 5 | +
|
| 6 | + * Partition 1 5MB: used for network certificates and OTA |
| 7 | + * Partition 2 11MB: general purpose |
| 8 | +
|
| 9 | + This example code is in the public domain. |
| 10 | +*/ |
| 11 | + |
| 12 | +#include "BlockDevice.h" |
| 13 | +#include "MBRBlockDevice.h" |
| 14 | +#include "LittleFileSystem.h" |
| 15 | +#include "FATFileSystem.h" |
| 16 | + |
| 17 | +BlockDevice* root = BlockDevice::get_default_instance(); |
| 18 | +MBRBlockDevice sys_bd(root, 1); |
| 19 | +MBRBlockDevice user_bd(root, 2); |
| 20 | +FATFileSystem sys_fs("sys"); |
| 21 | +FileSystem * user_data_fs; |
| 22 | + |
| 23 | +bool waitResponse() { |
| 24 | + bool confirmation = false; |
| 25 | + while (confirmation == false) { |
| 26 | + if (Serial.available()) { |
| 27 | + char choice = Serial.read(); |
| 28 | + switch (choice) { |
| 29 | + case 'y': |
| 30 | + case 'Y': |
| 31 | + confirmation = true; |
| 32 | + return true; |
| 33 | + break; |
| 34 | + case 'n': |
| 35 | + case 'N': |
| 36 | + confirmation = true; |
| 37 | + return false; |
| 38 | + break; |
| 39 | + default: |
| 40 | + continue; |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +void setup() { |
| 47 | + |
| 48 | + Serial.begin(115200); |
| 49 | + while (!Serial); |
| 50 | + |
| 51 | + Serial.println("\nWARNING! Running the sketch all the content of the QSPI flash will be erased."); |
| 52 | + Serial.println("Do you want to proceed? Y/[n]"); |
| 53 | + |
| 54 | + if (true == waitResponse()) { |
| 55 | + MBRBlockDevice::partition(root, 1, 0x0B, 0, 5 * 1024 * 1024); |
| 56 | + MBRBlockDevice::partition(root, 2, 0x0B, 5 * 1024 * 1024, 16 * 1024 * 1024); |
| 57 | + |
| 58 | + int err = sys_fs.reformat(&sys_bd); |
| 59 | + if (err) { |
| 60 | + Serial.println("Error formatting sys partition"); |
| 61 | + } |
| 62 | + |
| 63 | + Serial.println("\nDo you want to use LittleFS to format user data partition? Y/[n]"); |
| 64 | + Serial.println("If No, FatFS will be used to format user partition."); |
| 65 | + |
| 66 | + if (true == waitResponse()) { |
| 67 | + Serial.println("Formatting user partition with LittleFS."); |
| 68 | + user_data_fs = new LittleFileSystem("user"); |
| 69 | + } else { |
| 70 | + Serial.println("Formatting user partition with FatFS."); |
| 71 | + user_data_fs = new FATFileSystem("user"); |
| 72 | + } |
| 73 | + |
| 74 | + err = user_data_fs->reformat(&user_bd); |
| 75 | + if (err) { |
| 76 | + Serial.println("Error formatting user partition"); |
| 77 | + } |
| 78 | + |
| 79 | + Serial.println("\nQSPI Flash formatted!"); |
| 80 | + } |
| 81 | + |
| 82 | + Serial.println("It's now safe to reboot or disconnect your board."); |
| 83 | +} |
| 84 | + |
| 85 | +void loop() { |
| 86 | + |
| 87 | +} |
0 commit comments