From d996d41c883a88fd9eb62703d45949e9e5893290 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:38:27 +0000 Subject: [PATCH] Initial commit --- .devcontainer/devcontainer.json | 55 +++++++++++++++++++++ .github/workflows/build.yml | 11 +++++ .github/workflows/cppcheck.yml | 13 +++++ .github/workflows/embedded-check.yml | 13 +++++ .gitignore | 1 + .vscode/extensions.json | 7 +++ .vscode/launch.json | 28 +++++++++++ .vscode/settings.json | 47 ++++++++++++++++++ .vscode/tasks.json | 21 ++++++++ CMakeLists.txt | 33 +++++++++++++ main/CMakeLists.txt | 7 +++ main/main.c | 17 +++++++ pico.code-profile | 1 + pico_extras_import_optional.cmake | 59 ++++++++++++++++++++++ pico_sdk_import.cmake | 73 ++++++++++++++++++++++++++++ 15 files changed, 386 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/cppcheck.yml create mode 100644 .github/workflows/embedded-check.yml create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt create mode 100644 main/CMakeLists.txt create mode 100644 main/main.c create mode 100644 pico.code-profile create mode 100644 pico_extras_import_optional.cmake create mode 100644 pico_sdk_import.cmake diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3bb8f44 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,55 @@ +{ + "image": "rafaelcorsi/embarcados", + "remoteEnv": { + "WOKWI_CLI_TOKEN": "${localEnv:WOKWI_CLI_TOKEN}" + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined", + "--privileged", + "-v", "/dev/bus/usb:/dev/bus/usb", + "--device=/dev/bus/usb", + "--device=/dev/ttyACM0" + ], + "customizations": { + "vscode": { + "extensions": [ + "marus25.cortex-debug", + "mcu-debug.debug-tracker-vscode", + "mcu-debug.memory-view", + "mcu-debug.peripheral-viewer", + "mcu-debug.rtos-views", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools", + "ms-vscode.cpptools-extension-pack", + "ms-vscode.cpptools-themes", + "ms-vscode.vscode-serial-monitor", + "twxs.cmake", + "wokwi.wokwi-vscode", + "seunlanlege.action-buttons" + ] + }, + "settings":{ + "cmake.statusbar.advanced": { + "cpack": {"statusBarVisibility": "hidden"}, + "debug": { + "statusBarVisibility": "hidden", + "inheritDefault": "hidden" + }, + "launch": { + "visibility": "visible" + }, + "build": { + "visibility": "hidden" + }, + "buildTarget": { + "statusBarVisibility": "hidden", + "visibility": "hidden" + } + + } + } + } + +} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..30567c7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,11 @@ +name: build pico + +on: + push: +jobs: + + Testing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: insper-embarcados/pico-build@v0 diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml new file mode 100644 index 0000000..110c840 --- /dev/null +++ b/.github/workflows/cppcheck.yml @@ -0,0 +1,13 @@ +name: cppcheck + +on: + push: +jobs: + + Testing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: insper-embarcados/actions-cppcheck@v1 + with: + c_file: main/main.c diff --git a/.github/workflows/embedded-check.yml b/.github/workflows/embedded-check.yml new file mode 100644 index 0000000..2901a61 --- /dev/null +++ b/.github/workflows/embedded-check.yml @@ -0,0 +1,13 @@ +name: embedded-check + +on: + push: +jobs: + + Testing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: insper-embarcados/actions-embedded-check@v1 + with: + c_file: main/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..567609b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..79c4f23 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": ["ms-vscode.cpptools", "ms-vscode.cpptools-extension-pack", "ms-vscode.cpptools-themes", + "twxs.cmake", "ms-vscode.cmake-tools", "marus25.cortex-debug", "mcu-debug.debug-tracker-vscode", + "mcu-debug.memory-view", "mcu-debug.peripheral-viewer", "mcu-debug.rtos-views", "ms-vscode.vscode-serial-monitor", + "Wokwi.wokwi-vscode"] +} + diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..8197934 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Pico Debug", + "cwd": "${workspaceRoot}", + "executable": "${command:cmake.launchTargetPath}", + "request": "launch", + "type": "cortex-debug", + "servertype": "openocd", + // This may need to be "arm-none-eabi-gdb" for some previous builds + "gdbPath" : "gdb-multiarch", + "device": "RP2040", + "configFiles": ["interface/cmsis-dap.cfg", "target/rp2040.cfg"], + "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", + "runToEntryPoint": "main", + "openOCDLaunchCommands": [ + "adapter speed 5000" + ], + // Work around for stopping at main on restart + "postRestartCommands": [ + "break main", + "continue" + ], + + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..24a14ca --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,47 @@ +{ + // These settings tweaks to the cmake plugin will ensure + // that you debug using cortex-debug instead of trying to launch + // a Pico binary on the host + + "cmake.buildBeforeRun": true, + "cmake.configureOnOpen": true, + "cmake.ctest.allowParallelJobs": true, + "cmake.parallelJobs": 8, + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", + + + // actions task buttons + "actionButtons": { + "defaultColor": "#ff0034", // Can also use string color names. + "loadNpmCommands":false, // Disables automatic generation of actions for npm commands. + "reloadButton":"", // Custom reload button text or icon (default ↻). null value enables automatic reload on configuration change + "commands": [ + { + "name": "$(rocket) ", + "color": "white", + "useVsCodeApi": true, + "command": "workbench.action.tasks.runTask", + "args": ["Flash"] + } + ] + }, + + // CMake Tools Status Bar Configuration + "cmake.statusbar.advanced": { + "debug": { + "visibility": "hidden" + }, + "launch": { + "visibility": "visible" + }, + "build": { + "visibility": "hidden" + }, + "buildTarget": { + "visibility": "hidden" + } +} + + +} + diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..40de445 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,21 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Flash", + "type": "shell", + "command": "openocd", + "args": [ + "-f", + "interface/cmsis-dap.cfg", + "-f", + "target/rp2040.cfg", + "-c", + "adapter speed 5000; program {${command:cmake.launchTargetPath}} verify reset exit" + ], + "problemMatcher": [] + } + + ] + } + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..bb5e86a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.12) + +# Pull in SDK (must be before project) +include(pico_sdk_import.cmake) + +include(pico_extras_import_optional.cmake) + +project(pico_emb C CXX ASM) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +if(PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0") + message( + FATAL_ERROR + "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}" + ) +endif() + +# Initialize the SDK +pico_sdk_init() + +add_compile_options( + -Wall -Wno-format # int != int32_t as far as the compiler is concerned because + # gcc has int32_t as long int + -Wno-unused-function # we have some for the docs that aren't called +) + +if(CMAKE_C_COMPILER_ID STREQUAL "GNU") + add_compile_options(-Wno-maybe-uninitialized) +endif() + +# Codes subdir: +add_subdirectory(main) diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt new file mode 100644 index 0000000..7f00150 --- /dev/null +++ b/main/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(main main.c) + +# pull in common dependencies +target_link_libraries(main pico_stdlib) + +# create map/bin/hex/uf2 file etc. +pico_add_extra_outputs(main) diff --git a/main/main.c b/main/main.c new file mode 100644 index 0000000..5f49e3a --- /dev/null +++ b/main/main.c @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "pico/stdlib.h" +#include "hardware/gpio.h" + +int main() { + stdio_init_all(); + while (true) { + printf("Hello, world!\n"); + sleep_ms(1000); + } +} diff --git a/pico.code-profile b/pico.code-profile new file mode 100644 index 0000000..7d00174 --- /dev/null +++ b/pico.code-profile @@ -0,0 +1 @@ +{"name":"pico","icon":"dashboard","settings":"{\"settings\":\"{\\n \\\"window.zoomLevel\\\": 1,\\n \\\"cmake.configureOnOpen\\\": true\\n}\"}","extensions":"[{\"identifier\":{\"id\":\"marus25.cortex-debug\",\"uuid\":\"2fd8abff-b3ce-46c9-a6a8-92d5ad69d8d0\"},\"displayName\":\"Cortex-Debug\"},{\"identifier\":{\"id\":\"mcu-debug.debug-tracker-vscode\",\"uuid\":\"bd8507f9-4b21-4877-b045-1f20471fe96e\"},\"displayName\":\"debug-tracker-vscode\"},{\"identifier\":{\"id\":\"mcu-debug.memory-view\",\"uuid\":\"f319e29a-19e8-43fb-8e3e-e264b6144083\"},\"displayName\":\"MemoryView\"},{\"identifier\":{\"id\":\"mcu-debug.peripheral-viewer\",\"uuid\":\"e6f326b2-3602-4e64-9cd1-ebe454be1992\"},\"displayName\":\"Peripheral Viewer\"},{\"identifier\":{\"id\":\"mcu-debug.rtos-views\",\"uuid\":\"0b85f1d6-1d95-4f57-bacd-ca639159f71d\"},\"displayName\":\"RTOS Views\"},{\"identifier\":{\"id\":\"ms-vscode.cmake-tools\",\"uuid\":\"7c889349-8749-43d4-8b5e-08939936d7f4\"},\"displayName\":\"CMake Tools\"},{\"identifier\":{\"id\":\"ms-vscode.cpptools\",\"uuid\":\"690b692e-e8a9-493f-b802-8089d50ac1b2\"},\"displayName\":\"C/C++\"},{\"identifier\":{\"id\":\"ms-vscode.cpptools-extension-pack\",\"uuid\":\"3957b2f6-f086-49b5-a7b4-5da772123130\"},\"displayName\":\"C/C++ Extension Pack\"},{\"identifier\":{\"id\":\"ms-vscode.cpptools-themes\",\"uuid\":\"99b17261-8f6e-45f0-9ad5-a69c6f509a4f\"},\"displayName\":\"C/C++ Themes\"},{\"identifier\":{\"id\":\"ms-vscode.vscode-serial-monitor\",\"uuid\":\"17dcad22-0c4b-428f-8a04-5d2629f1480e\"},\"displayName\":\"Serial Monitor\"},{\"identifier\":{\"id\":\"twxs.cmake\",\"uuid\":\"2be7cf14-2603-402e-9771-fd79df83cdf8\"},\"displayName\":\"CMake\"},{\"identifier\":{\"id\":\"wokwi.wokwi-vscode\",\"uuid\":\"51c34fa3-18ea-4f95-aae8-1dbe5438fe31\"},\"displayName\":\"Wokwi Simulator\"}]"} diff --git a/pico_extras_import_optional.cmake b/pico_extras_import_optional.cmake new file mode 100644 index 0000000..692e14a --- /dev/null +++ b/pico_extras_import_optional.cmake @@ -0,0 +1,59 @@ +# This is a copy of /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}") + endif() + endif () +endif () + +if (PICO_EXTRAS_PATH) + 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) +endif() \ No newline at end of file diff --git a/pico_sdk_import.cmake b/pico_sdk_import.cmake new file mode 100644 index 0000000..65f8a6f --- /dev/null +++ b/pico_sdk_import.cmake @@ -0,0 +1,73 @@ +# This is a copy of /external/pico_sdk_import.cmake + +# This can be dropped into an external project to help locate this SDK +# It should be include()ed prior to project() + +if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) + set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) + message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) + set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) + message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) + set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) + message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") +endif () + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +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") +set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") + +if (NOT PICO_SDK_PATH) + if (PICO_SDK_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PICO_SDK_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + GIT_SUBMODULES_RECURSE FALSE + ) + else () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + ) + endif () + + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + FetchContent_Populate(pico_sdk) + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + else () + message(FATAL_ERROR + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + ) + endif () +endif () + +get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PICO_SDK_PATH}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") +endif () + +set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) +if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") +endif () + +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) + +include(${PICO_SDK_INIT_CMAKE_FILE})