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