Skip to content

Add companion_radio_serial env for XIAO nRF52840 🤖🤖 - #3191

Open
jpmartineau wants to merge 1 commit into
meshcore-dev:devfrom
jpmartineau:xiao-nrf52-companion-serial
Open

Add companion_radio_serial env for XIAO nRF52840 🤖🤖#3191
jpmartineau wants to merge 1 commit into
meshcore-dev:devfrom
jpmartineau:xiao-nrf52-companion-serial

Conversation

@jpmartineau

Copy link
Copy Markdown

The XIAO nRF52840 leaves D6/D7 free once the Wio-SX1262 has taken the SPI pins, so it can carry the companion protocol on a hardware UART exactly like Xiao_S3_WIO_companion_radio_serial already does on the ESP32-S3 side. Two things were in the way.

HardwareSerial. The SERIAL_RX block declares HardwareSerial companion_serial(1) and calls setPins() on it. The Adafruit nRF52 core has no numbered constructor and HardwareSerial is abstract there, so the env doesn't compile:

error: cannot declare variable 'companion_serial' to be of abstract type 'HardwareSerial'
error: 'class HardwareSerial' has no member named 'setPins'

Serial1 is the concrete Uart instance the core always defines on the nRF52840, and Uart::setPins(pin_rx, pin_tx) takes the same two arguments in the same order as the ESP32 method, so a reference to it leaves the call site untouched.

I2C is mapped onto the same two pins. variants/xiao_nrf52 sets PIN_WIRE_SCL=D6 and PIN_WIRE_SDA=D7, and both XiaoNrf52Board::begin() and sensors.begin() call Wire on them. sensors.begin() runs after setup() has configured the UART, so TWIM takes the pads back as open-drain I2C and the link goes quiet with correct wiring and nothing logged anywhere — it took me a while to find. The new env unsets those two defines and points I2C at the internal IMU pins (16/17), which is where the variant header suggests they belong.

That remap is scoped to the new env with build_unflags rather than changed in the shared [Xiao_nrf52] flags, so the ble, usb, repeater, room server and kiss modem builds are unaffected. Nothing outside the new env changes.

Tested on a XIAO nRF52840 with a Wio-SX1262, D6/D7 wired to a Luckfox Lyra's UART1 (crossed, common ground, powered from 3V3). The node has been up on the mesh since I flashed it and answers a companion client on /dev/ttyS1 at 115200 — self info, contacts, config reads and writes, clock sync.

I also built Xiao_nrf52_companion_radio_usb and Xiao_S3_WIO_companion_radio_serial to check both sides of the new #if; neither regressed.

Context: I need this to use my Seeed nRF52840 in my Clockwork PicoCalc, using GPIO.

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.
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.

1 participant