diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index c808b1b..91a35a5 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,24 +1,57 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/cpp/.devcontainer/base.Dockerfile - -# [Choice] Debian / Ubuntu version: debian-10, debian-9, ubuntu-20.04, ubuntu-18.04 ARG VARIANT="ubuntu-20.04" FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT} -# [Optional] Uncomment this section to install additional packages. -RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends cmake build-essential wget ca-certificates \ - gdb-multiarch automake autoconf libtool libftdi-dev libusb-1.0-0-dev pkg-config clang-format +RUN apt-get update && \ + export DEBIAN_FRONTEND=noninteractive && \ + apt-get -y install --no-install-recommends \ + cmake \ + build-essential \ + wget \ + ca-certificates \ + gdb-multiarch \ + binutils-multiarch \ + automake \ + autoconf \ + libtool \ + libftdi-dev \ + libusb-1.0-0-dev \ + pkg-config \ + clang-format \ + python3 \ + python3-tk WORKDIR /apps -RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 && \ +RUN wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 && \ tar xjf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 RUN mv gcc-arm-none-eabi-10.3-2021.10 gcc-arm-none && \ + ln -s /apps/gcc-arm-none/bin/arm-none-eabi-gcc /usr/bin/arm-none-eabi-gcc && \ rm gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 ENV PATH=$PATH:/apps/gcc-arm-none/bin -RUN git clone -b master https://github.com/raspberrypi/pico-sdk.git --depth=1 && cd pico-sdk && git submodule update --init +RUN cd /apps && \ + git clone -b master https://github.com/raspberrypi/pico-sdk.git --depth=1 && \ + cd pico-sdk && \ + git submodule update --init ENV PICO_SDK_PATH=/apps/pico-sdk -RUN git clone https://github.com/raspberrypi/openocd.git -b picoprobe --depth=1 \ - && cd openocd && ./bootstrap && ./configure --enable-ftdi --enable-sysfsgpio --enable-picoprobe && make -j 8 install \ - && cd /apps && git clone https://github.com/raspberrypi/picotool.git --depth=1 \ - && cd picotool && mkdir build && cd build && cmake ../ && make -j 8 && cp picotool /usr/local/bin \ - && cd /apps && git clone https://github.com/wtarreau/bootterm.git --depth=1 \ - && cd bootterm && make -j 8 install +RUN cd /apps && \ + git clone -b master https://github.com/raspberrypi/pico-extras.git --depth=1 \ + && cd pico-extras && \ + git submodule update --init +ENV PICO_EXTRAS_PATH=/apps/pico-extras +RUN cd /apps && \ + git clone https://github.com/raspberrypi/pico-project-generator.git +ENV PATH=$PATH:/apps/pico-project-generator +RUN cd /apps && \ + git clone https://github.com/codaris/picovga-cmake.git pico-vga +ENV PICOVGA_PATH=/apps/pico-vga +RUN cd /apps && \ + git clone https://github.com/earlephilhower/arduino-pico.git arduino-pico +ENV ARDUINO_PICO_PATH=/apps/arduino-pico +RUN cd /apps && \ + git clone https://github.com/earlephilhower/ArduinoCore-API.git arduino-core +ENV ARDUINO_CORE_PATH=/apps/arduino-core +RUN git clone https://github.com/raspberrypi/openocd.git -b picoprobe --depth=1 && \ + cd openocd && ./bootstrap && ./configure --disable-werror --enable-ftdi --enable-sysfsgpio --enable-picoprobe && make -j 8 install && \ + cd /apps && git clone https://github.com/raspberrypi/picotool.git --depth=1 && \ + cd picotool && mkdir build && cd build && cmake ../ && make -j 8 && cp picotool /usr/local/bin && \ + cd /apps && git clone https://github.com/wtarreau/bootterm.git --depth=1 && \ + cd bootterm && make -j 8 install +RUN cd /usr/bin && ln -s /usr/bin/objdump objdump-multiarch && ln -s /usr/bin/nm nm-multiarch diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ba6d0e8..8abd80d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,38 +1,51 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: // https://github.com/mwinters-stuff/vscode-devcontainer-raspberrypi-pico { - "name": "C++ Raspberry Pi Pico", - "build": { - "dockerfile": "Dockerfile", - }, - "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined", "--device=/dev/bus/usb", "--device=/dev/ttyACM0"], - - // Set *default* container specific settings.json values on container create. - "settings": { - "terminal.integrated.profiles.linux": { - "bash": { - "path": "/usr/bin/bash" - }, - } - }, + "name": "C++ Raspberry Pi Pico", + "build": { + "dockerfile": "Dockerfile" + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined", + "--privileged", + "-v", "/dev/bus/usb:/dev/bus/usb", + "--device=/dev/bus/usb", + "--device=/dev/ttyACM0" + ], + + // Set *default* container specific settings.json values on container create. + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/usr/bin/bash" + } + } + }, - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "ms-vscode.cpptools", - "marus25.cortex-debug", - "ms-vscode.cmake-tools", - "twxs.cmake", - "eamodio.gitlens", - "xaver.clang-format", - "chris-hock.pioasm" - ], + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.cpptools", + "marus25.cortex-debug", + "ms-vscode.cmake-tools", + "twxs.cmake", + "eamodio.gitlens", + "xaver.clang-format", + "chris-hock.pioasm", + "ms-vscode.cpptools-extension-pack" + ] + } + }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "gcc -v", + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "gcc -v", - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" } diff --git a/.vscode/launch.json b/.vscode/launch.json index 87909de..6fd1b04 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -18,7 +18,7 @@ "target/rp2040.cfg" ], "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", - "runToMain": true, + "runToEntryPoint": "main", // Give restart the same functionality as runToMain "postRestartCommands": [ "break main", diff --git a/CMakeLists.txt b/CMakeLists.txt index 346deb0..ffac705 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_CXX_STANDARD 17) # set(PICO_SDK_PATH "/home/mathew/src/pico/pico-sdk") # Pull in Raspberry Pi Pico SDK (must be before project) -include(pico_sdk_import.cmake) +include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) project(TestProject C CXX ASM) @@ -21,24 +21,24 @@ pico_sdk_init() # Add executable. Default name is the project name, version 0.1 -add_executable(TestProject TestProject.cpp ) +add_executable(${PROJECT_NAME} TestProject.cpp ) -pico_set_program_name(TestProject "TestProject") -pico_set_program_version(TestProject "0.1") +#pico_set_program_name(${PROJECT_NAME} "TestProject") +#pico_set_program_version(${PROJECT_NAME} "0.1") -pico_enable_stdio_uart(TestProject 1) -pico_enable_stdio_usb(TestProject 0) +pico_enable_stdio_uart(${PROJECT_NAME} 0) +pico_enable_stdio_usb(${PROJECT_NAME} 1) # Add the standard library to the build -target_link_libraries(TestProject pico_stdlib) +target_link_libraries(${PROJECT_NAME} pico_stdlib) # Add any user requested libraries -target_link_libraries(TestProject +target_link_libraries(${PROJECT_NAME} hardware_spi hardware_i2c hardware_dma hardware_clocks ) -pico_add_extra_outputs(TestProject) +pico_add_extra_outputs(${PROJECT_NAME}) diff --git a/README.md b/README.md index ee2a844..7590adf 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,69 @@ -# vscode-devcontainer-raspberrypi-pico [![Create docker image](https://github.com/mwinters-stuff/vscode-devcontainer-raspberrypi-pico/actions/workflows/build-image.yml/badge.svg)](https://github.com/mwinters-stuff/vscode-devcontainer-raspberrypi-pico/actions/workflows/build-image.yml) -VSCode Dev Container for the Raspberry PI Pico C SDK +# vscode-devcontainer-raspberrypi-pico -## Usage - -Clone or download repository, copy the contents of .devcontainer into your project -Remove any existing "build" directory. - -Open the folder, and allow the container to build. - -# To know -* SDK is installed in /pico-sdk -* All USB devices are exported to container - so the picoprobe can be found and used. -* USB Device /dev/ttyACM0 is exported to container for monitoring +## VSCode Dev Container for the Raspberry PI Pico C SDK ## This container includes + * pico-sdk +* pico-extras +* pico-project-generator +* pico-vga +* arduino-pico +* arduino-core * openocd - compiled for picoprobe +* arduino libraries * picotool * bootterm (for serial monitoring) - see https://github.com/wtarreau/bootterm +## Usage + +**For an existing project** + +* Clone or download the repository +* Copy the contents of .devcontainer into your project +* Copy the contents of .vscode into your project +* Remove any existing "build" directory. +* Open the folder in VSCode and allow the container to build. + +**For a new project** + +* Create the folder where you want to create the project. +* Copy the contents of .devcontainer into your project +* Copy the contents of .vscode into your project +* Open the folder in VSCode. When prompted reopen the folder in the container. +* Open a terminal in the dev container and execute the command "pico_project.py --gui". +* Change the project name to the name of your folder. Change the location to "/workspaces". +* Configure the rest of the project as desired but do not select Create VSCode project under the IDE options. +* Click OK to generate the code. +* Click Quit to exit the code generator. + +**Build and debug the project** + +* In the VSCode project Explorer pane, delete the project's build folder. +* In the VSCode left hand pane, select the Run and Debug icon +* In VSCode, press P and select the command CMake: Select a Kit +* Select the GCC 10.3.1 arm-none-eabi compiler. +* In VSCode, press P and select the command CMake: Select a Variant +* Select the Debug variant +* At the top of the screen in the Run and Debug dropdown select Cortext Debug +* Click the green arrow. If prompted to select a launch target select your project. +* The project will build and run in the debugger. + +## Environment Variables + +* PICO_SDK_PATH=/apps/pico-sdk +* PICO_EXTRAS_PATH=/apps/pico-extras +* PICOVGA_PATH=/apps/pico-vga +* ARDUINO_PICO_PATH=/apps/arduino-pico +* ARDUINO_CORE_PATH=/apps/arduino-core + +## To know + +* SDK is installed in /apps/pico-sdk +* EXTRAS is installed in /apps/pico-extras +* PICO-PROJECT-GENERATOR is installed in /apps/pico-project-generator +* PICO-VGA is installed in /apps/pico-vga +* Arduino pico libraries are available in /apps/arduino-pico +* Arduino core libraries are available in /apps/arduino-core +* All USB devices are exported to container - so the picoprobe can be found and used. +* USB Device /dev/ttyACM0 is exported to container for monitoring