raspberrypi / pico-feedback

25 stars 2 forks source link

Low Power modes - Do they actually work? #415

Open seamusdemora opened 5 days ago

seamusdemora commented 5 days ago

Personal experience w/ Pico: I've read (most of) the documentation, and posted a couple of pico-related issues here on github. I've also built several of examples, and have successfully "used" a couple of the i2c examples to create a fully functional Pico application/library that controls an INA260 "Power Monitor".

I use the Pico C SDK almost exclusively in my development; I have used the Earl Philhower Arduino-Pico environment to help me understand a few things wrt I2C. The Pico SDK is installed on my RPi 5 (bookworm Lite), and I do everything from there. I do not use any of the "VS" stuff (quit MS years ago, and ain't goin' back!), GUIs, etc.

My Issue: Based on my "success" with the INA260, I'm interested in using the Pico (2040) in an "off-grid" application; i.e. a small solar cell & battery, in a remote location).

Unfortunately, I can't seem to reach "second base" in this endeavor. I have been able to successfully compile and run the "hello_dormant" example in "pico-playground", but I've been unable to set it up as a stand-alone app as described in the section "Manually Create your own Project" of the "Getting Started ..." guide. I do not know what I am missing exactly!

I gather the delegation of sleep and dormant to the 'pico-playground' and 'pico-extras' repos is due to their "NRPT" (Not Ready for Prime Time) status?? But the sleep and dormant examples have been in this state for 3 years now according to the GitHub stats! Isn't it about time these examples were "fleshed out and documented"? Frankly, this makes me wonder if the issues are a failing of the low power facilities of the RP2040 - or workload of the RPi staff?

Not to nit pick, but there are what seem to be clear issues in the documentation:

From: raspberry-pi-pico-c-sdk-2024-08-21.pdf, para '4.2.1.3.2. aon_timer_enable_alarm': On RP2040 The alarm will not fire if it is in the past On RP2040 The alarm will fire if it is in the past

How about it then?... Will the sleep and dormant examples be brought out of the purgatory of 'pico-playground' and 'pico-extras' any time in the near future? And I would really appreciate some help in the meantime on how to set up these examples outside that purgatory; i.e. in ~/pico/MySleepAndDormantProject.

Thanks for listening.

kilograham commented 5 days ago

They are indeed coming soon - they didn't quite make it in with SDK2.0.0

In the meanwhile, you need to include pico_extras in your project as that's where hardware_sleep is

So, something like

# Pull in PICO SDK (must be before project)
include(pico_sdk_import.cmake)

# We also need PICO EXTRAS
include(pico_extras_import.cmake)
lurch commented 5 days ago

Not to nit pick, but there are what seem to be clear issues in the documentation:

From: raspberry-pi-pico-c-sdk-2024-08-21.pdf, para '4.2.1.3.2. aon_timer_enable_alarm': On RP2040 The alarm will not fire if it is in the past On RP2040 The alarm will fire if it is in the past

Looks like that was a typo, well spotted. https://github.com/raspberrypi/pico-sdk/pull/1945 should fix that.

seamusdemora commented 5 days ago

Thanks so much!!

But now I've got another problem - hoping you can offer some advice:

I've been thrashing about trying to get the dormant example working. In the meantime, my "other project" (the INA260 project at ~/pico/ina260_i2c/build) which has been working perfectly well (as of yesterday) is now having openocd failures:

$ sudo openocd -d2 -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program ina260_trial.elf verify reset exit"
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-02-11-10:09)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz

Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E6616408432C1933
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked

I suspected a wiring/connection issue initially, but I've been over the wiring 3 times now. I'm using a "Debug Probe", and that seems to be working OK (red LED is ON, wiring looks OK). The openocd command shown above is the exact same one I've been using for about a year now. I'm baffled! None of the files referenced in the openocd command have been changed (I checked), and none of the files in ~/pico/ina260_i2c/build have been changed AFAIK. I've re-booted, halted, switched USB connections - nothing seems to make any difference.

I know openocd is not an RPi product, but hoping you can offer some advice. My Internet searches have turned up "zilch".

seamusdemora commented 5 days ago

They are indeed coming soon - they didn't quite make it in with SDK2.0.0

That's very good to hear!

In the meanwhile, you need to include pico_extras in your project as that's where hardware_sleep is

So, something like

# Pull in PICO SDK (must be before project)
include(pico_sdk_import.cmake)

# We also need PICO EXTRAS
include(pico_extras_import.cmake)

Uh - where do those changes go exactly? I tried adding them to ~/pico/sleep_dormant/CMakeLists.txt, but here's the result:

$ pwd
~/pico/sleep_dormant/build
$ make -j2
PICO_SDK_PATH is /home/pi/pico/pico-sdk
Target board (PICO_BOARD) is 'pico'.
Using board configuration from /home/pi/pico/pico-sdk/src/boards/include/boards/pico.h
Pico Platform (PICO_PLATFORM) is 'rp2040'.
CMake Error at CMakeLists.txt:6 (include):
  include could not find requested file:

    pico_extras_import.cmake

Build type is Release
TinyUSB available at /home/pi/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
BTstack available at /home/pi/pico/pico-sdk/lib/btstack
cyw43-driver available at /home/pi/pico/pico-sdk/lib/cyw43-driver
lwIP available at /home/pi/pico/pico-sdk/lib/lwip
mbedtls available at /home/pi/pico/pico-sdk/lib/mbedtls
Using PICO_EXAMPLES_PATH from environment ('/home/pi/pico/pico-examples')
-- Configuring incomplete, errors occurred!
See also "/home/pi/pico/sleep_dormant/build/CMakeFiles/CMakeOutput.log".
See also "/home/pi/pico/sleep_dormant/build/CMakeFiles/CMakeError.log".
make: *** [Makefile:2184: cmake_check_build_system] Error 1

But then ...

$ find ~/pico -type f -iname "pico_extras_import.cmake"
/home/pi/pico/pico-extras/external/pico_extras_import.cmake
/home/pi/pico/pico-playground/pico_extras_import.cmake

# and then editing `~/pico/sleep_dormant/CMakeLists.txt` to change 
# FROM: include(pico_extras_import.cmake)
# TO:      include(/home/pi/pico/pico-playground/pico_extras_import.cmake)

$ pwd
~/pico/sleep_dormant/build
$ $ make -j2
PICO_SDK_PATH is /home/pi/pico/pico-sdk
Target board (PICO_BOARD) is 'pico'.
Using board configuration from /home/pi/pico/pico-sdk/src/boards/include/boards/pico.h
Pico Platform (PICO_PLATFORM) is 'rp2040'.
Using PICO_EXTRAS_PATH from environment ('/home/pi/pico/pico-extras')
Build type is Release
TinyUSB available at /home/pi/pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
BTstack available at /home/pi/pico/pico-sdk/lib/btstack
cyw43-driver available at /home/pi/pico/pico-sdk/lib/cyw43-driver
lwIP available at /home/pi/pico/pico-sdk/lib/lwip
mbedtls available at /home/pi/pico/pico-sdk/lib/mbedtls
Using PICO_EXAMPLES_PATH from environment ('/home/pi/pico/pico-examples')
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/pico/sleep_dormant/build

...

[100%] Linking CXX executable sleep_dormant.elf
[100%] Built target sleep_dormant
$ # HOORAY! 

This seemed to fix the compile issue. Unfortunately, the openocd issue remains :(

$ pwd
~/pico/sleep_dormant/build
$ sudo openocd -d2 -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program sleep_dormant.elf verify reset exit"
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-02-11-10:09)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz

Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E6616408432C1933
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked
seamusdemora commented 5 days ago

RE the openocd issue:

Wow... what a goat rope this has become. I finally managed to restore some function: I can at least upload my 'INA260 Power project' file from the RPi 5 to the pico. How? I had to flash (re-flash??) the firmware in the debug probe! Even d/l the file from your GitHub site was a mystery, but finally resolved as follows:

 $ wget "https://github.com/raspberrypi/debugprobe/releases/download/debugprobe-v2.0.1/debugprobe.uf2?raw=True" -O /home/pi/debugprobe.uf2 

. . . 

Length: 84480 (82K) [application/octet-stream]
Saving to: ‘/home/pi/debugprobe.uf2’

/home/pi/debugprobe.uf2                         100%[====================================================================================================>]  82.50K  --.-KB/s    in 0.02s

2024-09-24 05:13:28 (5.26 MB/s) - ‘/home/pi/debugprobe.uf2’ saved [84480/84480]
$ 

However, when I now try to upload my sleep_dormant using openocd:

$ pwd
~/pico/sleep_dormant/build
$ sudo openocd -d0 -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program sleep_dormant.elf verify reset exit"

Open On-Chip Debugger 0.12.0-g4d87f6d (2024-02-11-10:09)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
debug_level: 0

adapter speed: 5000 kHz

[rp2040.core0] halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
[rp2040.core1] halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Error: Failed to connect multidrop rp2040.dap1
Error: Failed to connect multidrop rp2040.dap1
Error: Failed to connect multidrop rp2040.dap1
Error: Failed to connect multidrop rp2040.dap1
Error: Failed to connect multidrop rp2040.dap1
Error: Failed to connect multidrop rp2040.dap1
Error: Failed to select multidrop rp2040.dap1
Error: Failed to connect multidrop rp2040.dap1
Error: [rp2040.core1] DP initialisation failed
in procedure 'program' 

$

It fails in the same way when I try to load from the pico-playground folder:

$pwd
~/pico/pico-playground/build/sleep/hello_dormant

$ sudo openocd -d2 -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program hello_dormant.elf verify reset exit"
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-02-11-10:09)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : Hardware thread awareness created
Info : Hardware thread awareness created
adapter speed: 5000 kHz

Info : Using CMSIS-DAPv2 interface with VID:PID=0x2e8a:0x000c, serial=E6616408432C1933
Info : CMSIS-DAP: SWD supported
Info : CMSIS-DAP: Atomic commands supported
Info : CMSIS-DAP: Test domain timer supported
Info : CMSIS-DAP: FW Version = 2.0.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 0
Info : CMSIS-DAP: Interface ready
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477, DLPIDR 0x00000001
Error: Failed to connect multidrop rp2040.dap1
Warn : Connecting DP: stalled AP operation, issuing ABORT
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked

$ 

After failing as above (two separate cases), openocd now returns to failing with the INA260 project!!!

Any idea what's behind this craziness??

lurch commented 4 days ago

I know openocd is not an RPi product, but hoping you can offer some advice.

You probably ought to open an issue on https://github.com/raspberrypi/openocd

You could also try asking for help at https://forums.raspberrypi.com/

lurch commented 4 days ago

Uh - where do those changes go exactly? I tried adding them to ~/pico/sleep_dormant/CMakeLists.txt, but here's the result:

https://github.com/raspberrypi/pico-extras/blob/master/README.md says "(copying external/pico_extras_import.cmake into your project)"

seamusdemora commented 4 days ago

Uh - where do those changes go exactly? I tried adding them to ~/pico/sleep_dormant/CMakeLists.txt, but here's the result:

https://github.com/raspberrypi/pico-extras/blob/master/README.md says "(copying external/pico_extras_import.cmake into your project)"

Thanks - I was using the PDFs as my primary source of info. ... but may I say that passage in the README is quite confusing!?

seamusdemora commented 4 days ago

I know openocd is not an RPi product, but hoping you can offer some advice.

You probably ought to open an issue on https://github.com/raspberrypi/openocd

I'll certainly look into that... have you guys had many issues with openocd?

You could also try asking for help at https://forums.raspberrypi.com/

No can do - was banned "for life" for the infraction of standing up to dictators :)

JamesH65 commented 4 days ago

I double checked and looked at that thread; you were banned for perfectly valid reasons. Very few rules on the forum as well, so well done.

seamusdemora commented 3 days ago

I double checked and looked at that thread; you were banned for perfectly valid reasons. Very few rules on the forum as well, so well done.

"banned for perfectly valid reasons"?!?! Because I had an issue with hardware I bought from the company you work for?

Listen James - IIRC, it was you who were throwing your weight around, acting like Mr. Big Shot, and damning me because I had a complaint about the faulty hardware that I bought from RPi... Then, you demanded that I shut up! I had a legitimate complaint - your trying to silence me is not the way "Customer Service" is supposed to be handled. At least not in reputable companies.

seamusdemora commented 2 days ago

@kilograham

They are indeed coming soon - they didn't quite make it in with SDK2.0.0

Hello Graham - I wondered if you had an approximate date for bringing the sleep and dormant examples into the "mainstream"? Curious as I'm apparently going to have to rebuild my development setup in an effort to cure the OpenOCD issues. Thanks for any insight.