Implement Dormant Mode for RPi Pico with Arduino and Pico-SDK

Hello,

I’m relatively new to the embedded systems domain and I’m trying to enable low power mode on my RPi Pico. I’ve found resources indicating that this can be achieved using the Pico-SDK (source1, source2). As such, I’ve decided to use this branch
https://github.com/maxgerhardt/platform-raspberrypi.git which integrates both the Arduino framework and the Pico-SDK. I plan to include the <pico/sleep.h> and <hardware/rosc.h> headers and implement a solution similar to this one: https://github.com/earlephilhower/arduino-pico/issues/345#issuecomment-1465131731. Apologies, as a new user, I’m limited to including only two links in a post.

This is my platformio.ini file:

platform = https://github.com/maxgerhardt/platform-raspberrypi.git 
board = pico
framework = arduino

board_build.core = earlephilhower
board_build.mcu = rp2040
board_build.f_cpu = 133000000L
board_microros_distro = humble
board_microros_transport = serial

upload_port = /media/pk/RPI-RP2
monitor_speed = 115200

lib_ldf_mode = chain+
lib_deps =
    https://github.com/micro-ROS/micro_ros_platformio#2.0.0
    https://github.com/adafruit/Adafruit_Sensor#1.1.7
    https://github.com/adafruit/Adafruit_BNO055#1.6.1

However, I’m facing a couple of challenges:

  • Is my approach to using the SDK functionalities correct or is there a better alternative that I might have missed?

  • If this is the right approach, I need to add the hardware_rosc and pico_sleep libraries. How can I do this? I understand they are part of pico-extras, but how can I incorporate them into my PlatformIO project?

Any guidance would be greatly appreciated.

Thank you.

If you want to keep using the Arduino framework in general, yes that’s right. The other way to use it by creating a Pico-SDK only project, using e.g. https://github.com/maxgerhardt/wizio-pico. This is however not updated anymore so you’d better use the native Pico-SDK CMake tooling instead.

You should be able to just copy-paste the source code files in the lib folder of the project, that is hardware_rosc as lib/hardware_rosc and pico_sleep to lib/pico_sleep.

FYI, if it was something in the Pico-SDK that you needed but Arduino-Pico didn’t include, the way to go would have been to modify the build files that generate libpico.a. Since this is in Pico-Extras however, this does not apply.

Also notable is that per https://github.com/earlephilhower/arduino-pico/discussions/1544, there already is an Arduino library for it: https://github.com/matthias-bs/arduino-pico-sleep

1 Like

Hi,
Thank you for your prompt and insightful response. I’ve copied pico-extras to the lib directory and am now using these two functions:

sleep_run_from_xosc(); 
sleep_goto_dormant_until_edge_high(POWER_BTN);

This works well and my Pico is now consuming very low power. However, I had to remove this line from pico_sleep.c because the setup_default_uart() function was not declared. This modification has caused my Serial communication to stop working after waking up. I’m still a bit unclear about the roles of Arduino-pico and Pico-SDK :stuck_out_tongue:

After switching to your platform-raspberrypi fork, my arduino::UART disappeared. Without giving it much thought, I decided to use SerialUART. It usually works well, but due to the absence of function I mentioned before, it doesn’t work after waking up.

What is the optimal method to restart SerialUART and any other required components without having to reset the entire microcontroller?

I think that’s a thing only in ArduinoCore-mbed, not Arduino-Pico?

It should have the Arduino-standard Serial.end(); and Serial.begin(); functions, no?