Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3c959ab

Browse filesBrowse files
erasing MBR table before creating a new partitioning scheme
1 parent 53a89c3 commit 3c959ab
Copy full SHA for 3c959ab

File tree

1 file changed

+27
-0
lines changed
Filter options

1 file changed

+27
-0
lines changed

‎libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino

Copy file name to clipboardExpand all lines: libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ void setup() {
6060
Serial.println("Do you want to proceed? Y/[n]");
6161

6262
if (true == waitResponse()) {
63+
if (root.init() != QSPIF_BD_ERROR_OK) {
64+
Serial.println(F("Error: QSPI init failure."));
65+
return;
66+
}
67+
68+
const size_t pts = 512; // MBR partition table size = 512b
69+
const size_t erase_size = root.get_erase_size(0x0);
70+
71+
size_t remainder = pts % erase_size;
72+
size_t division = pts / erase_size;
73+
74+
uint8_t *buf = nullptr;
75+
76+
// save the data that exceeded the size of MBR partition table and write it back
77+
if(remainder != 0) {
78+
buf = (uint8_t*) malloc(erase_size - remainder);
79+
root.read(buf, division*erase_size, sizeof(buf));
80+
}
81+
82+
root.erase(0x0, erase_size*(division + remainder == 0? 0 : 1)); // clear the MBR partition table
83+
84+
if(remainder != 0) {
85+
root.program(buf, division*erase_size, sizeof(buf));
86+
free(buf);
87+
buf = nullptr;
88+
}
89+
6390
mbed::MBRBlockDevice::partition(&root, 1, 0x0B, 0, 1024 * 1024);
6491
if(default_scheme) {
6592
mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 14 * 1024 * 1024, 14 * 1024 * 1024);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.