Skip to content

Commit 355ee1a

Browse files
committed
Add Firmware Upload/Download With MSC
Current running firmware is available as file inside the MSC Disk. To update the firmware on the ESP, just copy a regular firmware bin into the drive
1 parent befcb49 commit 355ee1a

File tree

11 files changed

+835
-4
lines changed

11 files changed

+835
-4
lines changed

cores/esp32/esp32-hal-tinyusb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ static void usb_device_task(void *param) {
559559
/*
560560
* PUBLIC API
561561
* */
562-
static const char *tinyusb_interface_names[USB_INTERFACE_MAX] = {"CDC", "MSC", "DFU", "HID", "VENDOR", "MIDI", "CUSTOM"};
562+
static const char *tinyusb_interface_names[USB_INTERFACE_MAX] = {"MSC", "DFU", "HID", "VENDOR", "CDC", "MIDI", "CUSTOM"};
563563

564564
static bool tinyusb_is_initialized = false;
565565

cores/esp32/esp32-hal-tinyusb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ void usb_persist_restart(restart_type_t mode);
8282

8383
// The following definitions and functions are to be used only by the drivers
8484
typedef enum {
85-
USB_INTERFACE_CDC,
8685
USB_INTERFACE_MSC,
8786
USB_INTERFACE_DFU,
8887
USB_INTERFACE_HID,
8988
USB_INTERFACE_VENDOR,
89+
USB_INTERFACE_CDC,
9090
USB_INTERFACE_MIDI,
9191
USB_INTERFACE_CUSTOM,
9292
USB_INTERFACE_MAX

libraries/USB/examples/FirmwareMSC/.skip.esp32c3

Whitespace-only changes.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include "USB.h"
2+
#include "FirmwareMSC.h"
3+
4+
FirmwareMSC MSC_Update;
5+
6+
#if ARDUINO_SERIAL_PORT
7+
#define HWSerial Serial0
8+
#define USBSerial Serial
9+
#else
10+
#define HWSerial Serial
11+
USBCDC USBSerial;
12+
#endif
13+
14+
static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data){
15+
if(event_base == ARDUINO_USB_EVENTS){
16+
arduino_usb_event_data_t * data = (arduino_usb_event_data_t*)event_data;
17+
switch (event_id){
18+
case ARDUINO_USB_STARTED_EVENT:
19+
HWSerial.println("USB PLUGGED");
20+
break;
21+
case ARDUINO_USB_STOPPED_EVENT:
22+
HWSerial.println("USB UNPLUGGED");
23+
break;
24+
case ARDUINO_USB_SUSPEND_EVENT:
25+
HWSerial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en);
26+
break;
27+
case ARDUINO_USB_RESUME_EVENT:
28+
HWSerial.println("USB RESUMED");
29+
break;
30+
31+
default:
32+
break;
33+
}
34+
} else if(event_base == ARDUINO_FIRMWARE_MSC_EVENTS){
35+
arduino_firmware_msc_event_data_t * data = (arduino_firmware_msc_event_data_t*)event_data;
36+
switch (event_id){
37+
case ARDUINO_FIRMWARE_MSC_START_EVENT:
38+
HWSerial.println("MSC Update Start");
39+
break;
40+
case ARDUINO_FIRMWARE_MSC_WRITE_EVENT:
41+
//HWSerial.printf("MSC Update Write %u bytes at offset %u\n", data->write.size, data->write.offset);
42+
HWSerial.print(".");
43+
break;
44+
case ARDUINO_FIRMWARE_MSC_END_EVENT:
45+
HWSerial.printf("\nMSC Update End: %u bytes\n", data->end.size);
46+
break;
47+
case ARDUINO_FIRMWARE_MSC_ERROR_EVENT:
48+
HWSerial.printf("MSC Update ERROR! Progress: %u bytes\n", data->error.size);
49+
break;
50+
case ARDUINO_FIRMWARE_MSC_POWER_EVENT:
51+
HWSerial.printf("MSC Update Power: power: %u, start: %u, eject: %u", data->power.power_condition, data->power.start, data->power.load_eject);
52+
break;
53+
54+
default:
55+
break;
56+
}
57+
}
58+
}
59+
60+
void setup() {
61+
HWSerial.begin(115200);
62+
HWSerial.setDebugOutput(true);
63+
64+
USB.onEvent(usbEventCallback);
65+
MSC_Update.onEvent(usbEventCallback);
66+
MSC_Update.begin();
67+
#if !ARDUINO_SERIAL_PORT
68+
USBSerial.begin();
69+
USB.begin();
70+
#endif
71+
}
72+
73+
void loop() {
74+
// put your main code here, to run repeatedly
75+
}

libraries/USB/examples/USBMSC/USBMSC.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define USBSerial Serial
77
#else
88
#define HWSerial Serial
9-
//USBCDC USBSerial; // Windows does not like it if both devices are on
9+
USBCDC USBSerial;
1010
#endif
1111

1212
USBMSC MSC;
@@ -184,7 +184,7 @@ void setup() {
184184
MSC.mediaPresent(true);
185185
MSC.begin(DISK_SECTOR_COUNT, DISK_SECTOR_SIZE);
186186
#if !ARDUINO_SERIAL_PORT
187-
//USBSerial.begin(); // Windows does not like it if both devices are on
187+
USBSerial.begin();
188188
USB.begin();
189189
#endif
190190
}

0 commit comments

Comments
 (0)