Skip to content

7. Radio bring-up (LoRa Cap)

Only relevant if your app drives the Cap LoRa-1262. This is the sequence to power and initialize its SX1262 robustly from userspace with no root. Getting it wrong is what defeated earlier attempts on this device, so it's worth doing carefully.

⚠️ Attach the antenna before powering the radio. Transmitting without an antenna can permanently damage the SX1262. The software cannot check this — it's on the user, so say so in your UI and docs.

Confirmed wiring (this Cap on this board)

Line Value
SPI /dev/spidev0.1 (kernel CS1)
RESET GPIO26
BUSY GPIO22
DIO1 / IRQ GPIO23
RF switch SX1262 DIO2 (DIO2_AS_RF_SWITCH=true)
TCXO SX1262 DIO3, 3.0 V
Cap 5 V rail /sys/class/leds/ext_5v_out/brightness (1 = on)
EXT selector /sys/class/leds/ext_usb_gpio_fun/brightness — must be 0 (GPIO mode)
Band-path expander PI4IOE5V6408 at I²C 0x43 on /dev/i2c-1 (lives on the Cap; only answers once the 5 V rail is up)
GNSS /dev/serial0 @ 115200 (shares the 5 V rail)

Run it in a child process

Run the radio in a child process whose lifetime matches the connection, so the kernel frees every GPIO line and the spidev handle the instant it exits or crashes — no stuck pins, no lingering lock. Let the kernel be the lock: don't invent a lockfile for the SPI bus; a second claimant gets EBUSY and the kernel cleans up on exit. (This is the same child-process boundary the architecture chapter recommends for all hardware work.)

The sequence (ordered)

  1. Pre-flight. Check /dev/spidev0.1, /dev/gpiochip0, /dev/i2c-1 exist and are read/write; turn each failure into a specific message (no-spi / no-gpio / no-i2c / permission → "add your user to the spi, gpio, i2c groups and re-login"). If a known holder owns the radio (another LoRa app, a bridge), say so rather than retry-failing.
  2. Power, saving state first. Read and save the current ext_5v_out and ext_usb_gpio_fun values. Write ext_5v_out=1, then ext_usb_gpio_fun=0 (at =1 the Cap's reset line is cut and the chip stays in reset). Sleep ~100 ms for the regulator and the on-Cap expander to come up.
  3. Band path (the 0x43 expander). On /dev/i2c-1, address 0x43: verify the ID register first (expect 0xA2, maker bits 0b101); then write the output level (reg 0x05) before the direction (reg 0x03) so the RF-enable pin comes up already-high with no low glitch, then high-Z (reg 0x07). Classify every failure (busy / absent / wrong-chip) with an actionable message; on any failure here, restore the LED switches and abort cleanly.
  4. Init the SX1262. Let your radio library do the reset pulse, BUSY handshake, DIO3-TCXO (3.0 V), DIO2-as-RF-switch, and image calibration — don't hand-code them. Construct with: SPI spidev0.1, RESET 26, BUSY 22, IRQ/DIO1 23, DIO2_AS_RF_SWITCH=true, DIO3_TCXO_VOLTAGE=3.0. Filter constructor kwargs against the driver's real signature so a library version that doesn't accept a field doesn't crash you. begin() with a few retries and escalating backoff (~1.5 s) to ride out a line a dying prior process is still releasing.
  5. Serve / run. This is where your actual radio work happens — e.g. running meshtasticd against the now-powered Cap, which handles the SX1262 and the Meshtastic protocol via its YAML. The Cap power + the 0x43 band path are yours to do first, because the radio daemon does not drive them.
  6. Teardown on normal exit. In a try/finally: stop the radio, then restore ext_usb_gpio_fun and ext_5v_out to their saved values in reverse order (5 V rail back off, so the Cap doesn't drain the battery). This must run on a failed start. A finally block cannot run after SIGKILL; use a separate guardian and service cleanup for abrupt termination. Restore exact prior values; do not assume a saved rail value was zero.

Gotchas (each one cost real debugging)

  • ext_usb_gpio_fun must be 0, or the Cap's reset line is cut and the SX1262 stays in reset.
  • Power the rail and settle ~100 ms before touching the expander — it has no power before that, so probing it earlier reads a false "absent."
  • Write the expander's output level before its direction to avoid a low glitch on the RF-enable pin.
  • The radio library's IRQ-watch thread can stall shutdown ~2 s, but the launcher only allows ~3 s between SIGTERM and SIGKILL — stop the edge threads before cleanup or your app looks like it hangs on quit.
  • Resolve the gpiochip by its kernel label, not its number — the number can move across CM revisions and kernels.

If you bundle a GPL radio daemon

The native daemon and Python client retain their GPL terms. Mesh's supervisor is GPL-3.0-or-later; its separate UI files retain their MIT terms. Preserve each component's applicable licenses and corresponding-source obligations. A process or socket boundary is not an automatic licensing exemption.

Earlier Mesh versions used separate prerequisites. Version 0.1.19 redistributes a private native runtime and locked wheels with notices and paired source. Neither plan is universal; see packaging and security/publishing.

Legal/operational rules to surface in your app

  • Use a band you're licensed to transmit on (e.g. 902–928 MHz in the US).
  • Antenna before power (above).
  • Support public channels deliberately and label them clearly. Use a secret random key for traffic that needs a private group; public default keys provide no group privacy.

Next: shipping it safely — security and publishing.

Radio configuration is part of the safety boundary

The daemon can transmit from persisted settings during startup, before a client has connected and inspected them. Prepare a reviewed profile with the correct region before powering it, and document that boot window. Validate the effective per-channel location precision and MQTT module state, not just the broadcast interval. Do not enable position on every enabled channel: a public primary may have been deliberately disabled for location. Require an explicit channel target and verify real readback. A DM or trace must not silently use a public primary.

Validate persisted configuration before powering the device/daemon, not only after connecting. Firmware can emit identity or telemetry on its primary channel without a UI send intent. Distinguish an operator's private-only configuration from a product-wide restriction. A general client can support public and private channels while requiring explicit routing and separate location consent. Disable unapproved public location defaults before firmware can broadcast; persist only confirmed consent, bound to channel identity and precision. Preserve frequency/modulation when converting an existing secondary private channel into a private-only profile, and verify the peer link. Check the firmware's accepted preference schema and required fields too: an empty or stale protobuf may parse successfully but trigger factory defaults at boot. An absent transmission flag must not be mistaken for verified receive-only configuration. Fail closed for schemas your integration has not qualified.

Parsing a fresh protobuf is insufficient to validate first run. Explicitly set required operational defaults, then start the actual daemon from empty app state and read them back. A default-false security/console flag can suppress startup diagnostics even while the daemon runs. Likewise, an empty settings submessage may be serialized in every disabled channel slot; message presence alone does not prove that a slot contains a retained configuration. Check meaningful fields.

Verify requested settings semantically. Firmware can populate derived modem fields and normalize empty submessages, so whole-message byte equality can reject a successful change. Compare the requested effective values and safety invariants such as transmission state. Test both an accepted normalization and a genuine readback mismatch. Treat expected tuning reboots as a planned stop/reconnect, while preserving unexpected disconnects as actual failures.

Public and private chat channels share one radio's region, modem preset and frequency slot. Importing a channel key does not establish matching RF tuning. Expose those settings and avoid silently applying URL tuning or replacing an existing channel just because the names match. A DM must not choose an arbitrary private channel or fall back to the public primary when its selection disappears.

Check kernel ownership, not only device-file permissions

Read/write access to /dev/gpiochip0 does not mean the needed lines are free. A different Cap's SPI overlay can claim a line through a kernel driver, with no userspace GPIO file descriptor to find. Query line ownership before power-on and surface the specific conflict. On this image, the NFC SPI-CS2 overlay reserves GPIO22, which LoRa needs for BUSY, and the upstream NFC app leaves the runtime overlay until reboot. Do not silently unbind another driver's pin or remove a shared SPI overlay; those actions can affect the display and other apps.

Normalize vendor sysfs values by their physical meaning. This image can report 255 for an enabled binary GPIO LED despite max_brightness=1. Validate the complete recovery record before writing any switch and persist canonical logical0/1, so valid vendor values cannot strand all later starts behind a failed recovery.