├── .gitignore ├── .vscode ├── c_cpp_properties.json ├── cmake-kits.json ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── CMakeLists.txt ├── README.md ├── header.h ├── main.c └── pico_sdk_import.cmake /.gitignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Pico", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "${env:PICO_SDK_PATH}/**" 8 | ], 9 | "defines": [], 10 | "compilerPath": "${env:PICO_INSTALL_PATH}/gcc-arm-none-eabi/bin/arm-none-eabi-gcc.exe", 11 | "cStandard": "c11", 12 | "cppStandard": "c++11", 13 | "intelliSenseMode": "linux-gcc-arm", 14 | "configurationProvider": "ms-vscode.cmake-tools" 15 | } 16 | ], 17 | "version": 4 18 | } 19 | -------------------------------------------------------------------------------- /.vscode/cmake-kits.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Pico ARM GCC", 4 | "description": "Pico SDK Toolchain with GCC arm-none-eabi", 5 | "toolchainFile": "${env:PICO_SDK_PATH}/cmake/preload/toolchains/pico_arm_gcc.cmake" 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "marus25.cortex-debug", 4 | "ms-vscode.cmake-tools", 5 | "ms-vscode.cpptools", 6 | "ms-vscode.cpptools-extension-pack", 7 | "ms-vscode.vscode-serial-monitor" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Pico Debug (Cortex-Debug)", 6 | "cwd": "${workspaceFolder}", 7 | "executable": "${command:cmake.launchTargetPath}", 8 | "request": "launch", 9 | "type": "cortex-debug", 10 | "servertype": "openocd", 11 | "gdbPath": "arm-none-eabi-gdb", 12 | "device": "RP2040", 13 | "configFiles": [ 14 | "interface/cmsis-dap.cfg", 15 | "target/rp2040.cfg" 16 | ], 17 | "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", 18 | "runToEntryPoint": "main", 19 | "openOCDLaunchCommands": [ 20 | "adapter speed 1000" 21 | ] 22 | }, 23 | { 24 | "name": "Pico Debug (Cortex-Debug with external OpenOCD)", 25 | "cwd": "${workspaceFolder}", 26 | "executable": "${command:cmake.launchTargetPath}", 27 | "request": "launch", 28 | "type": "cortex-debug", 29 | "servertype": "external", 30 | "gdbTarget": "localhost:3333", 31 | "gdbPath": "arm-none-eabi-gdb", 32 | "device": "RP2040", 33 | "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", 34 | "runToEntryPoint": "main" 35 | }, 36 | { 37 | "name": "Pico Debug (C++ Debugger)", 38 | "type": "cppdbg", 39 | "request": "launch", 40 | "cwd": "${workspaceFolder}", 41 | "program": "${command:cmake.launchTargetPath}", 42 | "MIMode": "gdb", 43 | "miDebuggerPath": "arm-none-eabi-gdb", 44 | "miDebuggerServerAddress": "localhost:3333", 45 | "debugServerPath": "openocd", 46 | "debugServerArgs": "-f interface/cmsis-dap.cfg -f target/rp2040.cfg -c \"adapter speed 1000\"", 47 | "serverStarted": "Listening on port .* for gdb connections", 48 | "filterStderr": true, 49 | "stopAtEntry": true, 50 | "hardwareBreakpoints": { 51 | "require": true, 52 | "limit": 4 53 | }, 54 | "preLaunchTask": "Flash", 55 | "svdPath": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd" 56 | } 57 | ] 58 | } 59 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // These settings tweaks to the cmake plugin will ensure 3 | // that you debug using cortex-debug instead of trying to launch 4 | // a Pico binary on the host 5 | "cmake.statusbar.advanced": { 6 | "debug": { 7 | "visibility": "hidden" 8 | }, 9 | "launch": { 10 | "visibility": "hidden" 11 | }, 12 | "build": { 13 | "visibility": "hidden" 14 | }, 15 | "buildTarget": { 16 | "visibility": "hidden" 17 | } 18 | }, 19 | "cmake.buildBeforeRun": true, 20 | "cmake.configureOnOpen": true, 21 | "cmake.configureSettings": { 22 | "CMAKE_MODULE_PATH": "${env:PICO_INSTALL_PATH}/pico-sdk-tools" 23 | }, 24 | "cmake.generator": "Ninja", 25 | "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" 26 | } 27 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Flash", 6 | "type": "shell", 7 | "command": "openocd", 8 | "args": [ 9 | "-f", 10 | "interface/cmsis-dap.cfg", 11 | "-f", 12 | "target/rp2040.cfg", 13 | "-c", 14 | "adapter speed 1000; program {${command:cmake.launchTargetPath}} verify reset exit" 15 | ], 16 | "problemMatcher": [] 17 | }, 18 | { 19 | "label": "Build", 20 | "type": "cmake", 21 | "command": "build", 22 | "problemMatcher": "$gcc", 23 | "group": { 24 | "kind": "build", 25 | "isDefault": true 26 | } 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | include(pico_sdk_import.cmake) 4 | 5 | project(project_name) 6 | 7 | pico_sdk_init() 8 | 9 | add_executable(template 10 | main.c 11 | ) 12 | 13 | # Add pico_stdlib library, add more if used 14 | target_link_libraries(template pico_stdlib) 15 | 16 | # enable usb output, disable uart output 17 | pico_enable_stdio_usb(template 1) 18 | pico_enable_stdio_uart(template 0) 19 | 20 | # Need to generate UF2 file for upload to RP2040 21 | pico_add_extra_outputs(template) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rp2040-project-template 2 | VSCode project template for RP2040 C/C++ development 3 | -------------------------------------------------------------------------------- /header.h: -------------------------------------------------------------------------------- 1 | // Sample Header file 2 | #include 3 | 4 | int print_hello_world(){ 5 | printf("Hello world!\n"); 6 | } -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "header.h" 4 | 5 | int main() { 6 | stdio_init_all(); 7 | while (1) { 8 | print_hello_world(); 9 | sleep_ms(1000); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | --------------------------------------------------------------------------------