Skip to content

RP2040 example#4

Open
matthias-bs wants to merge 2 commits intoradiolib-org:mainfrom
matthias-bs:main
Open

RP2040 example#4
matthias-bs wants to merge 2 commits intoradiolib-org:mainfrom
matthias-bs:main

Conversation

@matthias-bs
Copy link

@matthias-bs matthias-bs commented May 4, 2024

This is a working example for RP2040. Persistent storage is implemented using https://github.com/vshymanskyy/Preferences and putting a few variables into the .uninitialized_data RAM section. The watchdog scratch register 1 is used to keep track of the boot count and for initial initialization after HW reset.
Resuming normal operation after wake-up is possible, but currently does not work presumably due to incorrect restoring of clock configurations. As a workaround, a soft reset is performed after wake-up.

@StevenCellist
Copy link
Collaborator

Hi @matthias-bs, thanks for contributing! Lovely to see an RP2040 example appear here. I personally have a Pico + SX1262 hat in a box somewhere, I'll take it out for a spin early next week to check your example!
Interestingly, jgromes/RadioLib#1086 also just appeared on the main repo; will have a look at the differences in pin-selection as well, as there appears to be some difference at first glance. But first: weekend :)

@matthias-bs
Copy link
Author

matthias-bs commented May 6, 2024

Hi @StevenCellist ,
the pin selection will be different, because my example uses the Adafruit Radio FeatherWing, which needs some jumper wires on the FeatherWing board for connection between the radio chip and the Feather interface to the MCU. Therefore, the wiring is partly user-defined.

@StevenCellist
Copy link
Collaborator

@matthias-bs finally managed to setup my VS Code / PlatformIO to work nicely with this repo, but I am having include errors on some of the pico source files (e.g. stdio). Do you use PIO? If so, could you please share your .ini file? I expect you're using Philhower's version, or not?

@Velocet
Copy link

Velocet commented May 10, 2024

Which extensions do you use besides PIO and the Microsoft C++ extension?
Try rebuilding the compile_commands.json and the IntelliSense cache. Have a look at this config. Hope it helps 👌🏻

platformio.ini

You can also use the clangd extension. Ignore the warnings...

@StevenCellist
Copy link
Collaborator

@Velocet I don't see any Pico/RP2040 environment there.. the problem is not with PIO itself, but I think with the possible platforms against which you can build Pico/RP2040 sketches.

@Velocet
Copy link

Velocet commented May 10, 2024

Hm.. i had the same issues as you described thats why i thought it is worth a try.

Those settings normally sit in .vscode/c_cpp_properties*. Have you checked if the necessary includes are in there?

@StevenCellist
Copy link
Collaborator

StevenCellist commented May 10, 2024

I used this which is PIO's default for the Pico:

[env:pico]
platform = raspberrypi
board = pico
framework = arduino

Not much to see in the file you mentioned, except that it looks at RASPBERRY_PI_PICO in framework-arduino-mbed/variants folder in the PIO packages.

@matthias-bs
Copy link
Author

@matthias-bs finally managed to setup my VS Code / PlatformIO to work nicely with this repo, but I am having include errors on some of the pico source files (e.g. stdio). Do you use PIO? If so, could you please share your .ini file? I expect you're using Philhower's version, or not?

Yes, I'm using Earle Philhower's version with Arduino IDE and VSCode with the Arduino Extension.

@StevenCellist
Copy link
Collaborator

Some hacking about later, I can now compile your sketch from PlatformIO.

@StevenCellist
Copy link
Collaborator

Had to pull some lines from jgromes/RadioLib#1086 to get SPI1 going - which is not a problem for your Feather which you've probably wired to SPI0.
While testing, I noticed that my Pico doesn't seem to wake up / reset. Says it is going to sleep for 60 seconds, RTC scheduled wakeup time is indeed 1 minute later, but just hangs. @matthias-bs or @Velocet any experience with this? For reference, my platformio.ini looks like this:

[env]
framework = arduino
lib_deps = 
	jgromes/RadioLib@6.5.0
build_flags = 
    -D RADIOLIB_DEBUG_BASIC=1
	-D RADIOLIB_DEBUG_PROTOCOL=1
extra_scripts = 
	pre:scripting/find_ino.py

[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
board_build.core = earlephilhower
board_build.filesystem_size = 1m
upload_protocol = picotool
monitor_speed = 115200
monitor_filters = time
build_src_filter = 
	-<*>
	+<LoRaWAN_RP2040/>
lib_deps = 
    ${env.lib_deps}
    vshymanskyy/Preferences@^2.1.0

And last few lines of output:

00:46:03.345 > RLB_PRO: [MAC] 0x06
00:46:03.345 > RLB_PRO: DevStatusReq
00:46:03.345 > RLB_PRO: DevStatusAns: status = 0x08ff
00:46:03.345 > FcntUp: 0
00:46:03.345 > Sleeping for 60 seconds
00:46:03.445 > RTC time:1970-01-01 00:00:01
00:46:03.446 > Wakeup time:1970-01-01 00:01:01

@Velocet
Copy link

Velocet commented May 16, 2024

Sadly no. I'm mostly into ESP32 and STM32.
But the ini looks good so far

@matthias-bs
Copy link
Author

matthias-bs commented May 16, 2024

@StevenCellist I can only tell that this example works for me. I checked if there is anything special regarding the board I used (such as an extra RTC clock - which is not present), but I didn't find anything.

I've made the experience that the RTC part is tricky, too. First you have to enable it, then you have to ensure that it is initialized with valid data and finally you have to ensure that the wake-up time is set correctly. And of course, you have to take care that it is still running in sleep mode. Many potential sources for errors...

Is this specific for PlatformIO? Did you try it with Arduino IDE?

@StevenCellist
Copy link
Collaborator

Missed the edit, currently installing Philhower's core for Arduino IDE. Can you share your config for Arduino IDE: board, tools and other things that may be of importance?

@StevenCellist
Copy link
Collaborator

@matthias-bs still no luck with the Arduino IDE. Note that I have a Pico W. Can you share all possible details on your board and configuration?

@matthias-bs
Copy link
Author

matthias-bs commented Jun 8, 2024

@StevenCellist Certainly!
Hardware
Adafruit Feather RP2040
Adafruit LoRa Radio Featherwing 900 MHz - Wiring: A to RST, B to DIO1, D to DIO0, E to CS

Software
Arduino IDE 2.3.2
Raspberry Pi Pico/RP2040 Package 3.9.2 by Earle Philhower

grafik

Libraries
RadioLib 6.5.0
Preferences 2.1.0

@matthias-bs
Copy link
Author

matthias-bs commented Jun 8, 2024

Compile Log
radiolib_persistence_rp2040_compile.log

Serial Console Log

17:17:04.013 -> FcntUp: 0
17:17:04.013 -> Sleeping for 300 seconds
17:17:04.110 -> RTC time:1970-01-01 00:00:01
17:17:04.110 -> Wakeup time:1970-01-01 00:05:01
17:22:06.879 -> 
17:22:06.879 -> Setup
17:22:06.880 -> Initalise the radio
17:22:06.880 -> Recalling LoRaWAN nonces & session
17:22:06.880 -> 
17:22:06.880 -> lfs_file_close: fd=0x20003bec
17:22:06.911 -> lfs_file_close: fd=0x20003bec
17:22:06.911 -> Setup LoRaWAN session
17:22:06.911 -> Sending uplink
17:22:13.408 -> FcntUp: 1
17:22:13.408 -> Sleeping for 300 seconds
17:22:13.505 -> RTC time:1970-01-01 00:00:01
17:22:13.505 -> Wakeup time:1970-01-01 00:05:01
17:27:16.337 -> 
17:27:16.337 -> Setup
17:27:16.337 -> Initalise the radio
17:27:16.337 -> Recalling LoRaWAN nonces & session
17:27:16.337 -> 
17:27:16.337 -> lfs_file_close: fd=0x20003bec
17:27:16.337 -> lfs_file_close: fd=0x20003bec
17:27:16.337 -> Setup LoRaWAN session
17:27:16.370 -> Sending uplink
17:27:22.874 -> FcntUp: 2
17:27:22.874 -> Sleeping for 300 seconds
17:27:22.971 -> RTC time:1970-01-01 00:00:01
17:27:22.971 -> Wakeup time:1970-01-01 00:05:01

TTN Uplink

DEADBEEF
{
  "name": "as.up.data.forward",
  "time": "2024-06-08T15:16:58.918807221Z",
  "identifiers": [
    {
      "device_ids": {
        "device_id": "eui-0c8b95aab05cfeff",
        "application_ids": {
          "application_id": "pv-inverter"
        },
        "dev_eui": "0C8B95AAB05CFEFF",
        "join_eui": "0000000000000000",
        "dev_addr": "260B057A"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.ApplicationUp",
    "end_device_ids": {
      "device_id": "eui-0c8b95aab05cfeff",
      "application_ids": {
        "application_id": "pv-inverter"
      },
      "dev_eui": "0C8B95AAB05CFEFF",
      "join_eui": "0000000000000000",
      "dev_addr": "260B057A"
    },
    "correlation_ids": [
      "gs:uplink:01HZW6S76GFJE66NSZK34R0XE3"
    ],
    "received_at": "2024-06-08T15:16:58.912861325Z",
    "uplink_message": {
      "session_key_id": "AY/4bIFiGoCY9jm8/9B/gw==",
      "f_port": 1,
      "frm_payload": "3q2+7w==",
      "rx_metadata": [
        {
          "gateway_ids": {
            "gateway_id": "lora-db0fc",
            "eui": "3135323538002400"
          },
          "time": "2024-06-08T15:16:58.469638Z",
          "timestamp": 3492535740,
          "rssi": -109,
          "channel_rssi": -109,
          "snr": -7,
          "location": {
            "latitude": 52.27640735,
            "longitude": 10.54058183,
            "altitude": 65,
            "source": "SOURCE_REGISTRY"
          },
          "uplink_token": "ChgKFgoKbG9yYS1kYjBmYxIIMTUyNTgAJAAQvLuvgQ0aDAjq65GzBhDg3JjPAiDgzOja0qpn",
          "channel_index": 7,
          "received_at": "2024-06-08T15:16:58.683315074Z"
        }
      ],
      "settings": {
        "data_rate": {
          "lora": {
            "bandwidth": 125000,
            "spreading_factor": 10,
            "coding_rate": "4/5"
          }
        },
        "frequency": "867900000",
        "timestamp": 3492535740,
        "time": "2024-06-08T15:16:58.469638Z"
      },
      "received_at": "2024-06-08T15:16:58.704908384Z",
      "consumed_airtime": "0.329728s",
      "network_ids": {
        "net_id": "000013",
        "ns_id": "EC656E0000000181",
        "tenant_id": "ttn",
        "cluster_id": "eu1",
        "cluster_address": "eu1.cloud.thethings.network"
      }
    }
  },
  "correlation_ids": [
    "gs:uplink:01HZW6S76GFJE66NSZK34R0XE3"
  ],
  "origin": "ip-10-100-14-82.eu-west-1.compute.internal",
  "context": {
    "tenant-id": "CgN0dG4="
  },
  "visibility": {
    "rights": [
      "RIGHT_APPLICATION_TRAFFIC_READ"
    ]
  },
  "unique_id": "01HZW6S7D6WQCDMD8JH3WSNVWS"
}

(No suitable payload formatter in place... :-) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants