Skip to content

Allow USB CDC Serial to be disabled, redirect to UART#93

Merged
h2zero merged 1 commit intomasterfrom
usb-serial-override
Mar 3, 2026
Merged

Allow USB CDC Serial to be disabled, redirect to UART#93
h2zero merged 1 commit intomasterfrom
usb-serial-override

Conversation

@h2zero
Copy link
Owner

@h2zero h2zero commented Feb 10, 2026

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_SERIAL in several nRF52840 variants conditional (#ifndef ... #define ...) to allow build-time overrides.
  • Replace #ifdef/#ifndef USB_CDC_DEFAULT_SERIAL with value-based #if USB_CDC_DEFAULT_SERIAL checks in core utilities.
  • Introduce UART pin remapping logic intended to convert Serial1 pins into Serial pins 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.

@h2zero h2zero force-pushed the usb-serial-override branch from 8e9da42 to ec11dfd Compare February 11, 2026 00:10
@h2zero h2zero marked this pull request as ready for review February 11, 2026 00:10
@h2zero h2zero requested a review from Copilot February 11, 2026 00:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@h2zero h2zero force-pushed the usb-serial-override branch 2 times, most recently from 8a1d4f5 to fcba97c Compare February 12, 2026 00:42
@h2zero h2zero requested a review from Copilot February 12, 2026 01:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@h2zero h2zero force-pushed the usb-serial-override branch from 515355a to e496edc Compare March 3, 2026 18:10
@h2zero h2zero changed the title Allow USB Serial to be disabled, redirect to UART Serial Allow USB CDC Serial to be disabled, redirect to UART Mar 3, 2026
@h2zero h2zero requested a review from Copilot March 3, 2026 18:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@h2zero h2zero force-pushed the usb-serial-override branch 2 times, most recently from 44b8ff5 to 9732d72 Compare March 3, 2026 20:30
@h2zero h2zero requested a review from Copilot March 3, 2026 20:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • SerialTinyUSB is conditionally macro-mapped to Serial based on USB_CDC_DEFAULT_SERIAL. Since USB_CDC_DEFAULT_SERIAL may not be defined yet in some translation units (e.g., files that include Adafruit_USBD_CDC.h before Arduino.h/variant.h), this can produce inconsistent symbol names (Serial vs SerialTinyUSB) across TUs and lead to link errors. Please ensure USB_CDC_DEFAULT_SERIAL is defined before including this header everywhere it’s used (e.g., include Arduino.h earlier in those TUs or centralize the macro definition in a common config header included before Adafruit_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.

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.
@h2zero h2zero force-pushed the usb-serial-override branch from 9732d72 to dde6a09 Compare March 3, 2026 23:08
@h2zero h2zero merged commit 9edb8a7 into master Mar 3, 2026
60 checks passed
@h2zero h2zero deleted the usb-serial-override branch March 3, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants