sysctl: add pico_extras support for rtc/sleep; add usb enum and xosc startup fixes

This commit is contained in:
Lukas F. Hartmann 2023-12-12 14:21:25 +01:00
parent 7f94e57c7b
commit 38a8ec7417
No known key found for this signature in database
GPG Key ID: 376511EB67AD7BAF
3 changed files with 71 additions and 2 deletions

View File

@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.13)
# note: this must happen before project() # note: this must happen before project()
include(pico_sdk_import.cmake) include(pico_sdk_import.cmake)
include(pico_extras_import.cmake)
project(my_project) project(my_project)
# initialize the Raspberry Pi Pico SDK # initialize the Raspberry Pi Pico SDK
@ -15,10 +17,15 @@ add_executable(sysctl
sysctl.c sysctl.c
) )
target_link_libraries(sysctl pico_stdlib hardware_i2c) target_link_libraries(sysctl pico_stdlib hardware_i2c hardware_rtc hardware_sleep)
pico_enable_stdio_usb(sysctl 1) pico_enable_stdio_usb(sysctl 1)
pico_enable_stdio_uart(sysctl 0) pico_enable_stdio_uart(sysctl 0)
pico_add_extra_outputs(sysctl) pico_add_extra_outputs(sysctl)
target_compile_definitions(sysctl PUBLIC PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1)
target_compile_definitions(sysctl PUBLIC
PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64
)

View File

@ -1,10 +1,10 @@
#!/bin/bash #!/bin/bash
export PICO_SDK_PATH=$PWD/../../pico-sdk export PICO_SDK_PATH=$PWD/../../pico-sdk
export PICO_EXTRAS_PATH=$PWD/../../pico-extras
mkdir -p build mkdir -p build
cd build cd build
cmake .. cmake ..
make make

View File

@ -0,0 +1,62 @@
# This is a copy of <PICO_EXTRAS_PATH>/external/pico_extras_import.cmake
# This can be dropped into an external project to help locate pico-extras
# It should be include()ed prior to project()
if (DEFINED ENV{PICO_EXTRAS_PATH} AND (NOT PICO_EXTRAS_PATH))
set(PICO_EXTRAS_PATH $ENV{PICO_EXTRAS_PATH})
message("Using PICO_EXTRAS_PATH from environment ('${PICO_EXTRAS_PATH}')")
endif ()
if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT))
set(PICO_EXTRAS_FETCH_FROM_GIT $ENV{PICO_EXTRAS_FETCH_FROM_GIT})
message("Using PICO_EXTRAS_FETCH_FROM_GIT from environment ('${PICO_EXTRAS_FETCH_FROM_GIT}')")
endif ()
if (DEFINED ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH} AND (NOT PICO_EXTRAS_FETCH_FROM_GIT_PATH))
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH $ENV{PICO_EXTRAS_FETCH_FROM_GIT_PATH})
message("Using PICO_EXTRAS_FETCH_FROM_GIT_PATH from environment ('${PICO_EXTRAS_FETCH_FROM_GIT_PATH}')")
endif ()
if (NOT PICO_EXTRAS_PATH)
if (PICO_EXTRAS_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_EXTRAS_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
pico_extras
GIT_REPOSITORY https://github.com/raspberrypi/pico-extras
GIT_TAG master
)
if (NOT pico_extras)
message("Downloading Raspberry Pi Pico Extras")
FetchContent_Populate(pico_extras)
set(PICO_EXTRAS_PATH ${pico_extras_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
if (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../pico-extras")
set(PICO_EXTRAS_PATH ${PICO_SDK_PATH}/../pico-extras)
message("Defaulting PICO_EXTRAS_PATH as sibling of PICO_SDK_PATH: ${PICO_EXTRAS_PATH}")
else()
message(FATAL_ERROR
"PICO EXTRAS location was not specified. Please set PICO_EXTRAS_PATH or set PICO_EXTRAS_FETCH_FROM_GIT to on to fetch from git."
)
endif()
endif ()
endif ()
set(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" CACHE PATH "Path to the PICO EXTRAS")
set(PICO_EXTRAS_FETCH_FROM_GIT "${PICO_EXTRAS_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of PICO EXTRAS from git if not otherwise locatable")
set(PICO_EXTRAS_FETCH_FROM_GIT_PATH "${PICO_EXTRAS_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download EXTRAS")
get_filename_component(PICO_EXTRAS_PATH "${PICO_EXTRAS_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_EXTRAS_PATH})
message(FATAL_ERROR "Directory '${PICO_EXTRAS_PATH}' not found")
endif ()
set(PICO_EXTRAS_PATH ${PICO_EXTRAS_PATH} CACHE PATH "Path to the PICO EXTRAS" FORCE)
add_subdirectory(${PICO_EXTRAS_PATH} pico_extras)