From 3f03aaa404fbf95ef519d2c2be35e97c57a83574 Mon Sep 17 00:00:00 2001 From: "ANLO.PO" Date: Thu, 26 Mar 2026 10:07:01 +0100 Subject: [PATCH] waveshare_rp2040_lora: fix radio init and antenna switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, radio initialization failed with "ERROR: radio init failed: -2" (RADIOLIB_ERR_CHIP_NOT_FOUND), meaning the SX1262 chip was not responding over SPI. Fix 1 - SPI initialization (target.cpp): The original code manually configured SPI1 pins and called SPI1.begin(false) before passing NULL to std_init(), which skips SPI setup inside std_init. This approach failed because the RP2040 SPI hardware did not properly communicate with the radio using this sequence. Replaced with radio.std_init(&SPI1), which is the same pattern used by other working RP2040 variants in this project (rak11310, rpi_picow). std_init(&SPI1) internally calls SPI1.setMISO/setSCK/setMOSI and SPI1.begin(), then RadioLib's Module::init() overrides the CS pin to GPIO output mode for manual software-controlled chip select — which is the correct and tested initialization order for RP2040. Fix 2 - Antenna switch RXEN pin (platformio.ini): Added -D SX126X_RXEN=17 (GPIO17 / DIO4). The Waveshare RP2040-LoRa uses a PE4259 antenna switch with complementary control logic: DIO2 (via SX126X_DIO2_AS_RF_SWITCH) drives the CTRL signal, and GPIO17 must drive the inverted !CTRL signal. Without RXEN defined, GPIO17 was left floating, causing the antenna switch to remain in an undefined state during TX/RX. Fix 3 - BLE library excluded (platformio.ini): Added lib_ignore = BLE. PlatformIO's Library Dependency Finder automatically picked up the BLE library from the earlephilhower framework and attempted to compile it, resulting in a build error: "static assertion failed: This library needs Bluetooth enabled." The Waveshare RP2040-LoRa has no Bluetooth hardware, so BLE must be explicitly excluded from the build. Co-Authored-By: Claude Sonnet 4.6 --- variants/waveshare_rp2040_lora/platformio.ini | 2 ++ variants/waveshare_rp2040_lora/target.cpp | 12 +----------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/variants/waveshare_rp2040_lora/platformio.ini b/variants/waveshare_rp2040_lora/platformio.ini index 1f7fb02f1b..54b0d865fc 100644 --- a/variants/waveshare_rp2040_lora/platformio.ini +++ b/variants/waveshare_rp2040_lora/platformio.ini @@ -20,6 +20,7 @@ build_flags = ${rp2040_base.build_flags} -D P_LORA_MOSI=15 -D P_LORA_TX_LED=25 -D SX126X_DIO2_AS_RF_SWITCH=true + -D SX126X_RXEN=17 -D SX126X_DIO3_TCXO_VOLTAGE=0 -D SX126X_RX_BOOSTED_GAIN=1 -D LORA_TX_POWER=22 @@ -33,6 +34,7 @@ build_src_filter = ${rp2040_base.build_src_filter} + +<../variants/waveshare_rp2040_lora> lib_deps = ${rp2040_base.lib_deps} +lib_ignore = BLE [env:waveshare_rp2040_lora_repeater] extends = waveshare_rp2040_lora diff --git a/variants/waveshare_rp2040_lora/target.cpp b/variants/waveshare_rp2040_lora/target.cpp index 459bf82c35..5d1ee33882 100644 --- a/variants/waveshare_rp2040_lora/target.cpp +++ b/variants/waveshare_rp2040_lora/target.cpp @@ -15,17 +15,7 @@ SensorManager sensors; bool radio_init() { rtc_clock.begin(Wire); - SPI1.setSCK(P_LORA_SCLK); - SPI1.setTX(P_LORA_MOSI); - SPI1.setRX(P_LORA_MISO); - - pinMode(P_LORA_NSS, OUTPUT); - digitalWrite(P_LORA_NSS, HIGH); - - SPI1.begin(false); - - //passing NULL skips init of SPI - return radio.std_init(NULL); + return radio.std_init(&SPI1); } uint32_t radio_get_rng_seed() {