Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6960

General • Pico 2 W freezes with lwip and SX1262

$
0
0
Hi,
I started a little project with a Pico 2 W and a Waveshare SX1262 Pico hat (https://www.waveshare.com/wiki/Pico-LoRa-SX1262).
The Pico is supposed to receive a message over lora radio and then relay it over wifi.
For lora I use Radiolib (https://github.com/jgromes/RadioLib). For wifi I use the background task version of lwip.
I was able to get wifi and lora working individually but I face some issues when I want to combine them:

The lora radio chip is supposed to trigger an IRQ on GPIO pin 20 when a message is received. Without wifi it works.
But as soon as I activate Wifi the Pico seems to freeze. By that I mean that it won't toogle LEDs or send printf anymore, as if it is stuck in an infinite loop. Not really sure what is going or how I could debug it.

I could trace down the issue to the IRQ attached to pin 20. I did following testing:
- Wifi + IRQ on GPIO is working
- Wifi + Lora without IRQ is working. This solution is using a blocking receive.
- Wifi + Lora with IRQ --> Pico freezes as soon as the IRQ gets configured.

I also tested
- everything above with a different pin that is not connected at all to the lora modules (gpio 19), but with the same result...
- using the polling version of the wifi lib


I am out of ideas...

Code:

#include <stdio.h>#include "pico/stdlib.h"#include "pico/cyw43_arch.h"#include "lora.h"#define IRQ_GPIO 19void gpio_callback(uint gpio, uint32_t events) {    // Check for the correct GPIO and a falling edge event.    if (gpio == IRQ_GPIO && (events & GPIO_IRQ_EDGE_RISE)) {        printf("IRQ on GPIO %u\n",IRQ_GPIO);        gpio_acknowledge_irq(gpio, events);    }}void setup_irq(){    gpio_init(IRQ_GPIO);    gpio_set_dir(IRQ_GPIO, GPIO_IN);    gpio_pull_down(IRQ_GPIO);    gpio_set_irq_enabled_with_callback(        IRQ_GPIO,                               GPIO_IRQ_EDGE_RISE,                true,                              &gpio_callback                 );}int main(){    stdio_init_all();    printf("Connecting to Wi-Fi...\n");    cyw43_arch_init();    cyw43_arch_enable_sta_mode();      cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PWD, CYW43_AUTH_WPA2_AES_PSK, 30000);    printf("lora_init\n");    lora_init();    printf("setup_irq\n");    //attach an IRQ to a free pin for testing...it will freeze here    setup_irq();    printf("Entering while loop\n");    while (true) {        printf("Hello, world!\n");        sleep_ms(1000);    }}

Code:

#include <pico/stdlib.h>#include <RadioLib.h>#include "hal/RPiPico/PicoHal.h"#include "lora.h"#define SPI_PORT spi1  // Pico spi#define RADIO_RESET 15 // Reset#define RADIO_MOSI 11  // SPI MOSI#define RADIO_MISO 12  // SPI MISO#define RADIO_SCLK 10  // SPI Clock#define RADIO_NSS 3    // Chip select#define RADIO_BUSY 2   // Busy#define RADIO_DIO_1 20 // IRQ pinstatic PicoHal hal(SPI_PORT, RADIO_MISO, RADIO_MOSI, RADIO_SCLK);static Module module(&hal, RADIO_NSS, RADIO_DIO_1, RADIO_RESET, RADIO_BUSY);static SX1262 radio(&module);extern "C"{  void lora_init()  {    printf("Initialising Lora...");    int state = radio.begin(        868.0F, //frequency        125.0F, //bandwidth        9U,     //spreading factor        5U,     //coding rate        0x12,   //sync word        10,     //power        8U,     //preamble length        1.6F,   //tcxo voltage        false   //don't use LDO      );    if (state != RADIOLIB_ERR_NONE)    {      printf("failed, code %d\n", state);    }    printf("success!\n");  }}

Code:

#ifndef __LORA_H__#define __LORA_H__#ifdef __cplusplusextern "C" {#endifvoid lora_init();#ifdef __cplusplus}#endif#endif // __LORA_H__

Statistics: Posted by ole12345! — Sun Jul 20, 2025 3:45 pm — Replies 0 — Views 47



Viewing all articles
Browse latest Browse all 6960

Trending Articles