Enable lr2021 on native - #10567
Conversation
… into Enable-lr2021-on-native
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Enables LR2021 LoRA radio support on the native (Portduino) platform by adding module selection/configuration and wiring up LR2021 initialization and RF-switch handling.
Changes:
- Added
lr2021as a selectable LoRA module for Portduino and introduced LR2021-specific config options (max power incl. HF and IRQ DIO number). - Updated radio initialization to construct
LR2021Interfacewhen selected. - Refactored RF-switch symbol handling to avoid LR11x0/LR20x0 table name collisions and added a sample native USB config for an LR2021 module.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| variants/nrf52840/diy/nrf52_promicro_diy_tcxo/rfswitch.h | Adds LR20x0-native RF-switch definitions and wraps existing tables with per-table guards. |
| src/platform/portduino/PortduinoGlue.h | Adds use_lr2021 and LR2021-related config fields. |
| src/platform/portduino/PortduinoGlue.cpp | Loads new LR2021 config values from YAML. |
| src/mesh/RadioInterface.cpp | Constructs an LR2021Interface when use_lr2021 is selected. |
| src/mesh/LR20x0Interface.cpp | Adjusts compile guards, RF-switch aliasing, and Portduino IRQ DIO configuration. |
| src/mesh/LR2021Interface.cpp | Adjusts compile guard for LR2021 interface compilation. |
| src/mesh/LR11x0Interface.cpp | Namespaces LR11x0 RF-switch tables to avoid collisions and updates usage. |
| src/mesh/InterfacesTemplates.cpp | Adjusts explicit template instantiation guard for LR20x0/LR2021. |
| bin/config.d/lora-usb-meshtoad-nicerflora2021f33.yaml | Adds a sample native USB configuration for an LR2021-based module. |
| #include "RadioLib.h" | ||
|
|
||
| // Keep LR20x0 naming while RadioLib exposes LR2021 symbols. |
| static const uint32_t lr20x0_rfswitch_dio_pins[] = {RADIOLIB_LR2021_DIO5, RADIOLIB_LR2021_DIO6, RADIOLIB_LR2021_DIO7, | ||
| RADIOLIB_LR2021_DIO8, RADIOLIB_NC}; |
| #if RADIOLIB_EXCLUDE_LR2021 != 1 | ||
| template class LR20x0Interface<LR2021>; | ||
| #endif |
⚡ Try this PR in the Web FlasherWarning This is an automated, unreviewed CI test build. Back up your device configuration Supported boards built by this PR (30)
Build artifacts expire on 2026-08-19. Updated for |
Firmware Size Report22 targets | vs
Show 17 more target(s)
Updated for 18ae0c2 |
|
@jessm33 can you run trunk fmt? |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds LR2021 Portduino support, updates LR11x0/LR20x0 RF switch handling and compilation guards, extends Portduino configuration and radio selection, and adds a ChangesLR2021 Portduino Integration and RF Switch Renaming
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant PortduinoGlue
participant portduino_config
participant RadioInterface
participant LR2021Interface
PortduinoGlue->>portduino_config: parse LR2021 power, IRQ, and RX HF settings
RadioInterface->>portduino_config: select use_lr2021
RadioInterface->>LR2021Interface: construct interface
LR2021Interface->>portduino_config: read lr2021_irq_dio_num
LR2021Interface->>LR2021Interface: set lora.irqDioNum during init
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bin/config.d/lora-usb-meshtoad-nicerflora2021f33.yaml`:
- Around line 24-31: The rfswitch_table entry includes MODE_RX_HF, but
PortduinoGlue.cpp only parses the supported mode keys, so this column will be
ignored at runtime. Update the LoRa2021F33 rfswitch_table in the YAML to use one
of the parsed mode names (for example an existing RX/TX variant), or, if LR2021
truly needs it, extend the PortduinoGlue parser first so it recognizes
MODE_RX_HF alongside the other mode constants.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 96ff0d91-46ba-4f2a-bb6a-0c1dcd73e6ac
📒 Files selected for processing (9)
bin/config.d/lora-usb-meshtoad-nicerflora2021f33.yamlsrc/mesh/InterfacesTemplates.cppsrc/mesh/LR11x0Interface.cppsrc/mesh/LR2021Interface.cppsrc/mesh/LR20x0Interface.cppsrc/mesh/RadioInterface.cppsrc/platform/portduino/PortduinoGlue.cppsrc/platform/portduino/PortduinoGlue.hvariants/nrf52840/diy/nrf52_promicro_diy_tcxo/rfswitch.h
done |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/platform/portduino/PortduinoGlue.cpp (1)
902-937: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winSeparate LR2021
MODE_RX_HFfrom the sharedMODE_TX_HPslot.src/platform/portduino/PortduinoGlue.cppstores both YAML keys inrfswitch_table[3], andsrc/platform/portduino/PortduinoGlue.honly round-tripsMODE_TX_HP, so LR2021 configs lose the RX_HF state and the table is tagged with the wrong mode forsrc/mesh/LR20x0Interface.cpp. Use the LR2021 mode enum for that row instead of aliasing it.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platform/portduino/PortduinoGlue.cpp` around lines 902 - 937, The LR2021 RF switch handling is conflating `MODE_RX_HF` with the `MODE_TX_HP` table entry in `PortduinoGlue.cpp`, so the YAML state is stored under the wrong mode and cannot round-trip correctly. Update the `rfswitch_table` setup to use the proper LR2021 mode symbol for the RX_HF row, and make sure the corresponding serialization logic in `PortduinoGlue.h` preserves that distinct mode instead of aliasing it to `MODE_TX_HP`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/platform/portduino/PortduinoGlue.cpp`:
- Around line 902-937: The LR2021 RF switch handling is conflating `MODE_RX_HF`
with the `MODE_TX_HP` table entry in `PortduinoGlue.cpp`, so the YAML state is
stored under the wrong mode and cannot round-trip correctly. Update the
`rfswitch_table` setup to use the proper LR2021 mode symbol for the RX_HF row,
and make sure the corresponding serialization logic in `PortduinoGlue.h`
preserves that distinct mode instead of aliasing it to `MODE_TX_HP`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 97e9d065-a9b5-4ad6-b0ef-a64e5b934433
📒 Files selected for processing (1)
src/platform/portduino/PortduinoGlue.cpp
The save path in PortduinoGlue.h hardcoded LR11x0 mode names (MODE_TX_HP, MODE_GNSS, MODE_WIFI) and always wrote 7 entries. For LR2021 configs, slot 3 is MODE_RX_HF (not MODE_TX_HP) and modes 5-6 (GNSS/WIFI) don't exist. Saving an LR2021 config and reloading it would put RF switch values in the wrong slots. Branch the serialization loop on lora_module == use_lr2021: - Write MODE_RX_HF for slot 3 instead of MODE_TX_HP - Write only 5 entries (no MODE_GNSS/MODE_WIFI) - Guard with #if !RADIOLIB_EXCLUDE_LR2021 for builds without LR2021 This matches the load path in PortduinoGlue.cpp which already branches on use_lr2021 to use LR2021::MODE_* enums. Ref: CodeRabbit review on meshtastic#10567 (outside-diff comment on PortduinoGlue.cpp lines 902-937).
Add full LR2021 radio support for meshtasticd on Linux native builds, including USB (CH341) and SPI (GPIO) configurations. Key changes: PortduinoGlue (config plumbing): - Add use_lr2021 to lora_module_enum and loraModules map - Add lr2021_max_power, lr2021_max_power_hf, lr2021_irq_dio_num config fields - Parse LR2021_MAX_POWER, LR2021_MAX_POWER_HF, IRQ_DIO_NUM (and LR2021_IRQ_DIO_NUM alias) from YAML - Use LR2021::MODE_* enums for rfswitch_table when module is lr2021 (LR2021 has MODE_RX_HF at value 4 where LR11x0 has MODE_TX_HP; no MODE_GNSS/MODE_WIFI) - Parse MODE_RX_HF YAML key for LR2021 configs instead of MODE_TX_HP - Branch YAML serialization on use_lr2021 so configs round-trip correctly LR20x0Interface (radio driver): - Set irqDioNum BEFORE lora.begin() so config() programs the correct DIO for IRQ routing. Setting it after begin() is too late - config() has already configured DIO5 as IRQ, then setRfSwitchTable() overrides it to RF_SWITCH, breaking all radio interrupts. This is the fix for the DIO5 IRQ/RF-switch conflict that caused meshtasticd to crash (SIGABRT/segfault) on TX when DIO5 is used for both IRQ and RF switch control. - Add ARCH_PORTDUINO path for reading irqDioNum from config - Add LR20X0_RFSWITCH_NATIVE guard for variant-defined RF switch tables LR11x0Interface (symbol namespacing): - Namespace RF switch symbols as lr11x0_rfswitch_* to prevent collisions when LR11x0 and LR20x0 templates share a translation unit (InterfacesTemplates.cpp). Removes the old #undef hack. RadioInterface: - Add case use_lr2021 to construct LR2021Interface in portduino mode - Guard hardcoded SPI pin fallback with !defined(ARCH_PORTDUINO) ProMicro rfswitch.h: - Add per-table include guards (RFSWITCH_NRF52TCXO_LR11X0_DEFINED, RFSWITCH_NRF52TCXO_LR20X0_DEFINED) to prevent redefinition - Nest #ifdef USE_LR1121 / #ifdef USE_LR2021 inside include guards so tables are only emitted when their radio is built - Add LR20X0_RFSWITCH_NATIVE define so LR20x0Interface uses the variant's native lr20x0_rfswitch_* symbols - Add explanatory comment for DIO7 (in pin array for matrix completeness, never driven HIGH on this variant) Native build config: - Add -D USE_LR2021 to portduino.ini build flags Sample configs: - lora-femtofox_LR2021_TCXO.yaml: SPI/GPIO config for Luckfox Pico Mini with GNiceRF LoRa2021F33-2G4 module (DIO3 TCXO, DIO5-8 RF switch, IRQ_DIO_NUM: 9 to avoid DIO5 conflict) - lora-usb-meshtoad-nicerflora2021f33.yaml: USB/CH341 config for NiceRF LoRa2021F33 module Co-authored-by: jessm33 <112707725+jessm33@users.noreply.github.com> Ref: meshtastic#10567 (portions of LR11x0 symbol namespacing, ProMicro rfswitch.h guards, and USB config YAML adapted from this PR)
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/platform/portduino/PortduinoGlue.cpp (2)
1005-1006: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winRegister
MODE_RX_HFas an RX_HF table entry.Slot 3 is initialized at Line 976 as
LR11x0::MODE_TX_HP, but these lines writeMODE_RX_HFvalues into that slot. Consequently, LR20x0/ LR2021 will not have a table entry matchingMODE_RX_HF; initialize the table with the LR20x0 mode (LR20x0::MODE_RX_HF) for that radio family instead of reusing the LR11x0 TX_HP slot.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platform/portduino/PortduinoGlue.cpp` around lines 1005 - 1006, Update the rfswitch table initialization near slot 3 so the LR20x0/LR2021 radio family registers that slot with LR20x0::MODE_RX_HF rather than LR11x0::MODE_TX_HP, while preserving the existing MODE_RX_HF value assignments.
902-909: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUse a safe LR2021 HF-power default and enforce the hardware limit.
lr2021_max_power_hfdefaults to 22, butLR20x0Interfaceapplies this value directly for theLORA_24region, whose documented hardware maximum is 12 dBm. If the YAML omitsLR2021_MAX_POWER_HF, the radio can be configured above its safe limit. Default this field to 12 and reject or clamp larger configured values.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platform/portduino/PortduinoGlue.cpp` around lines 902 - 909, The LR2021 HF power configuration in PortduinoGlue must default to the hardware-safe 12 dBm limit and prevent YAML values above that limit. Update the LR2021_MAX_POWER_HF assignment in the configuration-loading code to use 12 as its fallback and reject or clamp larger configured values before storing them in portduino_config.lr2021_max_power_hf.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/platform/portduino/PortduinoGlue.cpp`:
- Around line 1005-1006: Update the rfswitch table initialization near slot 3 so
the LR20x0/LR2021 radio family registers that slot with LR20x0::MODE_RX_HF
rather than LR11x0::MODE_TX_HP, while preserving the existing MODE_RX_HF value
assignments.
- Around line 902-909: The LR2021 HF power configuration in PortduinoGlue must
default to the hardware-safe 12 dBm limit and prevent YAML values above that
limit. Update the LR2021_MAX_POWER_HF assignment in the configuration-loading
code to use 12 as its fallback and reject or clamp larger configured values
before storing them in portduino_config.lr2021_max_power_hf.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9d289ac8-21a9-418b-9fec-26682759c5f8
📒 Files selected for processing (1)
src/platform/portduino/PortduinoGlue.cpp
… screen from config. Requires meshtastic/device-ui#355 and supersedes #10567 and #11138 Many thanks to the original authors https://github.com/a-li3n and https://github.com/jessm33
… screen from config. Requires meshtastic/device-ui#355 and supersedes #10567 and #11138 Many thanks to the original authors https://github.com/a-li3n and https://github.com/jessm33
Changes to enable lr2021 LoRA radio support on native platform, including a few new config options for the lr2021, sample config files for ch341 are provided.
🤝 Attestations
Summary by CodeRabbit
Summary
New Features
use_lr2021Portduino module option to auto-select the LR2021 interface.Bug Fixes
MODE_RX_HF(“HIGH”) handling.Refactor