1
- #include " QSPIFlashBlockDevice.h"
1
+ /*
2
+ Portenta C33 - Certificate uploader
3
+
4
+ The sketch uploads and saves network certificates on the system
5
+ partition of the QSPI flash
6
+
7
+ This example code is in the public domain.
8
+ */
9
+
10
+ #include " BlockDevice.h"
11
+ #include " MBRBlockDevice.h"
2
12
#include " FATFileSystem.h"
3
13
#include " certificates.h"
4
14
5
- QSPIFlashBlockDevice root (PIN_QSPI_CLK, PIN_QSPI_SS, PIN_QSPI_D0, PIN_QSPI_D1, PIN_QSPI_D2, PIN_QSPI_D3);
6
- FATFileSystem root_fs (" wlan" );
15
+ BlockDevice* root = BlockDevice::get_default_instance();
16
+ MBRBlockDevice sys_bd (root, 1 );
17
+ FATFileSystem sys_fs (" sys" );
7
18
8
19
long getFileSize (FILE *fp) {
9
20
fseek (fp, 0 , SEEK_END);
@@ -32,33 +43,33 @@ void setup() {
32
43
Serial.begin (115200 );
33
44
while (!Serial);
34
45
35
- int err = root_fs .mount (&root );
46
+ int err = sys_fs .mount (&sys_bd );
36
47
if (err) {
37
48
// Reformat if we can't mount the filesystem
38
49
// this should only happen on the first boot
39
50
Serial.println (" No filesystem containing the WiFi firmware was found." );
40
51
Serial.println (" Usually that means that the WiFi firmware has not been installed yet"
41
52
" or was overwritten with another firmware.\n " );
42
53
Serial.println (" Formatting the filsystem to install the firmware and certificates...\n " );
43
- err = root_fs .reformat (&root );
54
+ err = sys_fs .reformat (&sys_bd );
44
55
}
45
56
46
57
DIR *dir;
47
58
struct dirent *ent;
48
59
49
- if ((dir = opendir (" /wlan " )) != NULL ) {
60
+ if ((dir = opendir (" /sys " )) != NULL ) {
50
61
/* print all the files and directories within directory */
51
62
while ((ent = readdir (dir)) != NULL ) {
52
63
Serial.println (" Searching for WiFi firmware file " + String (ent->d_name ) + " ..." );
53
- String fullname = " /wlan /" + String (ent->d_name );
54
- if (fullname == " /wlan /cacert.pem" ) {
64
+ String fullname = " /sys /" + String (ent->d_name );
65
+ if (fullname == " /sys /cacert.pem" ) {
55
66
Serial.println (" A WiFi firmware is already installed. "
56
67
" Do you want to install the firmware anyway? Y/[n]" );
57
68
while (1 ) {
58
69
if (Serial.available ()) {
59
70
int c = Serial.read ();
60
71
if (c == ' Y' || c == ' y' ) {
61
- root_fs .reformat (&root );
72
+ sys_fs .reformat (&sys_bd );
62
73
break ;
63
74
}
64
75
if (c == ' N' || c == ' n' ) {
@@ -76,7 +87,7 @@ void setup() {
76
87
77
88
int chunck_size = 128 ;
78
89
int byte_count = 0 ;
79
- FILE* fp = fopen (" /wlan /cacert.pem" , " wb" );
90
+ FILE* fp = fopen (" /sys /cacert.pem" , " wb" );
80
91
81
92
Serial.println (" Flashing certificates" );
82
93
printProgress (byte_count, cacert_pem_len, 10 , true );
@@ -93,7 +104,7 @@ void setup() {
93
104
}
94
105
fclose (fp);
95
106
96
- fp = fopen (" /wlan /cacert.pem" , " rb" );
107
+ fp = fopen (" /sys /cacert.pem" , " rb" );
97
108
char buffer[128 ];
98
109
int ret = fread (buffer, 1 , 128 , fp);
99
110
Serial.write (buffer, ret);
0 commit comments