From 923526252503a641ff876fb59b2d031573c6f910 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Martineau Date: Wed, 12 Aug 2026 21:11:11 -0400 Subject: [PATCH] Add companion_radio_serial env for XIAO nRF52840 The SERIAL_RX/SERIAL_TX companion interface only builds on ESP32 and RP2040: it declares HardwareSerial companion_serial(1) and calls setPins(), neither of which exists on the Adafruit nRF52 core, where HardwareSerial is abstract and Serial1 is the concrete Uart instance. Use Serial1 there. Uart::setPins(pin_rx, pin_tx) takes the same arguments in the same order, so the call site is unchanged. The new env also has to move I2C. variants/xiao_nrf52 maps PIN_WIRE_SCL and PIN_WIRE_SDA onto D6/D7, and both XiaoNrf52Board::begin() and sensors.begin() call Wire on them, so the TWIM peripheral takes the pads back after setup() and the UART goes quiet with no other symptom. The env unsets those two defines and points I2C at the internal IMU pins instead. Nothing outside the new env changes. Tested on a XIAO nRF52840 with a Wio-SX1262, wired D6/D7 to a Luckfox Lyra's UART1 and talking to a terminal client over /dev/ttyS1. --- examples/companion_radio/main.cpp | 8 +++++++- variants/xiao_nrf52/platformio.ini | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 89f0e6cb9f..cf30f9ad82 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -61,7 +61,13 @@ MultiSerialInterface interface_manager; #if defined(SERIAL_RX) #include ArduinoSerialInterface hardware_serial_interface; - HardwareSerial companion_serial(1); + #if defined(NRF52_PLATFORM) + // nRF52 has no numbered-constructor HardwareSerial; Serial1 is the concrete UARTE0 + // instance the core always defines. setPins() below moves it to the requested pads. + Uart& companion_serial = Serial1; + #else + HardwareSerial companion_serial(1); + #endif #endif // platform file system diff --git a/variants/xiao_nrf52/platformio.ini b/variants/xiao_nrf52/platformio.ini index 1076bd8de7..1eb216d15a 100644 --- a/variants/xiao_nrf52/platformio.ini +++ b/variants/xiao_nrf52/platformio.ini @@ -119,3 +119,28 @@ build_src_filter = ${Xiao_nrf52.build_src_filter} +<../examples/kiss_modem/*.cpp> lib_deps = ${Xiao_nrf52.lib_deps} + +[env:Xiao_nrf52_companion_radio_serial] +extends = Xiao_nrf52 +board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld +board_upload.maximum_size = 708608 +build_flags = + ${Xiao_nrf52.build_flags} + -I examples/companion_radio/ui-orig + -D MAX_CONTACTS=350 + -D MAX_GROUP_CHANNELS=40 + -D OFFLINE_QUEUE_SIZE=256 + -D QSPIFLASH=1 + -D SERIAL_TX=D6 + -D SERIAL_RX=D7 + -D PIN_WIRE_SCL=16 + -D PIN_WIRE_SDA=17 +build_unflags = + -D PIN_WIRE_SCL=D6 + -D PIN_WIRE_SDA=D7 +build_src_filter = ${Xiao_nrf52.build_src_filter} + +<../examples/companion_radio/*.cpp> + +<../examples/companion_radio/ui-orig/*.cpp> +lib_deps = + ${Xiao_nrf52.lib_deps} + densaugeo/base64 @ ~1.4.0