Skip to content

Commit e73d35f

Browse files
committed
Rework USB selection
1 parent 333d0d4 commit e73d35f

File tree

9 files changed

+26
-22
lines changed

9 files changed

+26
-22
lines changed

boards.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
menu.UploadSpeed=Upload Speed
2+
menu.USBMode=USB Mode
23
menu.CDCOnBoot=USB CDC On Boot
34
menu.MSCOnBoot=USB Firmware MSC On Boot
45
menu.DFUOnBoot=USB DFU On Boot
@@ -43,6 +44,7 @@ esp32s3.build.core=esp32
4344
esp32s3.build.variant=esp32s3
4445
esp32s3.build.board=ESP32S3_DEV
4546

47+
esp32s3.build.usb_mode=1
4648
esp32s3.build.cdc_on_boot=0
4749
esp32s3.build.msc_on_boot=0
4850
esp32s3.build.dfu_on_boot=0
@@ -66,19 +68,24 @@ esp32s3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1
6668
esp32s3.menu.EventsCore.0=Core 0
6769
esp32s3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0
6870

71+
esp32s3.menu.USBMode.hwcdc=Hardware CDC and JTAG
72+
esp32s3.menu.USBMode.hwcdc.build.usb_mode=1
73+
esp32s3.menu.USBMode.default=USB-OTG
74+
esp32s3.menu.USBMode.default.build.usb_mode=0
75+
6976
esp32s3.menu.CDCOnBoot.default=Disabled
7077
esp32s3.menu.CDCOnBoot.default.build.cdc_on_boot=0
7178
esp32s3.menu.CDCOnBoot.cdc=Enabled
7279
esp32s3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1
7380

7481
esp32s3.menu.MSCOnBoot.default=Disabled
7582
esp32s3.menu.MSCOnBoot.default.build.msc_on_boot=0
76-
esp32s3.menu.MSCOnBoot.msc=Enabled
83+
esp32s3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode)
7784
esp32s3.menu.MSCOnBoot.msc.build.msc_on_boot=1
7885

7986
esp32s3.menu.DFUOnBoot.default=Disabled
8087
esp32s3.menu.DFUOnBoot.default.build.dfu_on_boot=0
81-
esp32s3.menu.DFUOnBoot.dfu=Enabled
88+
esp32s3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode)
8289
esp32s3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1
8390

8491
esp32s3.menu.UploadMode.default=UART0

cores/esp32/HWCDC.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ void HWCDC::begin(unsigned long baud)
167167
setRxBufferSize(256);//default if not preset
168168
setTxBufferSize(256);//default if not preset
169169

170-
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET);
170+
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
171+
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
171172
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET);
172173
if(!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK){
173174
isr_log_e("HW USB CDC failed to init interrupts");
@@ -179,7 +180,7 @@ void HWCDC::begin(unsigned long baud)
179180
void HWCDC::end()
180181
{
181182
//Disable tx/rx interrupt.
182-
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET);
183+
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
183184
esp_intr_free(intr_handle);
184185
intr_handle = NULL;
185186
if(tx_lock != NULL) {
@@ -379,7 +380,7 @@ void HWCDC::setDebugOutput(bool en)
379380
}
380381
}
381382

382-
#if ARDUINO_HW_CDC_ON_BOOT //Serial used for USB CDC
383+
#if ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE //Serial used for USB CDC
383384
HWCDC Serial;
384385
#else
385386
HWCDC USBSerial;

cores/esp32/HWCDC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class HWCDC: public Stream
9898

9999
};
100100

101-
#if ARDUINO_HW_CDC_ON_BOOT //Serial used for USB CDC
101+
#if ARDUINO_USB_CDC_ON_BOOT && ARDUINO_USB_MODE//Serial used for USB CDC
102102
extern HWCDC Serial;
103103
#else
104104
extern HWCDC USBSerial;

cores/esp32/HardwareSerial.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ void serialEvent2(void) {}
8080
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
8181
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
8282
HardwareSerial Serial0(0);
83-
#elif ARDUINO_HW_CDC_ON_BOOT
84-
HardwareSerial Serial0(0);
8583
#else
8684
HardwareSerial Serial(0);
8785
#endif
@@ -96,8 +94,6 @@ void serialEventRun(void)
9694
{
9795
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
9896
if(Serial0.available()) serialEvent();
99-
#elif ARDUINO_HW_CDC_ON_BOOT
100-
if(Serial0.available()) serialEvent();
10197
#else
10298
if(Serial.available()) serialEvent();
10399
#endif

cores/esp32/HardwareSerial.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ extern void serialEventRun(void) __attribute__((weak));
123123
#define ARDUINO_USB_CDC_ON_BOOT 0
124124
#endif
125125
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
126+
#if !ARDUINO_USB_MODE
126127
#include "USB.h"
127128
#include "USBCDC.h"
128-
extern HardwareSerial Serial0;
129-
#elif ARDUINO_HW_CDC_ON_BOOT
129+
#endif
130130
extern HardwareSerial Serial0;
131131
#else
132132
extern HardwareSerial Serial;

cores/esp32/USBCDC.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ USBCDC::operator bool() const
412412
return connected;
413413
}
414414

415-
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
415+
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE //Serial used for USB CDC
416416
USBCDC Serial(0);
417417
#endif
418418

cores/esp32/USBCDC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class USBCDC: public Stream
134134

135135
};
136136

137-
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
137+
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE //Serial used for USB CDC
138138
extern USBCDC Serial;
139139
#endif
140140

cores/esp32/main.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "freertos/task.h"
33
#include "esp_task_wdt.h"
44
#include "Arduino.h"
5-
#if (ARDUINO_USB_CDC_ON_BOOT|ARDUINO_USB_MSC_ON_BOOT|ARDUINO_USB_DFU_ON_BOOT)
5+
#if (ARDUINO_USB_CDC_ON_BOOT|ARDUINO_USB_MSC_ON_BOOT|ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE
66
#include "USB.h"
77
#if ARDUINO_USB_MSC_ON_BOOT
88
#include "FirmwareMSC.h"
@@ -54,16 +54,16 @@ void loopTask(void *pvParameters)
5454

5555
extern "C" void app_main()
5656
{
57-
#if ARDUINO_USB_CDC_ON_BOOT
57+
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
5858
Serial.begin();
5959
#endif
60-
#if ARDUINO_USB_MSC_ON_BOOT
60+
#if ARDUINO_USB_MSC_ON_BOOT && !ARDUINO_USB_MODE
6161
MSC_Update.begin();
6262
#endif
63-
#if ARDUINO_USB_DFU_ON_BOOT
63+
#if ARDUINO_USB_DFU_ON_BOOT && !ARDUINO_USB_MODE
6464
USB.enableDFU();
6565
#endif
66-
#if ARDUINO_USB_ON_BOOT
66+
#if ARDUINO_USB_ON_BOOT && !ARDUINO_USB_MODE
6767
USB.begin();
6868
#endif
6969
loopTaskWDTEnabled = false;

platform.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ compiler.cpp.flags.esp32s3=-mlongcalls -ffunction-sections -fdata-sections -Wno-
4646
compiler.S.flags.esp32s3=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c
4747
compiler.c.elf.flags.esp32s3=-T memory.ld -T sections.ld -T esp32s3.rom.ld -T esp32s3.rom.api.ld -T esp32s3.rom.libgcc.ld -T esp32s3.rom.newlib.ld -T esp32s3.rom.version.ld -T esp32s3.peripherals.ld -mlongcalls -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u ld_include_highint_hdl -u start_app -u start_app_other_cores -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy
4848
compiler.ar.flags.esp32s3=cr
49-
build.extra_flags.esp32s3=-DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUINO_USB_MSC_ON_BOOT={build.msc_on_boot} -DARDUINO_USB_DFU_ON_BOOT={build.dfu_on_boot}
49+
build.extra_flags.esp32s3=-DARDUINO_USB_MODE={build.usb_mode} -DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUINO_USB_MSC_ON_BOOT={build.msc_on_boot} -DARDUINO_USB_DFU_ON_BOOT={build.dfu_on_boot}
5050
#
5151
# ESP32S3 Support End
5252
#
@@ -61,7 +61,7 @@ compiler.cpp.flags.esp32s2=-mlongcalls -ffunction-sections -fdata-sections -Wno-
6161
compiler.S.flags.esp32s2=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c
6262
compiler.c.elf.flags.esp32s2=-T memory.ld -T sections.ld -T esp32s2.rom.ld -T esp32s2.rom.api.ld -T esp32s2.rom.libgcc.ld -T esp32s2.rom.newlib-funcs.ld -T esp32s2.rom.newlib-data.ld -T esp32s2.rom.spiflash.ld -T esp32s2.peripherals.ld -mlongcalls -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u ld_include_highint_hdl -u start_app -u __ubsan_include -Wl,--wrap=longjmp -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -u __cxa_guard_dummy
6363
compiler.ar.flags.esp32s2=cr
64-
build.extra_flags.esp32s2=-DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUINO_USB_MSC_ON_BOOT={build.msc_on_boot} -DARDUINO_USB_DFU_ON_BOOT={build.dfu_on_boot}
64+
build.extra_flags.esp32s2=-DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot} -DARDUINO_USB_MSC_ON_BOOT={build.msc_on_boot} -DARDUINO_USB_DFU_ON_BOOT={build.dfu_on_boot}
6565
#
6666
# ESP32S2 Support End
6767
#
@@ -76,7 +76,7 @@ compiler.cpp.flags.esp32c3=-march=rv32imc -ffunction-sections -fdata-sections -W
7676
compiler.S.flags.esp32c3=-ffunction-sections -fdata-sections -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -ggdb -Wno-error=format= -nostartfiles -Wno-format -Os -freorder-blocks -fstrict-volatile-bitfields -Wno-error=unused-but-set-variable -fno-jump-tables -fno-tree-switch-conversion -x assembler-with-cpp -MMD -c
7777
compiler.c.elf.flags.esp32c3=-T memory.ld -T sections.ld -T esp32c3.rom.ld -T esp32c3.rom.api.ld -T esp32c3.rom.libgcc.ld -T esp32c3.rom.newlib.ld -T esp32c3.rom.version.ld -T esp32c3.rom.eco3.ld -T esp32c3.peripherals.ld -nostartfiles -march=rv32imc --specs=nosys.specs -Wl,--cref -Wl,--gc-sections -fno-rtti -fno-lto -u _Z5setupv -u _Z4loopv -u esp_app_desc -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u pthread_include_pthread_rwlock_impl -u start_app -u __ubsan_include -u __assert_func -u vfs_include_syscalls_impl -Wl,--undefined=uxTopUsedPriority -u app_main -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u newlib_include_assert_impl -Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting -Wl,--wrap=__register_frame_info_bases -Wl,--wrap=__register_frame_info -Wl,--wrap=__register_frame -Wl,--wrap=__register_frame_info_table_bases -Wl,--wrap=__register_frame_info_table -Wl,--wrap=__register_frame_table -Wl,--wrap=__deregister_frame_info_bases -Wl,--wrap=__deregister_frame_info -Wl,--wrap=_Unwind_Find_FDE -Wl,--wrap=_Unwind_GetGR -Wl,--wrap=_Unwind_GetCFA -Wl,--wrap=_Unwind_GetIP -Wl,--wrap=_Unwind_GetIPInfo -Wl,--wrap=_Unwind_GetRegionStart -Wl,--wrap=_Unwind_GetDataRelBase -Wl,--wrap=_Unwind_GetTextRelBase -Wl,--wrap=_Unwind_SetIP -Wl,--wrap=_Unwind_SetGR -Wl,--wrap=_Unwind_GetLanguageSpecificData -Wl,--wrap=_Unwind_FindEnclosingFunction -Wl,--wrap=_Unwind_Resume -Wl,--wrap=_Unwind_RaiseException -Wl,--wrap=_Unwind_DeleteException -Wl,--wrap=_Unwind_ForcedUnwind -Wl,--wrap=_Unwind_Resume_or_Rethrow -Wl,--wrap=_Unwind_Backtrace -Wl,--wrap=__cxa_call_unexpected -Wl,--wrap=__gxx_personality_v0 -u __cxa_guard_dummy -u __cxx_fatal_exception
7878
compiler.ar.flags.esp32c3=cr
79-
build.extra_flags.esp32c3=-DARDUINO_HW_CDC_ON_BOOT={build.cdc_on_boot}
79+
build.extra_flags.esp32c3=-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT={build.cdc_on_boot}
8080
#
8181
# ESP32C3 Support End
8282
#

0 commit comments

Comments
 (0)