Allow USB CDC Serial to be disabled, redirect to UART#93
Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes USB_CDC_DEFAULT_SERIAL overridable so that when USB CDC is disabled (USB_CDC_DEFAULT_SERIAL=0), Serial is redirected to the UART hardware port (using the board’s Serial1 pins where applicable).
Changes:
- Make
USB_CDC_DEFAULT_SERIALin several nRF52840 variants conditional (#ifndef ... #define ...) to allow build-time overrides. - Replace
#ifdef/#ifndef USB_CDC_DEFAULT_SERIALwith value-based#if USB_CDC_DEFAULT_SERIALchecks in core utilities. - Introduce UART pin remapping logic intended to convert
Serial1pins intoSerialpins when USB CDC is not the default.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| variants/nRF52840_Dongle/variant.h | Make USB_CDC_DEFAULT_SERIAL override-friendly while defaulting to 1. |
| variants/itsybitsy_nrf52840_express/variant.h | Same: allow override, default to USB CDC serial. |
| variants/feather_nrf52840_sense/variant.h | Same: allow override, default to USB CDC serial. |
| variants/feather_nrf52840_express/variant.h | Same: allow override, default to USB CDC serial. |
| variants/clue_nrf52840/variant.h | Same: allow override, default to USB CDC serial. |
| variants/circuitplayground_nrf52840/variant.h | Same: allow override, default to USB CDC serial. |
| variants/Seeed_XIAO_nRF52840_Sense/variant.h | Same: allow override, default to USB CDC serial. |
| cores/nRF5/utils/debug_utils.cpp | Use value-based checks so USB_CDC_DEFAULT_SERIAL=0 behaves correctly. |
| cores/nRF5/libc/printf/putchar.cpp | Gate Serial.flush() based on the macro’s value (USB CDC vs UART). |
| cores/nRF5/Uart.h | Switch to value-based macro logic and add pin remapping for UART-as-Serial. |
| cores/nRF5/Uart.cpp | Instantiate Serial UART object when USB_CDC_DEFAULT_SERIAL is 0. |
| cores/nRF5/Arduino.h | Ensure variant.h is included early and provide a fallback default for the macro. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8e9da42 to
ec11dfd
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8a1d4f5 to
fcba97c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fcba97c to
c2b2818
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore/Adafruit_TinyUSB_API.cpp
Outdated
Show resolved
Hide resolved
c2b2818 to
515355a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore/Adafruit_USBD_Device.cpp
Show resolved
Hide resolved
515355a to
e496edc
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore/Adafruit_USBD_Device.cpp
Show resolved
Hide resolved
44b8ff5 to
9732d72
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore/Adafruit_USBD_CDC.h:102
SerialTinyUSBis conditionally macro-mapped toSerialbased onUSB_CDC_DEFAULT_SERIAL. SinceUSB_CDC_DEFAULT_SERIALmay not be defined yet in some translation units (e.g., files that includeAdafruit_USBD_CDC.hbeforeArduino.h/variant.h), this can produce inconsistent symbol names (SerialvsSerialTinyUSB) across TUs and lead to link errors. Please ensureUSB_CDC_DEFAULT_SERIALis defined before including this header everywhere it’s used (e.g., includeArduino.hearlier in those TUs or centralize the macro definition in a common config header included beforeAdafruit_USBD_CDC.h).
// Built-in support "Serial" is assigned to TinyUSB CDC
// CH32 defines Serial as alias in WSerial.h
#if defined(USE_TINYUSB) && !defined(ARDUINO_ARCH_CH32) && USB_CDC_DEFAULT_SERIAL
#define SerialTinyUSB Serial
#endif
extern Adafruit_USBD_CDC SerialTinyUSB;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore/Adafruit_USBD_Device.cpp
Show resolved
Hide resolved
This will set the default Serial output to UART if USB CDC is disabled by setting USB_CDC_DEFAULT_SERIAL to 0. If the board has Serial1 pins defined they will be redefined to Serial.
9732d72 to
dde6a09
Compare
This will set the default Serial output to UART if USB CDC is disabled by setting USB_CDC_DEFAULT_SERIAL to 0.
If the board has Serial1 pins defined they will be redefined to Serial.