Skip to content

Commit 1f062f2

Browse files
committed
Add example to boot M4 code from file + SDRAM
1 parent e93d792 commit 1f062f2

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "SDRAM.h"
2+
#include "QSPIFBlockDevice.h"
3+
#include "MBRBlockDevice.h"
4+
#include "FATFileSystem.h"
5+
#include "PluggableUSBMSD.h"
6+
7+
QSPIFBlockDevice root(PD_11, PD_12, PF_7, PD_13, PF_10, PG_6, QSPIF_POLARITY_MODE_1, 40000000);
8+
mbed::MBRBlockDevice ota_data(&root, 2);
9+
mbed::FATFileSystem ota_data_fs("fs");
10+
11+
void USBMSD::begin()
12+
{
13+
}
14+
15+
USBMSD MassStorage(&root);
16+
17+
long getFileSize(FILE *fp) {
18+
fseek(fp, 0, SEEK_END);
19+
int size = ftell(fp);
20+
fseek(fp, 0, SEEK_SET);
21+
22+
return size;
23+
}
24+
25+
void setup() {
26+
// put your setup code here, to run once:
27+
Serial.begin(115200);
28+
while (!Serial);
29+
30+
SDRAM.begin(0);
31+
32+
int err = ota_data_fs.mount(&ota_data);
33+
if (err) {
34+
Serial.println("Please run PortentaWiFiFirmwareUpdater once");
35+
while (1) {
36+
delay(10000);
37+
}
38+
}
39+
40+
// Copy M4 firmware to SDRAM
41+
FILE* fw = fopen("/fs/fw.bin", "r");
42+
if (fw == NULL) {
43+
Serial.println("Please copy a firmware for M4 core in the PORTENTA mass storage");
44+
Serial.println("When done, please unmount the mass storage and reset the board");
45+
MassStorage.begin();
46+
while (1) {
47+
delay(10000);
48+
}
49+
}
50+
fread((uint8_t*)CM4_BINARY_START, getFileSize(fw), 1, fw);
51+
fclose(fw);
52+
53+
bootM4();
54+
}
55+
56+
void loop() {
57+
// put your main code here, to run repeatedly:
58+
delay(10000);
59+
}

0 commit comments

Comments
 (0)