forked from raspberrypi/pico-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 26653ea
Showing
404 changed files
with
135,614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
.vscode | ||
cmake-* | ||
.DS_Store | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "tinyusb"] | ||
path = lib/tinyusb | ||
url = [email protected]:raspberrypi/tinyusb.git | ||
branch = pico |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
if (NOT TARGET _pico_sdk_inclusion_marker) | ||
add_library(_pico_sdk_inclusion_marker INTERFACE) | ||
include(pico_sdk_init.cmake) | ||
|
||
project(pico_sdk C CXX ASM) | ||
|
||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") | ||
if (PICO_DEOPTIMIZED_DEBUG) | ||
message("Using fully de-optimized debug build (set PICO_DEOPTIMIZED_DEBUG=0 to optimize)") | ||
else() | ||
message("Using regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)") | ||
endif() | ||
endif() | ||
|
||
pico_is_top_level_project(PICO_SDK_TOP_LEVEL_PROJECT) | ||
|
||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
if (NOT PICO_SDK_TOP_LEVEL_PROJECT) | ||
set(PICO_SDK 1 PARENT_SCOPE) | ||
endif() | ||
|
||
# allow customization | ||
add_sub_list_dirs(PICO_SDK_PRE_LIST_DIRS) | ||
|
||
add_subdirectory(tools) | ||
add_subdirectory(src) | ||
|
||
add_compile_options(-Winline) | ||
|
||
if (PICO_SDK_TOP_LEVEL_PROJECT AND NOT DEFINED PICO_SDK_TESTS_ENABLED) | ||
set(PICO_SDK_TESTS_ENABLED 1) | ||
endif() | ||
if (PICO_SDK_TESTS_ENABLED) | ||
add_subdirectory(test) | ||
endif () | ||
set(PICO_SDK_TESTS_ENABLED "${PICO_SDK_TESTS_ENABLED}" CACHE INTERNAL "Enable build of SDK tests") | ||
|
||
# allow customization | ||
add_sub_list_dirs(PICO_SDK_POST_LIST_DIRS) | ||
|
||
# add docs at the end, as we gather documentation dirs as we go | ||
add_subdirectory(docs) | ||
endif() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products | ||
derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# Pico SDK | ||
|
||
The Pico SDK provides the headers, libraries and build system | ||
necessary to write programs for the RP2040 based devices such as the Raspberry Pi Pico | ||
in C, C++ or assembly language. | ||
|
||
The Pico SDK is designed to provide an API and programming environment that is familiar both to non-embedded C developers and embedded C developers alike. | ||
A single program runs on the device at a time and startrs with a conventional `main()` method. Standard C/C++ libraries are supported along with | ||
C level libraries/APIs for accessing all of the RP2040's hardware include PIO (Programmable IO) | ||
|
||
Additionally the Pico SDK provides higher level libraries for dealing with timers, synchronization, USB (TinyUSB) and multi-core programming | ||
along with various utilities. | ||
|
||
The Pico SDK can be used to build anything from simple applications, full fledged runtime environments such as MicroPython, to low level software | ||
such as RP2040's on chip bootrom itself. | ||
|
||
Additional libraries/APIs that are not yet ready for inclusion in the Pico SDK can be found in [pico-extras](https://github.com/raspberrypi/pico-extras). | ||
|
||
# Documentation | ||
|
||
See [Getting Started with the Raspberry Pi Pico](https://rptl.io/pico-get-started) for information on how to setup your | ||
hardware, IDE/environment and for how to build and debug software for the Raspberry Pi Pico | ||
and other RP2040 based devices. | ||
|
||
See [Pico C/C++ SDK](https://rptl.io/pico-c-sdk) to learn more about programming using the | ||
Pico SDK, exploring more advanced features, and complete PDF based API documentation. | ||
|
||
See [Online Pico SDK API docs](https://rptl.io/pico-doxygen) for HTML based API documentation. | ||
|
||
# Example code | ||
|
||
See [pico-examples](https://github.com/raspberrypi/pico-examples) for example code you can build. | ||
|
||
# Quick-start your own project | ||
|
||
These instructions are exteremly terse, and Linux based only. For detailed steps, | ||
instructions for other platforms, and just in general, we recommend you see [Pico C/C++ SDK](https://rptl.io/pico-c-sdk) | ||
|
||
1. Install CMake (at least version 3.12), and GCC cross compiler | ||
``` | ||
sudo apt install cmake gcc-arm-none-eabi | ||
``` | ||
1. Set up your project to point to use the Pico SDK | ||
|
||
* By cloning the Pico SDK locally (most common) | ||
1. `git clone` this Pico SDK repository | ||
1. Copy [pico_sdk_import.cmake](https://github.com/raspberrypi/pico-sdk/blob/master/external/pico_sdk_import.cmake) | ||
from the SDK into your project directory | ||
2. Set `PICO_SDK_PATH` to the SDK location in your environment, or pass it (`-DPICO_SDK_PATH=`) to cmake later. | ||
3. Setup a `CMakeLists.txt` like: | ||
|
||
```cmake | ||
cmake_minimum_required(VERSION 3.12) | ||
# initialize the SDK based on PICO_SDK_PATH | ||
# note: this must happen before project() | ||
include(pico_sdk_import.cmake) | ||
project(my_project) | ||
# initialize the Pico SDK | ||
pico_sdk_init() | ||
# rest of your project | ||
``` | ||
* With Pico SDK as a submodule | ||
1. Clone the SDK as a submodule called `pico-sdk` | ||
1. Setup a `CMakeLists.txt` like: | ||
```cmake | ||
cmake_minimum_required(VERSION 3.12) | ||
# initialize pico_sdk from submodule | ||
# note: this must happen before project() | ||
include(pico-sdk/pico_sdk_init.cmake) | ||
project(my_project) | ||
# initialize the Pico SDK | ||
pico_sdk_init() | ||
# rest of your project | ||
``` | ||
* With automatic download from github | ||
1. Copy [pico_sdk_import.cmake](https://github.com/raspberrypi/pico-sdk/blob/master/external/pico_sdk_import.cmake) | ||
from the SDK into your project directory | ||
1. Setup a `CMakeLists.txt` like: | ||
```cmake | ||
cmake_minimum_required(VERSION 3.12) | ||
# initialize pico_sdk from GIT | ||
# (note this can come from environment, CMake cache etc) | ||
set(PICO_SDK_FETCH_FROM_GIT on) | ||
# pico_sdk_import.cmake is a single file copied from this SDK | ||
# note: this must happen before project() | ||
include(pico_sdk_import.cmake) | ||
project(my_project) | ||
# initialize the Pico SDK | ||
pico_sdk_init() | ||
# rest of your project | ||
``` | ||
3. Setup a CMake build directory. | ||
For example, if not using an IDE: | ||
``` | ||
$ mkdir build | ||
$ cd build | ||
$ cmake .. | ||
``` | ||
4. Write your code (see [pico-examples](https://github.com/raspberrypi/pico-examples) or the [Pico C/C++ SDK](https://rptl.io/pico-c-sdk) documentation | ||
for more information) | ||
About the simplest you can do is a single source file (e.g. hello_world.c) | ||
```c | ||
#include <stdio.h> | ||
#include "pico/stdlib.h" | ||
int main() { | ||
setup_default_uart(); | ||
printf("Hello, world!\n"); | ||
return 0; | ||
} | ||
``` | ||
And add the following to your `CMakeLists.txt`: | ||
|
||
```cmake | ||
add_executable(hello_world | ||
hello_world.c | ||
) | ||
# Add pico_stdlib library which aggregates commonly used features | ||
target_link_libraries(hello_world pico_stdlib) | ||
# create map/bin/hex/uf2 file in addition to ELF. | ||
pico_add_extra_outputs(hello_world) | ||
``` | ||
|
||
Note this example uses the default UART for _stdout_; | ||
if you want ot use the default USB see the [hello-usb](https://github.com/raspberrypi/pico-examples/tree/master/hello_world/usb) example. | ||
|
||
|
||
5. Make your target from the build directory you created. | ||
```sh | ||
$ make hello_world | ||
``` | ||
|
||
6. You now have `hello_world.elf` to load via a debugger, or `hello_world.uf2` that can be installed and | ||
run on your Raspberry Pi Pico via drag and drop. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# this is included because toolchain file sets SYSTEM_NAME=PICO | ||
|
||
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE) | ||
set(CMAKE_EXECUTABLE_SUFFIX .elf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# PICO_CMAKE_CONFIG: PICO_PLATFORM, platform to build for e.g. rp2040/host, default=rp2040 or environment value, group=build | ||
if (DEFINED ENV{PICO_PLATFORM} AND (NOT PICO_PLATFORM)) | ||
set(PICO_PLATFORM $ENV{PICO_PLATFORM}) | ||
message("Using PICO_PLATFORM from environment ('${PICO_PLATFORM}')") | ||
else() | ||
if (NOT PICO_PLATFORM) | ||
set(PICO_PLATFORM "rp2040") | ||
pico_message("Defaulting PICO_PLATFORM to ${PICO_PLATFORM} since not specified.") | ||
else() | ||
message("PICO platform is ${PICO_PLATFORM}.") | ||
endif() | ||
endif () | ||
|
||
set(PICO_PLATFORM ${PICO_PLATFORM} CACHE STRING "PICO Build platform (e.g. rp2040, host)") | ||
|
||
# PICO_CMAKE_CONFIG: PICO_CMAKE_RELOAD_PLATFORM_FILE, custom CMake file to use to set up the platform environment, default=none, group=build | ||
set(PICO_CMAKE_PRELOAD_PLATFORM_FILE "" CACHE INTERNAL "") | ||
set(PICO_CMAKE_PRELOAD_PLATFORM_DIR "${CMAKE_CURRENT_LIST_DIR}/preload/platforms" CACHE INTERNAL "") | ||
|
||
if (NOT PICO_CMAKE_PRELOAD_PLATFORM_FILE) | ||
set(PICO_CMAKE_PRELOAD_PLATFORM_FILE ${PICO_CMAKE_PRELOAD_PLATFORM_DIR}/${PICO_PLATFORM}.cmake CACHE INTERNAL "") | ||
endif () | ||
|
||
if (NOT EXISTS "${PICO_CMAKE_PRELOAD_PLATFORM_FILE}") | ||
message(FATAL_ERROR "${PICO_CMAKE_PRELOAD_PLATFORM_FILE} does not exist. \ | ||
Either specify a valid PICO_PLATFORM (or PICO_CMAKE_PRELOAD_PLATFORM_FILE).") | ||
endif () | ||
|
||
include(${PICO_CMAKE_PRELOAD_PLATFORM_FILE}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# PICO_CMAKE_CONFIG: PICO_TOOLCHAIN_PATH, Path to search for compiler, default=none (i.e. search system paths), group=build | ||
# Set your compiler path here if it's not in the PATH environment variable. | ||
set(PICO_TOOLCHAIN_PATH "" CACHE INTERNAL "") | ||
|
||
# Set a default build type if none was specified | ||
set(default_build_type "Release") | ||
|
||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
message(STATUS "Defaulting build type to '${default_build_type}' since not specified.") | ||
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build, options are: 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'." FORCE) | ||
# Set the possible values of build type for cmake-gui | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS | ||
"Debug" "Release" "MinSizeRel" "RelWithDebInfo") | ||
endif() | ||
|
||
if (CMAKE_BUILD_TYPE STREQUAL "Default") | ||
error("Default build type is NOT supported") | ||
endif() | ||
|
||
# PICO_CMAKE_CONFIG: PICO_COMPILER, Optionally specifies a different compiler (other than pico_arm_gcc.cmake) - this is not yet fully supported, default=none, group=build | ||
# If PICO_COMPILER is specified, set toolchain file to ${PICO_COMPILER}.cmake. | ||
if (DEFINED PICO_COMPILER) | ||
if (DEFINED CMAKE_TOOLCHAIN_FILE) | ||
get_filename_component(toolchain "${CMAKE_TOOLCHAIN_FILE}" NAME_WE) | ||
if (NOT "${PICO_COMPILER}" STREQUAL "${toolchain}") | ||
message(WARNING "CMAKE_TOOLCHAIN_FILE is already defined to ${toolchain}.cmake, you\ | ||
need to delete cache and reconfigure if you want to switch compiler.") | ||
endif () | ||
else () | ||
set(toolchain_dir "${CMAKE_CURRENT_LIST_DIR}/preload/toolchains") | ||
set(toolchain_file "${toolchain_dir}/${PICO_COMPILER}.cmake") | ||
if (EXISTS "${toolchain_file}") | ||
set(CMAKE_TOOLCHAIN_FILE "${toolchain_file}" CACHE INTERNAL "") | ||
else () | ||
# todo improve message | ||
message(FATAL_ERROR "Toolchain file \"${PICO_COMPILER}.cmake\" does not exist, please\ | ||
select one from \"cmake/toolchains\" folder.") | ||
endif () | ||
endif () | ||
endif () | ||
|
||
message("PICO compiler is ${PICO_COMPILER}") | ||
unset(PICO_COMPILER CACHE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function(pico_message param) | ||
if (${ARGC} EQUAL 1) | ||
message("${param}") | ||
return() | ||
endif () | ||
|
||
if (NOT ${ARGC} EQUAL 2) | ||
message(FATAL_ERROR "Expect at most 2 arguments") | ||
endif () | ||
message("${param}" "${ARGV1}") | ||
endfunction() | ||
|
||
macro(assert VAR MSG) | ||
if (NOT ${VAR}) | ||
message(FATAL_ERROR "${MSG}") | ||
endif () | ||
endmacro() | ||
|
||
function(pico_find_in_paths OUT PATHS NAME) | ||
foreach(PATH IN LISTS ${PATHS}) | ||
if (EXISTS ${PATH}/${NAME}) | ||
get_filename_component(FULLNAME ${PATH}/${NAME} ABSOLUTE) | ||
set(${OUT} ${FULLNAME} PARENT_SCOPE) | ||
return() | ||
endif() | ||
endforeach() | ||
set(${OUT} "" PARENT_SCOPE) | ||
endfunction() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if (NOT (DEFINED PICO_COMPILER OR DEFINED CMAKE_TOOLCHAIN_FILE)) | ||
pico_message("Defaulting PICO platform compiler to pico_arm_gcc since not specified.") | ||
set(PICO_COMPILER "pico_arm_gcc") | ||
endif () | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include(${CMAKE_CURRENT_LIST_DIR}/pico/pico.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Toolchain file is processed multiple times, however, it cannot access CMake cache on some runs. | ||
# We store the search path in an environment variable so that we can always access it. | ||
if (NOT "${PICO_TOOLCHAIN_PATH}" STREQUAL "") | ||
set(ENV{PICO_TOOLCHAIN_PATH} "${PICO_TOOLCHAIN_PATH}") | ||
endif () | ||
|
||
# Find the compiler executable and store its path in a cache entry ${compiler_path}. | ||
# If not found, issue a fatal message and stop processing. PICO_TOOLCHAIN_PATH can be provided from | ||
# commandline as additional search path. | ||
function(pico_find_compiler compiler_path compiler_exe) | ||
# Search user provided path first. | ||
find_program( | ||
${compiler_path} ${compiler_exe} | ||
PATHS ENV PICO_TOOLCHAIN_PATH | ||
PATH_SUFFIXES bin | ||
NO_DEFAULT_PATH | ||
) | ||
|
||
# If not then search system paths. | ||
if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND") | ||
if (DEFINED ENV{PICO_TOOLCHAIN_PATH}) | ||
message(WARNING "PICO_TOOLCHAIN_PATH specified ($ENV{PICO_TOOLCHAIN_PATH}), but ${compiler_exe} not found there") | ||
endif() | ||
find_program(${compiler_path} ${compiler_exe}) | ||
endif () | ||
if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND") | ||
set(PICO_TOOLCHAIN_PATH "" CACHE PATH "Path to search for compiler.") | ||
message(FATAL_ERROR "Compiler '${compiler_exe}' not found, you can specify search path with\ | ||
\"PICO_TOOLCHAIN_PATH\".") | ||
endif () | ||
endfunction() |
Oops, something went wrong.