Skip to content

Commit 2ece7f4

Browse files
committed
SFU: add USBMSD binding only if included explicitly
Since SFU is being used for OTA on IotCloud, every sketch used to pull in USBMSD and expose a 1MB FAT disk when connected. This patch fixed this beahviour, providing the hooks only if the user explicitly includes "PluggableUSBMSD.h" in the sketch (or in another library)
1 parent d18d04d commit 2ece7f4

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

libraries/SFU/src/SFU.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
#include "SFU.h"
22
#include "FlashIAPBlockDevice.h"
3-
#include "FATFileSystem.h"
3+
#if __has_include("PluggableUSBMSD.h")
44
#include "PluggableUSBMSD.h"
5+
#define ADD_USB_MSD
6+
#endif
57

68
const unsigned char SFU[0x10000] __attribute__ ((section(".second_stage_ota"), used)) = {
79
#include "rp2040.h"
810
};
911

1012
FlashIAPBlockDevice bd(XIP_BASE + 0xF00000, 0x100000);
1113

12-
void USBMSD::begin()
13-
{
14-
int err = getFileSystem().mount(&bd);
15-
if (err) {
16-
err = getFileSystem().reformat(&bd);
17-
}
18-
}
19-
20-
mbed::FATFileSystem& USBMSD::getFileSystem()
21-
{
14+
mbed::FATFileSystem& SFU::getFileSystem() {
2215
static mbed::FATFileSystem fs("ota");
2316
return fs;
2417
}
2518

26-
USBMSD MassStorage(&bd);
27-
2819
int SFU::begin() {
29-
MassStorage.begin();
20+
int err = getFileSystem().mount(&bd);
21+
if (err) {
22+
err = getFileSystem().reformat(&bd);
23+
}
3024
}
3125

3226
int SFU::download(const char* url) {
@@ -36,3 +30,19 @@ int SFU::download(const char* url) {
3630
int SFU::apply() {
3731
// No autoreboot
3832
}
33+
34+
#ifdef ADD_USB_MSD
35+
36+
void USBMSD::begin()
37+
{
38+
SFU::begin();
39+
}
40+
41+
mbed::FATFileSystem& USBMSD::getFileSystem()
42+
{
43+
return SFU::getFileSystem();
44+
}
45+
46+
USBMSD MassStorage(&bd);
47+
48+
#endif

libraries/SFU/src/SFU.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#pragma once
22

33
#include "WiFiNINA.h"
4+
#include "FATFileSystem.h"
45

56
class SFU {
67
public:
78
static int begin();
89
static int download(const char* url);
910
static int apply();
11+
static mbed::FATFileSystem& getFileSystem();
1012
};

0 commit comments

Comments
 (0)