raspberrypi / pico-playground

BSD 3-Clause "New" or "Revised" License
450 stars 98 forks source link

Confusion re building examples in `pico-playground` #50

Open seamusdemora opened 2 months ago

seamusdemora commented 2 months ago

Sorry to have to ask, but I've got some doubts about my approach:

I need to use the sleep and/or dormant mode for an off-grid Pico project. I plan to use a RV-3028 as the RTC/interrupt source due to its accuracy and low power consumption.

I planned on using the examples in pico-playground to get me started, but I may have "missed a beat" somewhere along the line:

   $ cd ~/pico/pico-playground
   $  mkdir build 
   $ cd build
   $ export PICO_SDK_PATH=../../pico-sdk              # don't know if this was needed or not 
   $ cmake .. 
   $ cd sleep/hello_sleep
   $ make -j2 
    . . .
   [100%] Built target hello_sleep 
   $ 

So here's where I'm confused. I had to descend two levels below ./build - into sleep/hello_sleep to get things to work. This doesn't feel right...

Should I be copying hello_sleep into /home/pi/pico/examples/build?? - instead of trying to set up pico-playground as a stand-alone set of examples??

TIA!

lurch commented 2 months ago

So here's where I'm confused. I had to descend two levels below ./build - into sleep/hello_sleep to get things to work. This doesn't feel right...

IIRC this is exactly the same way that pico-examples works. Note that the examples in pico-examples need pico-sdk to be present (specified with PICO_SDK_PATH=...), but the examples in pico-playground may also need pico-extras to be present (specified with PICO_EXTRAS_PATH=...)

Should I be copying hello_sleep into /home/pi/pico/examples/build?? - instead of trying to set up pico-playground as a stand-alone set of examples??

You shouldn't be using the CMakeLists.txt from a pico-examples or pico-playground example for your own projects, as these are all tightly integrated with the top-level CMakeLists.txt in those repos.

To create your own project (independent from the pico-playground repo), see the "Manually Create your own Project" section in https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf

$ export PICO_SDK_PATH=../../pico-sdk # don't know if this was needed or not

If you're jumping around between different build directories, it's probably safer to set this to an absolute path, rather than a relative path.

kilograham commented 2 months ago

So here's where I'm confused. I had to descend two levels below ./build - into sleep/hello_sleep to get things to work. This doesn't feel right... $ make -j2

Make from the top-level builds everything in pico-playground by default

you could do

make -j2 hello_sleep

instead.

seamusdemora commented 2 months ago

Following the instructions in getting-started-with-pico-2024-08-21.pdf for "Manually Create your own Project" does not seem to work with the hello_sleep or hello_dormant examples from pico-playground. I think I followed the instructions, but got an error when running make:

$ pwd
~/pico
$ mkdir sleep_dormant
$ mkdir sleep_dormant/build
$ cd sleep_dormant
$ cp ../pico-sdk/external/pico_sdk_import.cmake .
$ cd build
$ export PICO_SDK_PATH=../../pico-sdk
$ export PICO_EXTRAS_PATH=../../pico-extras   # ADDED PER SUGGESTION ABOVE
$ cmake ..
...
-- Build files have been written to: /home/pi/pico/sleep_dormant/build
$ make 
...
[ 14%] Building C object CMakeFiles/sleep_dormant.dir/sleep_dormant.c.obj
/home/pi/pico/sleep_dormant/sleep_dormant.c:9:10: fatal error: pico/sleep.h: No such file or directory
    9 | #include "pico/sleep.h"
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/sleep_dormant.dir/build.make:76: CMakeFiles/sleep_dormant.dir/sleep_dormant.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:1748: CMakeFiles/sleep_dormant.dir/all] Error 2
make: *** [Makefile:91: all] Error 2 
---
$ find ~/pico -type f -iname "sleep.h"
/home/pi/pico/pico-sdk/lib/btstack/port/samv71-xplained-atwilc3000/ASF/sam/drivers/pmc/sleep.h
/home/pi/pico/pico-extras/src/rp2_common/pico_sleep/include/pico/sleep.h
$ 

Sorry, but I'm at a complete loss here. It's almost like pico-playground and pico-extras are completely cut off from the rest of the install??

FWIW, my ~/pico/sleep_dormant/sleep_dormant.c is almost a duplicate of the hello_dormant.c file from pico-playground:

#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/sleep.h"

int main() {
    stdio_init_all();
    printf("Hello Sleepy Dormant!\n");

    printf("Switching to XOSC\n");
    uart_default_tx_wait_blocking();

    // UART will be reconfigured by sleep_run_from_xosc
    sleep_run_from_xosc();

    printf("Running from XOSC\n");
    uart_default_tx_wait_blocking();

    printf("XOSC going dormant\n");
    uart_default_tx_wait_blocking();

    // Go to sleep until we see a high edge on GPIO 10
    sleep_goto_dormant_until_edge_high(22);

    uint i = 0;
    while (1) {
        printf("XOSC awake %d\n", i++);
    }

    return 0;
}

AND my ~/pico/sleep_dormant/CMakeLists.txt file:

cmake_minimum_required(VERSION 3.25)

include(pico_sdk_import.cmake)

project(sleep_dormant_project C CXX ASM)

set(CMAKE_C_STANDARD 11)

set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()

add_executable(sleep_dormant
        sleep_dormant.c
        )

target_link_libraries(sleep_dormant pico_stdlib hardware_sleep)

## pull in common dependencies and additional i2c hardware support
### target_link_libraries(ina260_trial pico_stdlib hardware_i2c)

if (PICO_CYW43_SUPPORTED)
    target_link_libraries(sleep_dormant pico_cyw43_arch_none)
endif()

# this enables stdio via minicom via usb, and uart support
pico_enable_stdio_usb(sleep_dormant 1)
pico_enable_stdio_uart(sleep_dormant 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(sleep_dormant)
lurch commented 2 months ago

Looks like @kilograham has given you the fix for this in your other issue? https://github.com/raspberrypi/pico-feedback/issues/415

@nathan-contino Do you think it's worth documenting how to use pico-extras in your own project in the getting-stared documentation? :thinking:

EDIT: Ahhh, I've just seen that this is actually documented towards the bottom of https://github.com/raspberrypi/pico-extras/blob/master/README.md !

seamusdemora commented 2 months ago

Looks like @kilograham has given you the fix for this in your other issue? raspberrypi/pico-feedback#415

@nathan-contino Do you think it's worth documenting how to use pico-extras in your own project in the getting-stared documentation? 🤔

EDIT: Ahhh, I've just seen that this is actually documented towards the bottom of https://github.com/raspberrypi/pico-extras/blob/master/README.md !

I got this working using the following line in CMakeLists.txt:

include(/home/pi/pico/pico-extras/external/pico_extras_import.cmake)

This was the only thing that seemed to work. Apparently I don't understand the instructions well at all:

I checked :

$ echo $PICO_EXTRAS_PATH
/home/pi/pico/pico-extras

But there seems to be no other include specification that works; e.g.

include(external/pico_extras_import.cmake)

did not work. ??