Skip to content

Fix/c6l hardware - #3996

Closed
cassiofiorin wants to merge 254 commits into
meshcore-dev:mainfrom
cassiofiorin:fix/c6l-hardware
Closed

cassiofiorin wants to merge 254 commits into
meshcore-dev:mainfrom
cassiofiorin:fix/c6l-hardware

Conversation

@cassiofiorin

Copy link
Copy Markdown

Summary

The m5stack_unit_c6l variant added in #3100 does not match the hardware of the
M5Stack Unit C6L: the pins and the I/O expander setup are wrong, so the radio has
no RF path and the console is unreachable.

This PR fixes the variant, keeping the existing environment names
(M5Stack_Unit_C6L_*) and adding no new dependencies.

current this PR
I2C (expander, button) GPIO 16/17 GPIO 10/8
PI4IOE5V6408 @0x43 never initialised P5 LNA_EN, P6 ANT_SW, P7 NRST
BOOT button not read read from P0 (active low)
SX1262 reset RESET pin through the expander
TCXO 1.8 V 3.0 V
TX indicator P_LORA_TX_LED=15 (collides with the OLED reset) on-board WS2812C on GPIO 2
SX126X_RXEN=5 collides with the Grove/GPS TX pin removed (TCXO only)
USB console Serial on UART0 (not reachable) USB-CDC (ARDUINO_USB_MODE, ARDUINO_USB_CDC_ON_BOOT)

Details

  • UnitC6LBoard now owns the expander: reset, direction, pull-ups on P0/P1,
    output latch (P7 | P6 | P5), isButtonPressed() and checkOTASwitch()
    (hold the button for 500 ms at boot to switch the OTA slot, with beeps).
  • The radio/board definitions moved to target.cpp, like the other variants;
    UnitC6LBoard.h only holds the board class. No functional change for the
    headless environments.
  • platformio.ini gets the corrected pins/TCXO, the NeoPixel TX indicator and
    the USB-CDC flags; the stale +<UnitC6LBoard.cpp> filter entry is dropped
    (the variant directory is already included).

Pinout and expander sequence follow the official Meshtastic variant for the same
board (m5stack/meshtastic-firmware, variants/esp32c6/m5stack_unitc6l);
register constants from the PI4IOE5V6408 datasheet.

Testing

Hardware: M5Stack Unit C6L (ESP32-C6, SX1262, 16 MB flash).

  • M5Stack_Unit_C6L_repeater, M5Stack_Unit_C6L_room_server and
    M5Stack_Unit_C6L_companion_radio_usb build successfully.
  • Flashed the repeater image over USB (esptool, no erase, coming from MeshCore
    1.11.0): boots, identity and radio prefs preserved, ver reports v1.18.0,
    board reports M5Stack Unit C6L, stats-radio shows RX traffic
    (noise floor / last RSSI), TX works, and a companion connected to it over the
    mesh.

Not tested: the OTA A/B switch (the button sequence) and the ble/room-server
images on hardware.

Quency-D and others added 30 commits July 23, 2026 15:53
M5Stack_Unit_C6L_kiss_modem env was missing ARDUINO_USB_CDC_ON_BOOT,
ARDUINO_USB_MODE, and ENABLE_USB_INTERFACE build flags, present in
the companion_radio_usb env for the same board. Without these,
ESP32-C6 native USB serial output goes to UART0 (unconnected on this
board), making the KISS modem unresponsive over USB.

Hardware-verified: M5Stack Unit C6L, KISS modem confirmed operational
via /dev/ttyACM0 with openhop_repeater.
A RAK4631 core paired with a RAK13302 leaves the core's own SX1262
powered but never initialized, idling in STDBY_RC for the life of the
board. Firmware cannot cut its supply -- P1.05 is the RF switch rail,
not the radio's -- so bring it up on its own pins just long enough to
issue a cold sleep, before std_init() repins SPI onto the RAK13302.

Gated behind RAK4631_ONBOARD_SX1262_SLEEP and exposed through seven
RAK_4631_13302_* envs, so RAK_3401_* artifacts are unchanged.

The sleep is issued regardless of what begin() returns: Module::init()
runs first, so SPI stays usable even if TCXO calibration fails. NSS is
then held high, since the SX1262 wakes on an NSS falling edge.

Verified on RAK19007 + RAK4631 + RAK13302: begin=0 sleep=0, RAK13302
init clean (device_errors=0x0000), TX and RX both confirmed. The
current saving itself is derived from the datasheet (600 uA STDBY_RC
-> 160 nA cold sleep) and is not measured.
BUSY is driven low in STDBY_RC and high while asleep, so reading it either
side of the sleep gives a non-invasive readback of the state the chip was
found in and the state it was left in. Confirmed on hardware.

This is what makes the sleep observable at all. The only other symptom of
a failed sleep is ~600 uA, which is below what an inline USB meter can
resolve, so without this a regression would be silent.

It immediately earned itself: busy_before reads 0 on every boot, showing
the cold sleep does not survive an MCU reset. GPIOs revert to input during
reset, NSS stops being driven high, and the falling edge wakes the chip.
The helper re-sleeps it, so this is self-healing, but it means the chip is
never found already asleep.
Add SetHardware sub-commands so a host can probe and configure
per-board RF front-end settings:

- GetCapabilities (0x1B): uint32 feature bits (AGC, FEM RX, FEM TX)
- Set/GetAgcResetInterval (0x1C/0x1D): 0-1020 s, 4 s resolution,
  0 disables; default stays 30 s
- Set/GetFemState (0x1E/0x1F): apply/value masks for FEM RX (LNA)
  and TX (PA) gain; all-or-nothing, Unsupported (0x08) if any
  requested bit is not controllable on this board

The AGC scheduler moves from main.cpp into KissModem so it is
configurable and unit-tested. FEM changes that arrive mid-TX are
deferred until the packet ends, since board setters drive FEM pins
directly.

MainBoard gains virtual FEM hooks (canControl/set/is for LNA and PA
gain). Boards that already implemented these methods privately now
expose them as overrides: Heltec V4, V4 R8, T096, Tracker V2,
Station G3 and Wio Tracker L1 1W.

KISS_FIRMWARE_VERSION bumped to 2.
USBCDC (ARDUINO_USB_MODE=0, TinyUSB) has no setTxBufferSize, which broke
the Station G3 and Heltec Tracker V2 KISS builds.
…ntrol

- Wio Tracker L1 1W no longer advertises TX gain control: its setter
  drives LORA_PWR_EN, the shared LDO for the SX1262 and the PA, so
  "gain off" would power down the radio.
- A SetFemState that arrives mid-TX is now applied after TxDone is
  queued, so its reply follows TxDone.
- SetFemState replies (immediate or deferred) are retained until they
  fit in the host output queue instead of being dropped, so a change
  that took effect is always acknowledged.
- GetFemState replies queue behind an outstanding SetFemState reply;
  a further SetFemState returns TxBusy until it clears.
Add SetRxBoostedGain (0x20) / GetRxBoostedGain (0x21, reply 0xA1) and
capability bit 3, the KISS equivalent of the radio.rxgain CLI setting.
It is separate from FEM RX gain; a board may support either or both.

- Support is declared by the driver via a new
  RadioLibWrapper::supportsRxBoostedGain() (SX1262, SX1268, LLCC68,
  LR1110, LR1121, LR2021), so nothing is written to the radio at boot.
- The set is refused with TxBusy during TX or while host output is
  backed up. Otherwise any completed RX packet is delivered first,
  because some drivers (LR2021) drop to standby to apply the gain.
- The reply always carries the state read back from the radio.

Driver fixes found along the way, which also affect the radio.rxgain
CLI in regular firmware:
- CustomLR2021 never updated its cached gain state, so the getter
  always reported off. It now tracks the applied level per RX path
  and rolls RadioLib's cached level back if a write fails.
- CustomLR1110/LR1121 cached the requested state even when the write
  failed.
- lr11x0ResetAGC only reapplied the gain when RX_BOOSTED_GAIN was
  defined, so a runtime setting was lost on the next AGC reset.
Boards own their FEM control through handleCommand() ("get/set
radio.fem.rxgain|txgain"). Use that instead of a parallel set of FEM
virtuals on MainBoard, so any board that implements the commands works
in KISS with no extra code.

- Remove the six FEM virtuals from MainBoard and the board overrides.
- KissModem talks to the board in one adapter. A gain counts as
  controllable only if "get" replies exactly "> on" or "> off". "set"
  is checked by reading the state back, never by its reply wording.
- SetFemState always replies with the read-back state once the
  requested bits pass the capability check.
- Guard the boards' prefs writes against a NULL store. KISS attaches
  no prefs, so "set radio.fem.*" would dereference NULL.
- Wio Tracker L1 1W TX gain is exposed again, matching its CLI.
A second SetFemState sent while the first was held for a TX got an
immediate TxBusy, which reached the host before the first request's
reply. With no request IDs, the host could not tell which Set failed.

FEM requests now go through a small ordered queue (Set, Get and their
error replies). Sets still wait for TxDone to be queued and apply
once. Each reply is kept until it can be queued. Capability checks
happen in order at processing time. Only an overflow (more than 4
waiting) replies TxBusy immediately.
The AGC interval is set in 4 s steps, matching MeshCore's
agc.reset.interval, so the old 30 s default could not be restored by a
host: setting 30 gives 28. Found on hardware. Use 32 s, the nearest
multiple of 4 above it.
sx126xResetAGC only restored the gain when the build defined
SX126X_RX_BOOSTED_GAIN, so a gain set at runtime was lost on reset.
Match lr11x0ResetAGC and always reapply. Also pass the gain state from
the LLCC68 wrapper, whose call did not match the helper's signature.
Housekeeping: removed unnecessary space
Use the existing RAK3401 firmware roles for RAK4631 cores paired with a
RAK13302. Probe the optional onboard radio and put it into cold sleep
before handing SPI to the primary radio, removing seven duplicate build
environments.

Preserve BUSY startup readiness, release probe pulls before sleep, and
disconnect unused GPIO input buffers during cleanup. Add focused tests
for sequencing, missing signatures, timeouts, and failed sleep readback.

Validated with four native tests, seven firmware-role builds, and repeater
boot checks on RAK4631 + RAK13302. Supply current was not measured.
Fix: tz_offset should allow for half hour timezone offsets
…ditional-display

Remove BLE screen when BLE not available
Move the onboard radio probe into RAK3401Board::begin() so a low-voltage
SYSTEMOFF at boot no longer leaves the RAK4631's onboard SX1262 in
standby. Add board startup tests and run them in CI.
'get tz.offset' printed one decimal, so a UTC+5:45 offset (5.75)
read back as 5.8. Print two decimals when the offset is on a quarter
hour (x.25 / x.75); everything else keeps one decimal.
ripplebiz and others added 29 commits November 21, 2026 20:59
get/set buzzer was added to the companion CLI in meshcore-dev#3603 but not to
docs/companion_cli.md.
onAckRecv called markDoNotRetransmit(), which sets the header to 0xFF,
before testing isRouteFlood(). 0xFF's route bits read as
ROUTE_TYPE_TRANSPORT_DIRECT, so the test was always false and
handleReturnPathRetry never ran for a flood ACK: the reciprocal path
was never re-sent to a node that was still flooding. Mark the packet
after the test instead.
…ion-buzzer-cli

Document the companion buzzer CLI command
Documentation change to clarify radio settings and individual country requirements.
…th-retry

Test a flood ACK's route before marking it, so the reciprocal path retry runs 🤖🤖
get/set ui.auto_off_keep_msgs was added to the companion CLI in meshcore-dev#3687
but not to docs/companion_cli.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reset during an RTC read left SDA held low, and the RTC probe then
hung every boot. Up to nine clock pulses release the bus.
The BLE build got it in ea85486. The USB build runs on the same
hardware.
…o-off-keep-msgs

Document the companion ui.auto_off_keep_msgs setting
…n-lock

ui: lock joystick with a Menu double-click
…egister-patch-upstream

fix(heltec_t096): enable the 0x8B5 register patch like the Heltec V4
feat(thinknode_m1): Enable the GPS on the USB companion
fix(thinknode_m6): Free the I2C bus before probing the RTC
…o-fix

Hide coordinates until GPS has a fix
updateContactFromFrame() copies 32 name bytes from the companion frame
without terminating them, so an app (or a corrupt frame) can store a name
with no NUL. The UI then passes it to sprintf() into fixed-size origin
buffers. Terminate the name on receipt and use snprintf() in both UIs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
addToRecents() in the new and tiny companion UIs strcpy()s the contact
name into a 32-byte field. Names are terminated on receipt now, but use
a bounded copy here as well, like the other name copies in the UIs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erwrite

Fix admin being overwritten when the client ACL is full of admins
Terminate contact names received from the companion app 🤖🤖
The C6L variant does not match the hardware it claims to support: the I2C bus
is on GPIO 10/8 (not 16/17), the PI4IOE5V6408 expander that drives the antenna
switch, the LNA enable and the LoRa reset is never initialised, the TCXO runs
at 3.0 V (not 1.8 V), the TX LED is the on-board WS2812C on GPIO2
(P_LORA_TX_LED=15 collides with the OLED reset) and SX126X_RXEN=5 collides
with the Grove/GPS TX pin, so the transceiver never sees a valid RF path.

- UnitC6LBoard: initialise the expander (P5 = LNA_EN, P6 = ANT_SW,
  P7 = NRST), read the BOOT button from P0 (active low), drive the buzzer and
  use the button to switch OTA partitions at boot
- move the radio/board definitions into target.cpp, matching the other
  variants (Board.h only holds the board class)
- platformio.ini: correct I2C pins and TCXO voltage, use the NeoPixel as TX
  indicator, drop SX126X_RXEN, select the USB-CDC console (the USB port is the
  only accessible console on this unit) and drop the stale src_filter entry

Pins and expander register sequence follow the official Meshtastic variant for
the same board (m5stack/meshtastic-firmware, variants/esp32c6/m5stack_unitc6l).

Builds: M5Stack_Unit_C6L_repeater, _room_server and _companion_radio_usb all
succeed. Radio init, RX/TX and the console were verified on hardware.
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.