Skip to content

Commit ee435d5

Browse files
committed
Adding sketch for loading binary to the MKRMEM shield
1 parent 79a7f38 commit ee435d5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

libraries/SFU/examples/SFU_LoadBinary/Binary.h

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**************************************************************************************
2+
* INCLUDE
3+
**************************************************************************************/
4+
5+
#include <Arduino_MKRMEM.h>
6+
7+
/**************************************************************************************
8+
* CONSTANTS
9+
**************************************************************************************/
10+
11+
static uint8_t const BINARY[] =
12+
{
13+
#include "Binary.h"
14+
};
15+
16+
/**************************************************************************************
17+
* SETUP/LOOP
18+
**************************************************************************************/
19+
20+
void setup() {
21+
Serial.begin(9600);
22+
23+
unsigned long const start = millis();
24+
for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { };
25+
26+
flash.begin();
27+
28+
Serial.print("Mounting ... ");
29+
if(SPIFFS_OK != filesystem.mount()) {
30+
Serial.println("mount() failed with error code "); Serial.println(filesystem.err()); return;
31+
}
32+
Serial.println("OK");
33+
34+
35+
Serial.print("Checking ... ");
36+
if(SPIFFS_OK != filesystem.check()) {
37+
Serial.println("check() failed with error code "); Serial.println(filesystem.err()); return;
38+
}
39+
Serial.println("OK");
40+
41+
42+
Serial.print("Writing \"UPDATE.BIN\" ... ");
43+
File file = filesystem.open("UPDATE.BIN", CREATE | READ_WRITE| TRUNCATE);
44+
45+
int const bytes_to_write = sizeof(BINARY);
46+
int const bytes_written = file.write((void *)BINARY, bytes_to_write);
47+
48+
if(bytes_written != bytes_to_write) {
49+
Serial.println("write() failed with error code "); Serial.println(filesystem.err()); return;
50+
} else {
51+
Serial.print("OK (");
52+
Serial.print(bytes_written);
53+
Serial.println(" bytes written)");
54+
}
55+
56+
Serial.print("Unmounting ... ");
57+
filesystem.unmount();
58+
Serial.println("OK");
59+
}
60+
61+
void loop() {
62+
63+
}

0 commit comments

Comments
 (0)