└── pico_setup.sh /pico_setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Exit on error 4 | set -e 5 | 6 | if grep -q Raspberry /proc/cpuinfo; then 7 | echo "Running on a Raspberry Pi" 8 | else 9 | echo "Not running on a Raspberry Pi. Use at your own risk!" 10 | fi 11 | 12 | # Number of cores when running make 13 | JNUM=4 14 | 15 | # Where will the output go? 16 | OUTDIR="$(pwd)/pico" 17 | 18 | # Install dependencies 19 | GIT_DEPS="git" 20 | SDK_DEPS="cmake gcc-arm-none-eabi gcc g++" 21 | OPENOCD_DEPS="gdb-multiarch automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev" 22 | # Wget to download the deb 23 | VSCODE_DEPS="wget" 24 | UART_DEPS="minicom" 25 | 26 | # Build full list of dependencies 27 | DEPS="$GIT_DEPS $SDK_DEPS" 28 | 29 | if [[ "$SKIP_OPENOCD" == 1 ]]; then 30 | echo "Skipping OpenOCD (debug support)" 31 | else 32 | DEPS="$DEPS $OPENOCD_DEPS" 33 | fi 34 | 35 | if [[ "$SKIP_VSCODE" == 1 ]]; then 36 | echo "Skipping VSCODE" 37 | else 38 | DEPS="$DEPS $VSCODE_DEPS" 39 | fi 40 | 41 | echo "Installing Dependencies" 42 | sudo apt update 43 | sudo apt install -y $DEPS 44 | 45 | echo "Creating $OUTDIR" 46 | # Create pico directory to put everything in 47 | mkdir -p $OUTDIR 48 | cd $OUTDIR 49 | 50 | # Clone sw repos 51 | GITHUB_PREFIX="https://github.com/raspberrypi/" 52 | GITHUB_SUFFIX=".git" 53 | SDK_BRANCH="master" 54 | 55 | for REPO in sdk examples extras playground 56 | do 57 | DEST="$OUTDIR/pico-$REPO" 58 | 59 | if [ -d $DEST ]; then 60 | echo "$DEST already exists so skipping" 61 | else 62 | REPO_URL="${GITHUB_PREFIX}pico-${REPO}${GITHUB_SUFFIX}" 63 | echo "Cloning $REPO_URL" 64 | git clone -b $SDK_BRANCH $REPO_URL 65 | 66 | # Any submodules 67 | cd $DEST 68 | git submodule update --init 69 | cd $OUTDIR 70 | 71 | # Define PICO_SDK_PATH in ~/.bashrc 72 | VARNAME="PICO_${REPO^^}_PATH" 73 | echo "Adding $VARNAME to ~/.bashrc" 74 | echo "export $VARNAME=$DEST" >> ~/.bashrc 75 | export ${VARNAME}=$DEST 76 | fi 77 | done 78 | 79 | cd $OUTDIR 80 | 81 | # Pick up new variables we just defined 82 | source ~/.bashrc 83 | 84 | # Build a couple of examples 85 | cd "$OUTDIR/pico-examples" 86 | mkdir build 87 | cd build 88 | cmake ../ -DCMAKE_BUILD_TYPE=Debug 89 | 90 | for e in blink hello_world 91 | do 92 | echo "Building $e" 93 | cd $e 94 | make -j$JNUM 95 | cd .. 96 | done 97 | 98 | cd $OUTDIR 99 | 100 | # Picoprobe and picotool 101 | for REPO in picoprobe picotool 102 | do 103 | DEST="$OUTDIR/$REPO" 104 | REPO_URL="${GITHUB_PREFIX}${REPO}${GITHUB_SUFFIX}" 105 | git clone $REPO_URL 106 | 107 | # Build both 108 | cd $DEST 109 | mkdir build 110 | cd build 111 | cmake ../ 112 | make -j$JNUM 113 | 114 | if [[ "$REPO" == "picotool" ]]; then 115 | echo "Installing picotool to /usr/local/bin/picotool" 116 | sudo cp picotool /usr/local/bin/ 117 | fi 118 | 119 | cd $OUTDIR 120 | done 121 | 122 | if [ -d openocd ]; then 123 | echo "openocd already exists so skipping" 124 | SKIP_OPENOCD=1 125 | fi 126 | 127 | if [[ "$SKIP_OPENOCD" == 1 ]]; then 128 | echo "Won't build OpenOCD" 129 | else 130 | # Build OpenOCD 131 | echo "Building OpenOCD" 132 | cd $OUTDIR 133 | # Should we include picoprobe support (which is a Pico acting as a debugger for another Pico) 134 | INCLUDE_PICOPROBE=1 135 | OPENOCD_BRANCH="rp2040" 136 | OPENOCD_CONFIGURE_ARGS="--enable-ftdi --enable-sysfsgpio --enable-bcm2835gpio" 137 | if [[ "$INCLUDE_PICOPROBE" == 1 ]]; then 138 | OPENOCD_BRANCH="picoprobe" 139 | OPENOCD_CONFIGURE_ARGS="$OPENOCD_CONFIGURE_ARGS --enable-picoprobe" 140 | fi 141 | 142 | git clone "${GITHUB_PREFIX}openocd${GITHUB_SUFFIX}" -b $OPENOCD_BRANCH --depth=1 143 | cd openocd 144 | ./bootstrap 145 | ./configure $OPENOCD_CONFIGURE_ARGS 146 | make -j$JNUM 147 | sudo make install 148 | fi 149 | 150 | cd $OUTDIR 151 | 152 | # Liam needed to install these to get it working 153 | EXTRA_VSCODE_DEPS="libx11-xcb1 libxcb-dri3-0 libdrm2 libgbm1 libegl-mesa0" 154 | if [[ "$SKIP_VSCODE" == 1 ]]; then 155 | echo "Won't include VSCODE" 156 | else 157 | if [ -f vscode.deb ]; then 158 | echo "Skipping vscode as vscode.deb exists" 159 | else 160 | echo "Installing VSCODE" 161 | if uname -m | grep -q aarch64; then 162 | VSCODE_DEB="https://aka.ms/linux-arm64-deb" 163 | else 164 | VSCODE_DEB="https://aka.ms/linux-armhf-deb" 165 | fi 166 | 167 | wget -O vscode.deb $VSCODE_DEB 168 | sudo apt install -y ./vscode.deb 169 | sudo apt install -y $EXTRA_VSCODE_DEPS 170 | 171 | # Get extensions 172 | code --install-extension marus25.cortex-debug 173 | code --install-extension ms-vscode.cmake-tools 174 | code --install-extension ms-vscode.cpptools 175 | fi 176 | fi 177 | 178 | # Enable UART 179 | if [[ "$SKIP_UART" == 1 ]]; then 180 | echo "Skipping uart configuration" 181 | else 182 | sudo apt install -y $UART_DEPS 183 | echo "Disabling Linux serial console (UART) so we can use it for pico" 184 | sudo raspi-config nonint do_serial 2 185 | echo "You must run sudo reboot to finish UART setup" 186 | fi 187 | --------------------------------------------------------------------------------