Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radio.begin() hangs on raspberry pi pico since b5a905b #899

Closed
felher opened this issue Mar 2, 2023 · 6 comments
Closed

radio.begin() hangs on raspberry pi pico since b5a905b #899

felher opened this issue Mar 2, 2023 · 6 comments
Labels

Comments

@felher
Copy link

felher commented Mar 2, 2023

Hey all!

When using the library on my raspbery pi pico, calling radio.begin() hangs forever. This was not always the case. I used a former version of this library in an older project and it worked fine. I run a git bisect with the version I had used in the old project and it seems that since commit b5a905b, calling radio.begin() just hangs.

Here is a minmal code example:

#define CE_PIN 7
#define CSN_PIN 8
#define IRQ_PIN 6

#include <RF24.h> // RF24 radio object

RF24 radio(CE_PIN, CSN_PIN);

int main() {
  const uint8_t LED_PIN = 25;
  stdio_init_all();
  gpio_init(LED_PIN);
  gpio_set_dir(LED_PIN, GPIO_OUT);

  radio.begin();

  while (true) {
    gpio_put(LED_PIN, 1);
    sleep_ms(100);
    gpio_put(LED_PIN, 0);
    sleep_ms(100);
  }
}

I did expect to see blinking, but I'm not seeing any. If I remove the radio.begin() line, the LED starts to blink again. If I reset library to a version before b5a905b I can leave radio.begin() in and it works fine.

I'm not an expert by any stretch, so this might well be an misunderstanding/mistake on my part. If so, I apologize for the spurious bug report

@2bndy5
Copy link
Member

2bndy5 commented Mar 3, 2023

There isn't any loops in RF24::begin() that would cause a hang. So I think this may be related to the arduino-wrapping SPI code that uses the PicoSDK's spi_write_read_blocking().

The only reason I can think of is if the specified SPI bus interface isn't initialized correctly (via spi_init() from our wrapping function SPI::beginTransaction()).

I'm not at home yet, but soon I'll spin up 1 of our lib's examples_pico binaries to try and reproduce.

@2bndy5
Copy link
Member

2bndy5 commented Mar 3, 2023

The mentioned commit neglects

static SPI spi;

which is the SPI instance that RF24 uses by default.

Maybe, the removal of static attributes requires the object be instantiated like so

SPI spi = SPI();

@2bndy5 2bndy5 added the bug label Mar 3, 2023
@2bndy5
Copy link
Member

2bndy5 commented Mar 3, 2023

yep, we didn't thoroughly test the default RF24::begin() from that commit... I got it working with the following patch:

diff --git a/RF24.cpp b/RF24.cpp
index c0ceef8a..68144a25 100644
--- a/RF24.cpp
+++ b/RF24.cpp
@@ -999,6 +999,7 @@ bool RF24::begin(void)
     _spi->begin(csn_pin);

 #elif defined(RF24_RP2)
+    _spi = new SPI();
     _spi->begin(PICO_DEFAULT_SPI ? spi1 : spi0);

 #else // using an Arduino platform || defined (LITTLEWIRE)
diff --git a/utility/rp2/RF24_arch_config.h b/utility/rp2/RF24_arch_config.h
index 7d5a1a93..3f24e949 100644
--- a/utility/rp2/RF24_arch_config.h
+++ b/utility/rp2/RF24_arch_config.h
@@ -28,8 +28,6 @@
 #define _SPI   SPI
 #define RF24_SPI_PTR

-static SPI spi;
-
 #ifdef SERIAL_DEBUG
     #define IF_SERIAL_DEBUG(x) ({ x; })
 #else

However, I'm not receiving any data, only sending data works. This might be a separate issue with my RPi4 setup, so I'll try again with a different device... I'm testing the examples_pico/getting_started.cpp on my Feather RP2040.

@2bndy5 2bndy5 closed this as completed in 557d165 Mar 3, 2023
@2bndy5
Copy link
Member

2bndy5 commented Mar 3, 2023

However, I'm not receiving any data, only sending data works

It wasn't my RPi setup, it was the adapter board I had connecting my nRF24 module to my Feather RP2040. This above patch works fine to fix this regression

@felher I pushed the fix to the master branch, so you should be good to go now

@felher
Copy link
Author

felher commented Mar 3, 2023

Holy moly, this was fast! Thank you!

@TMRh20
Copy link
Member

TMRh20 commented Mar 3, 2023

That was fast! You rock @2bndy5

2bndy5 pushed a commit that referenced this issue Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants