Skip to content

Commit 26653ea

Browse files
committed
Initial Release
0 parents  commit 26653ea

File tree

404 files changed

+135614
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

404 files changed

+135614
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
.vscode
3+
cmake-*
4+
.DS_Store
5+
build

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "tinyusb"]
2+
path = lib/tinyusb
3+
url = [email protected]:raspberrypi/tinyusb.git
4+
branch = pico

CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
if (NOT TARGET _pico_sdk_inclusion_marker)
3+
add_library(_pico_sdk_inclusion_marker INTERFACE)
4+
include(pico_sdk_init.cmake)
5+
6+
project(pico_sdk C CXX ASM)
7+
8+
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
9+
if (PICO_DEOPTIMIZED_DEBUG)
10+
message("Using fully de-optimized debug build (set PICO_DEOPTIMIZED_DEBUG=0 to optimize)")
11+
else()
12+
message("Using regular optimized debug build (set PICO_DEOPTIMIZED_DEBUG=1 to de-optimize)")
13+
endif()
14+
endif()
15+
16+
pico_is_top_level_project(PICO_SDK_TOP_LEVEL_PROJECT)
17+
18+
set(CMAKE_C_STANDARD 11)
19+
set(CMAKE_CXX_STANDARD 11)
20+
21+
if (NOT PICO_SDK_TOP_LEVEL_PROJECT)
22+
set(PICO_SDK 1 PARENT_SCOPE)
23+
endif()
24+
25+
# allow customization
26+
add_sub_list_dirs(PICO_SDK_PRE_LIST_DIRS)
27+
28+
add_subdirectory(tools)
29+
add_subdirectory(src)
30+
31+
add_compile_options(-Winline)
32+
33+
if (PICO_SDK_TOP_LEVEL_PROJECT AND NOT DEFINED PICO_SDK_TESTS_ENABLED)
34+
set(PICO_SDK_TESTS_ENABLED 1)
35+
endif()
36+
if (PICO_SDK_TESTS_ENABLED)
37+
add_subdirectory(test)
38+
endif ()
39+
set(PICO_SDK_TESTS_ENABLED "${PICO_SDK_TESTS_ENABLED}" CACHE INTERNAL "Enable build of SDK tests")
40+
41+
# allow customization
42+
add_sub_list_dirs(PICO_SDK_POST_LIST_DIRS)
43+
44+
# add docs at the end, as we gather documentation dirs as we go
45+
add_subdirectory(docs)
46+
endif()
47+

LICENSE.TXT

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4+
following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7+
disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided with the distribution.
11+
12+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
13+
derived from this software without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Pico SDK
2+
3+
The Pico SDK provides the headers, libraries and build system
4+
necessary to write programs for the RP2040 based devices such as the Raspberry Pi Pico
5+
in C, C++ or assembly language.
6+
7+
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.
8+
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
9+
C level libraries/APIs for accessing all of the RP2040's hardware include PIO (Programmable IO)
10+
11+
Additionally the Pico SDK provides higher level libraries for dealing with timers, synchronization, USB (TinyUSB) and multi-core programming
12+
along with various utilities.
13+
14+
The Pico SDK can be used to build anything from simple applications, full fledged runtime environments such as MicroPython, to low level software
15+
such as RP2040's on chip bootrom itself.
16+
17+
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).
18+
19+
# Documentation
20+
21+
See [Getting Started with the Raspberry Pi Pico](https://rptl.io/pico-get-started) for information on how to setup your
22+
hardware, IDE/environment and for how to build and debug software for the Raspberry Pi Pico
23+
and other RP2040 based devices.
24+
25+
See [Pico C/C++ SDK](https://rptl.io/pico-c-sdk) to learn more about programming using the
26+
Pico SDK, exploring more advanced features, and complete PDF based API documentation.
27+
28+
See [Online Pico SDK API docs](https://rptl.io/pico-doxygen) for HTML based API documentation.
29+
30+
# Example code
31+
32+
See [pico-examples](https://github.com/raspberrypi/pico-examples) for example code you can build.
33+
34+
# Quick-start your own project
35+
36+
These instructions are exteremly terse, and Linux based only. For detailed steps,
37+
instructions for other platforms, and just in general, we recommend you see [Pico C/C++ SDK](https://rptl.io/pico-c-sdk)
38+
39+
1. Install CMake (at least version 3.12), and GCC cross compiler
40+
```
41+
sudo apt install cmake gcc-arm-none-eabi
42+
```
43+
1. Set up your project to point to use the Pico SDK
44+
45+
* By cloning the Pico SDK locally (most common)
46+
1. `git clone` this Pico SDK repository
47+
1. Copy [pico_sdk_import.cmake](https://github.com/raspberrypi/pico-sdk/blob/master/external/pico_sdk_import.cmake)
48+
from the SDK into your project directory
49+
2. Set `PICO_SDK_PATH` to the SDK location in your environment, or pass it (`-DPICO_SDK_PATH=`) to cmake later.
50+
3. Setup a `CMakeLists.txt` like:
51+
52+
```cmake
53+
cmake_minimum_required(VERSION 3.12)
54+
55+
# initialize the SDK based on PICO_SDK_PATH
56+
# note: this must happen before project()
57+
include(pico_sdk_import.cmake)
58+
59+
project(my_project)
60+
61+
# initialize the Pico SDK
62+
pico_sdk_init()
63+
64+
# rest of your project
65+
66+
```
67+
68+
* With Pico SDK as a submodule
69+
1. Clone the SDK as a submodule called `pico-sdk`
70+
1. Setup a `CMakeLists.txt` like:
71+
72+
```cmake
73+
cmake_minimum_required(VERSION 3.12)
74+
75+
# initialize pico_sdk from submodule
76+
# note: this must happen before project()
77+
include(pico-sdk/pico_sdk_init.cmake)
78+
79+
project(my_project)
80+
81+
# initialize the Pico SDK
82+
pico_sdk_init()
83+
84+
# rest of your project
85+
86+
```
87+
88+
* With automatic download from github
89+
1. Copy [pico_sdk_import.cmake](https://github.com/raspberrypi/pico-sdk/blob/master/external/pico_sdk_import.cmake)
90+
from the SDK into your project directory
91+
1. Setup a `CMakeLists.txt` like:
92+
93+
```cmake
94+
cmake_minimum_required(VERSION 3.12)
95+
96+
# initialize pico_sdk from GIT
97+
# (note this can come from environment, CMake cache etc)
98+
set(PICO_SDK_FETCH_FROM_GIT on)
99+
100+
# pico_sdk_import.cmake is a single file copied from this SDK
101+
# note: this must happen before project()
102+
include(pico_sdk_import.cmake)
103+
104+
project(my_project)
105+
106+
# initialize the Pico SDK
107+
pico_sdk_init()
108+
109+
# rest of your project
110+
111+
```
112+
113+
3. Setup a CMake build directory.
114+
For example, if not using an IDE:
115+
```
116+
$ mkdir build
117+
$ cd build
118+
$ cmake ..
119+
```
120+
121+
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
122+
for more information)
123+
124+
About the simplest you can do is a single source file (e.g. hello_world.c)
125+
126+
```c
127+
#include <stdio.h>
128+
#include "pico/stdlib.h"
129+
130+
int main() {
131+
setup_default_uart();
132+
printf("Hello, world!\n");
133+
return 0;
134+
}
135+
```
136+
And add the following to your `CMakeLists.txt`:
137+
138+
```cmake
139+
add_executable(hello_world
140+
hello_world.c
141+
)
142+
143+
# Add pico_stdlib library which aggregates commonly used features
144+
target_link_libraries(hello_world pico_stdlib)
145+
146+
# create map/bin/hex/uf2 file in addition to ELF.
147+
pico_add_extra_outputs(hello_world)
148+
```
149+
150+
Note this example uses the default UART for _stdout_;
151+
if you want ot use the default USB see the [hello-usb](https://github.com/raspberrypi/pico-examples/tree/master/hello_world/usb) example.
152+
153+
154+
5. Make your target from the build directory you created.
155+
```sh
156+
$ make hello_world
157+
```
158+
159+
6. You now have `hello_world.elf` to load via a debugger, or `hello_world.uf2` that can be installed and
160+
run on your Raspberry Pi Pico via drag and drop.

cmake/Platform/PICO.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# this is included because toolchain file sets SYSTEM_NAME=PICO
2+
3+
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
4+
set(CMAKE_EXECUTABLE_SUFFIX .elf)

cmake/pico_pre_load_platform.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# PICO_CMAKE_CONFIG: PICO_PLATFORM, platform to build for e.g. rp2040/host, default=rp2040 or environment value, group=build
2+
if (DEFINED ENV{PICO_PLATFORM} AND (NOT PICO_PLATFORM))
3+
set(PICO_PLATFORM $ENV{PICO_PLATFORM})
4+
message("Using PICO_PLATFORM from environment ('${PICO_PLATFORM}')")
5+
else()
6+
if (NOT PICO_PLATFORM)
7+
set(PICO_PLATFORM "rp2040")
8+
pico_message("Defaulting PICO_PLATFORM to ${PICO_PLATFORM} since not specified.")
9+
else()
10+
message("PICO platform is ${PICO_PLATFORM}.")
11+
endif()
12+
endif ()
13+
14+
set(PICO_PLATFORM ${PICO_PLATFORM} CACHE STRING "PICO Build platform (e.g. rp2040, host)")
15+
16+
# PICO_CMAKE_CONFIG: PICO_CMAKE_RELOAD_PLATFORM_FILE, custom CMake file to use to set up the platform environment, default=none, group=build
17+
set(PICO_CMAKE_PRELOAD_PLATFORM_FILE "" CACHE INTERNAL "")
18+
set(PICO_CMAKE_PRELOAD_PLATFORM_DIR "${CMAKE_CURRENT_LIST_DIR}/preload/platforms" CACHE INTERNAL "")
19+
20+
if (NOT PICO_CMAKE_PRELOAD_PLATFORM_FILE)
21+
set(PICO_CMAKE_PRELOAD_PLATFORM_FILE ${PICO_CMAKE_PRELOAD_PLATFORM_DIR}/${PICO_PLATFORM}.cmake CACHE INTERNAL "")
22+
endif ()
23+
24+
if (NOT EXISTS "${PICO_CMAKE_PRELOAD_PLATFORM_FILE}")
25+
message(FATAL_ERROR "${PICO_CMAKE_PRELOAD_PLATFORM_FILE} does not exist. \
26+
Either specify a valid PICO_PLATFORM (or PICO_CMAKE_PRELOAD_PLATFORM_FILE).")
27+
endif ()
28+
29+
include(${PICO_CMAKE_PRELOAD_PLATFORM_FILE})

cmake/pico_pre_load_toolchain.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# PICO_CMAKE_CONFIG: PICO_TOOLCHAIN_PATH, Path to search for compiler, default=none (i.e. search system paths), group=build
2+
# Set your compiler path here if it's not in the PATH environment variable.
3+
set(PICO_TOOLCHAIN_PATH "" CACHE INTERNAL "")
4+
5+
# Set a default build type if none was specified
6+
set(default_build_type "Release")
7+
8+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
9+
message(STATUS "Defaulting build type to '${default_build_type}' since not specified.")
10+
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build, options are: 'Debug', 'Release', 'MinSizeRel', 'RelWithDebInfo'." FORCE)
11+
# Set the possible values of build type for cmake-gui
12+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
13+
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
14+
endif()
15+
16+
if (CMAKE_BUILD_TYPE STREQUAL "Default")
17+
error("Default build type is NOT supported")
18+
endif()
19+
20+
# 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
21+
# If PICO_COMPILER is specified, set toolchain file to ${PICO_COMPILER}.cmake.
22+
if (DEFINED PICO_COMPILER)
23+
if (DEFINED CMAKE_TOOLCHAIN_FILE)
24+
get_filename_component(toolchain "${CMAKE_TOOLCHAIN_FILE}" NAME_WE)
25+
if (NOT "${PICO_COMPILER}" STREQUAL "${toolchain}")
26+
message(WARNING "CMAKE_TOOLCHAIN_FILE is already defined to ${toolchain}.cmake, you\
27+
need to delete cache and reconfigure if you want to switch compiler.")
28+
endif ()
29+
else ()
30+
set(toolchain_dir "${CMAKE_CURRENT_LIST_DIR}/preload/toolchains")
31+
set(toolchain_file "${toolchain_dir}/${PICO_COMPILER}.cmake")
32+
if (EXISTS "${toolchain_file}")
33+
set(CMAKE_TOOLCHAIN_FILE "${toolchain_file}" CACHE INTERNAL "")
34+
else ()
35+
# todo improve message
36+
message(FATAL_ERROR "Toolchain file \"${PICO_COMPILER}.cmake\" does not exist, please\
37+
select one from \"cmake/toolchains\" folder.")
38+
endif ()
39+
endif ()
40+
endif ()
41+
42+
message("PICO compiler is ${PICO_COMPILER}")
43+
unset(PICO_COMPILER CACHE)
44+

cmake/pico_utils.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function(pico_message param)
2+
if (${ARGC} EQUAL 1)
3+
message("${param}")
4+
return()
5+
endif ()
6+
7+
if (NOT ${ARGC} EQUAL 2)
8+
message(FATAL_ERROR "Expect at most 2 arguments")
9+
endif ()
10+
message("${param}" "${ARGV1}")
11+
endfunction()
12+
13+
macro(assert VAR MSG)
14+
if (NOT ${VAR})
15+
message(FATAL_ERROR "${MSG}")
16+
endif ()
17+
endmacro()
18+
19+
function(pico_find_in_paths OUT PATHS NAME)
20+
foreach(PATH IN LISTS ${PATHS})
21+
if (EXISTS ${PATH}/${NAME})
22+
get_filename_component(FULLNAME ${PATH}/${NAME} ABSOLUTE)
23+
set(${OUT} ${FULLNAME} PARENT_SCOPE)
24+
return()
25+
endif()
26+
endforeach()
27+
set(${OUT} "" PARENT_SCOPE)
28+
endfunction()

cmake/preload/platforms/host.cmake

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if (NOT (DEFINED PICO_COMPILER OR DEFINED CMAKE_TOOLCHAIN_FILE))
2+
pico_message("Defaulting PICO platform compiler to pico_arm_gcc since not specified.")
3+
set(PICO_COMPILER "pico_arm_gcc")
4+
endif ()
5+
6+
7+

cmake/preload/platforms/rp2040.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/pico/pico.cmake)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Toolchain file is processed multiple times, however, it cannot access CMake cache on some runs.
2+
# We store the search path in an environment variable so that we can always access it.
3+
if (NOT "${PICO_TOOLCHAIN_PATH}" STREQUAL "")
4+
set(ENV{PICO_TOOLCHAIN_PATH} "${PICO_TOOLCHAIN_PATH}")
5+
endif ()
6+
7+
# Find the compiler executable and store its path in a cache entry ${compiler_path}.
8+
# If not found, issue a fatal message and stop processing. PICO_TOOLCHAIN_PATH can be provided from
9+
# commandline as additional search path.
10+
function(pico_find_compiler compiler_path compiler_exe)
11+
# Search user provided path first.
12+
find_program(
13+
${compiler_path} ${compiler_exe}
14+
PATHS ENV PICO_TOOLCHAIN_PATH
15+
PATH_SUFFIXES bin
16+
NO_DEFAULT_PATH
17+
)
18+
19+
# If not then search system paths.
20+
if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND")
21+
if (DEFINED ENV{PICO_TOOLCHAIN_PATH})
22+
message(WARNING "PICO_TOOLCHAIN_PATH specified ($ENV{PICO_TOOLCHAIN_PATH}), but ${compiler_exe} not found there")
23+
endif()
24+
find_program(${compiler_path} ${compiler_exe})
25+
endif ()
26+
if ("${${compiler_path}}" STREQUAL "${compiler_path}-NOTFOUND")
27+
set(PICO_TOOLCHAIN_PATH "" CACHE PATH "Path to search for compiler.")
28+
message(FATAL_ERROR "Compiler '${compiler_exe}' not found, you can specify search path with\
29+
\"PICO_TOOLCHAIN_PATH\".")
30+
endif ()
31+
endfunction()

0 commit comments

Comments
 (0)