commit | 6ff3e4fab27441de19fd53c0eb5aacbe83a18221 | [log] [tgz] |
---|---|---|
author | armandomontanez <montanez.armando.l@gmail.com> | Thu Jun 13 07:50:04 2024 -0700 |
committer | GitHub <noreply@github.com> | Thu Jun 13 09:50:04 2024 -0500 |
tree | 66b078191acb129e6a531aadd7f01028ad6720b8 | |
parent | 0dc17e5149851fe4c4ee719104f15738a7526c71 [diff] |
Expand bazel build to include configuration options and broader support. (#1731) * Add host Bazel build Updates target_compatible_with across the repo to ensure that wildcard builds for both host and rp2040 succeed. * Get unit tests building * Add Python script to identify build system differences Uses the build system tags to make it easier to identify differences between the CMake and Bazel builds. * Temporarily disable pico divider test * Support PICO_BARE_METAL in Bazel * Support PICO_NO_GC_SECTIONS in Bazel * Support boot2 configuration in Bazel Adds support for PICO_DEFAULT_BOOT_STAGE2 and PICO_DEFAULT_BOOT_STAGE2_FILE in the Bazel build. * Allowlist some CMake-only options * Support CXX configuration options in Bazel * Move multiple_choice_flag.bzl * Support all pico boards * Support linking multiple stdio implementations Changes the Bazel build so stdio implementations are no longer mutually exclusive. * Add PICO_BOOT_STAGE2_LINK_IMAGE * Support PICO_CMSIS_PATH in Bazel * Support PICO_USE_DEFAULT_MAX_PAGE_SIZE in Bazel * Silence PICO_CMSIS_VENDOR and PICO_CMSIS_DEVICE differences * Support PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS in Bazel * Properly support version defines * Support embedding binary info in Bazel * Embed build type in binary * Support different linker scripts in Bazel build * Finish out missing PICO_BUILD_DEFINE in Bazel build * Support PICO_NO_TARGET_NAME * Reorganize initial configuration options in Bazel Cleans up and reorganizes some of the initial configuration options added to the Bazel build so everything is consistent. * Add builds for pioasm and elf2uf2 * Use Python rules from rules_python * Actually link in output formats in pioasm tool * Make tools have public visibility * Add UF2 Bazel aspect * Add TODOs for pioasm/uf2 helpers * Fix compile flag typo * Update Bazel SDK configuration strings to match recent CMake changes * Fix pico_divider test * Clean up straggling TODOs * Clarify pico_stdio_test compatibility * Initial Bazel Pico W support * Add new files from develop * Clean up compatibility expressions in Bazel build * Clean up rp2 constraint handling in Bazel * More Bazel docs cleanup * Format Bazel build files * Consolidate transitions in the Pico SDK * Make every _allowlist_function_transition explicit * More docs cleanup * Add a few missing defines * Improve PICO_CONFIG_HEADER correctness in Bazel * Minor docs clarifications
The Raspberry Pi Pico SDK (henceforth the 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 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 starts 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 SDK provides higher level libraries for dealing with timers, synchronization, USB (TinyUSB) and multi-core programming along with various utilities.
The SDK can be used to build anything from simple applications, to fully 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 SDK can be found in pico-extras.
See Getting Started with the Raspberry Pi Pico 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 Connecting to the Internet with Raspberry Pi Pico W to learn more about writing applications for your Raspberry Pi Pico W that connect to the internet.
See Raspberry Pi Pico C/C++ SDK to learn more about programming using the SDK, to explore more advanced features, and for complete PDF-based API documentation.
See Online Raspberry Pi Pico SDK API docs for HTML-based API documentation.
See pico-examples for example code you can build.
The master branch of pico-sdk
on GitHub contains the latest stable release of the SDK. If you need or want to test upcoming features, you can try the develop branch instead.
These instructions are extremely terse, and Linux-based only. For detailed steps, instructions for other platforms, and just in general, we recommend you see Raspberry Pi Pico C/C++ SDK
Install CMake (at least version 3.13), and GCC cross compiler
sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib
Set up your project to point to use the Raspberry Pi Pico SDK
Either by cloning the SDK locally (most common) :
git clone
this Raspberry Pi Pico SDK repository
Copy pico_sdk_import.cmake from the SDK into your project directory
Set PICO_SDK_PATH
to the SDK location in your environment, or pass it (-DPICO_SDK_PATH=
) to cmake later.
Setup a CMakeLists.txt
like:
cmake_minimum_required(VERSION 3.13...3.27) # initialize the SDK based on PICO_SDK_PATH # note: this must happen before project() include(pico_sdk_import.cmake) project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
Or with the Raspberry Pi Pico SDK as a submodule :
Clone the SDK as a submodule called pico-sdk
Setup a CMakeLists.txt
like:
cmake_minimum_required(VERSION 3.13...3.27) # initialize pico-sdk from submodule # note: this must happen before project() include(pico-sdk/pico_sdk_init.cmake) project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
Or with automatic download from GitHub :
Copy pico_sdk_import.cmake from the SDK into your project directory
Setup a CMakeLists.txt
like:
cmake_minimum_required(VERSION 3.13) # 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 Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
Or by cloning the SDK locally, but without copying pico_sdk_import.cmake
:
git clone
this Raspberry Pi Pico SDK repository
Setup a CMakeLists.txt
like:
cmake_minimum_required(VERSION 3.13) # initialize the SDK directly include(/path/to/pico-sdk/pico_sdk_init.cmake) project(my_project) # initialize the Raspberry Pi Pico SDK pico_sdk_init() # rest of your project
Write your code (see pico-examples or the Raspberry Pi Pico C/C++ SDK documentation for more information)
About the simplest you can do is a single source file (e.g. hello_world.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
:
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 to use the default USB see the hello-usb example.
Setup a CMake build directory. For example, if not using an IDE:
$ mkdir build $ cd build $ cmake ..
When building for a board other than the Raspberry Pi Pico, you should pass -DPICO_BOARD=board_name
to the cmake
command above, e.g. cmake -DPICO_BOARD=pico_w ..
to configure the SDK and build options accordingly for that particular board.
Doing so sets up various compiler defines (e.g. default pin numbers for UART and other hardware) and in certain cases also enables the use of additional libraries (e.g. wireless support when building for PICO_BOARD=pico_w
) which cannot be built without a board which provides the requisite functionality.
For a list of boards defined in the SDK itself, look in this directory which has a header for each named board.
Make your target from the build directory you created.
$ make hello_world
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.