3
3
# Phase 0: Preflight check
4
4
# Verify baseline dependencies
5
5
6
- # Phase 1: Setup minimum dev environment
7
- # Install the toolchain
6
+ # Phase 1: Setup dev environment
7
+ # Install the software packages from APT or Homebrew
8
8
# Create a directory called pico
9
9
# Download the pico-sdk repository and submodules
10
- # Define env variables for repo : PICO_SDK_PATH
11
- # Configure the Raspberry Pi UART for use with Raspberry Pi Pico
10
+ # Define env variables: PICO_SDK_PATH
11
+ # On Raspberry Pi only: configure the UART for use with Raspberry Pi Pico
12
12
13
13
# Phase 2: Setting up tutorial repos
14
14
# Download pico-examples, pico-extras, pico-playground repositories, and submodules
24
24
set -e
25
25
# Show all commands
26
26
set -x
27
-
27
+ # Trying to use an non-existent variable is an error
28
+ set -u
28
29
29
30
# Number of cores when running make
30
31
JNUM=4
31
32
32
33
# Where will the output go?
33
- WORKING_DIR=" $( pwd) /pico"
34
+ if printenv TARGET_DIR; then
35
+ echo " Using target dir from \$ TARGET_DIR: ${TARGET_DIR} "
36
+ else
37
+ TARGET_DIR=" $( pwd) /pico"
38
+ echo " Using target dir: ${TARGET_DIR} "
39
+ fi
34
40
35
41
36
42
linux () {
@@ -73,7 +79,7 @@ raspberry_pi() {
73
79
}
74
80
75
81
phase_0 () {
76
- # Preflight the check
82
+ # Preflight check
77
83
# Checks the baseline dependencies. If you don't have these, this script won't work.
78
84
echo " Entering phase 0: Preflight check"
79
85
@@ -108,12 +114,12 @@ phase_0() {
108
114
fi
109
115
}
110
116
111
- install_toolchain_linux () {
112
- # Install toolchain for Linux
117
+ install_dev_env_deps_linux () {
118
+ # Install development environment dependencies for Linux
113
119
114
- DEPS=" python3 git cmake gcc-arm-none-eabi build-essential gdb-multiarch automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev"
120
+ DEPS=" python3 git cmake gcc-arm-none-eabi build-essential gdb-multiarch automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.0-0-dev minicom pkg-config "
115
121
if debian || ubuntu; then
116
- DEPS=" ${DEPS} pkg-config libstdc++-arm-none-eabi-newlib"
122
+ DEPS=" ${DEPS} libstdc++-arm-none-eabi-newlib"
117
123
fi
118
124
sudo apt install -y ${DEPS}
119
125
}
@@ -124,51 +130,55 @@ brew_install_idempotent() {
124
130
return ${?}
125
131
}
126
132
127
- install_toolchain_mac () {
128
- # Install dependencies for mac
133
+ install_dev_env_deps_mac () {
134
+ # Install development environment dependencies for mac
129
135
130
- brew_install_idempotent git cmake pkg-config libtool automake libusb wget pkg-config gcc texinfo
131
- brew tap ArmMbed/homebrew-formulae
132
- brew_install_idempotent arm-none-eabi-gcc
136
+ brew_install_idempotent git cmake pkg-config libtool automake libusb wget pkg-config gcc texinfo minicom ArmMbed/homebrew-formulae/arm-none-eabi-gcc
133
137
}
134
138
135
139
create_working_dir () {
136
140
# Creates ./pico directory if necessary
137
141
138
- mkdir -p " ${WORKING_DIR } "
142
+ mkdir -p " ${TARGET_DIR } "
139
143
}
140
144
141
- clone_repo () {
145
+ clone_raspberrypi_repo () {
142
146
# Clones the given repo name from GitHub and inits any submodules
143
147
# $1 should be the full name of the repo, ex: pico-sdk
144
148
# $2 should be the branch name. Defaults to master.
145
149
# all other args are passed to git clone
146
150
REPO_NAME=" ${1} "
147
- if shift && [ " ${1} " ]; then
151
+ if shift && [ ${ # } -gt 0 ]; then
148
152
BRANCH=" ${1} "
153
+ # Can't just say `shift` because `set -e` will think it's an error and terminate the script.
154
+ shift || true
149
155
else
150
156
BRANCH=master
151
157
fi
152
- if shift ; then
153
- # $* contains more args
154
- true
155
- fi
156
158
157
- cd " ${WORKING_DIR} "
159
+ # Save the working directory
160
+ pushd " ${TARGET_DIR} " >> /dev/null
158
161
159
162
REPO_URL=" https://github.com/raspberrypi/${REPO_NAME} .git"
160
- DEST=" ${WORKING_DIR } /${REPO_NAME} "
163
+ DEST=" ${TARGET_DIR } /${REPO_NAME} "
161
164
162
165
if [ -d " ${DEST} " ]; then
163
166
echo " Not cloning ${DEST} because it already exists. If you really want to start over, delete it: rm -rf ${DEST} "
164
167
else
165
168
echo " Cloning ${REPO_URL} "
166
- git clone -b " ${BRANCH} " " ${REPO_URL} " ${* }
169
+ if [ ${# } -gt 0 ]; then
170
+ git clone -b " ${BRANCH} " " ${REPO_URL} " ${* }
171
+ else
172
+ git clone -b " ${BRANCH} " " ${REPO_URL} "
173
+ fi
167
174
168
175
# Any submodules
169
176
cd " ${DEST} "
170
177
git submodule update --init
171
178
fi
179
+
180
+ # Restore working directory
181
+ popd >> /dev/null
172
182
}
173
183
174
184
set_env () {
@@ -187,10 +197,8 @@ set_env() {
187
197
188
198
# ensure that appends go to a new line
189
199
if [ -f " ${FILE} " ]; then
190
- if tail -n 1 " ${FILE} " | grep -q " ^$" ; then
191
- echo " ${FILE} exists and has trailing newline."
192
- else
193
- echo " ${FILE} exists but has no trailing newline. Adding newline."
200
+ if ! ( tail -n 1 " ${FILE} " | grep -q " ^$" ); then
201
+ # FILE exists but has no trailing newline. Adding newline.
194
202
echo >> " ${FILE} "
195
203
fi
196
204
fi
@@ -206,20 +214,15 @@ set_env() {
206
214
}
207
215
208
216
setup_sdk () {
209
- # Downloads and builds the SDK
210
- cd " ${WORKING_DIR} "
211
-
212
- clone_repo pico-sdk
217
+ # Download the SDK
218
+ clone_raspberrypi_repo pico-sdk
213
219
214
220
# Set env var PICO_SDK_PATH
215
- REPO_UPPER=$( echo ${REPO_NAME} | tr " [:lower:]" " [:upper:]" )
216
- REPO_UPPER=$( echo ${REPO_UPPER} | tr " -" " _" )
217
- set_env " ${REPO_UPPER} _PATH=$DEST "
221
+ set_env " PICO_SDK_PATH=${TARGET_DIR} /pico-sdk"
218
222
}
219
223
220
224
enable_uart () {
221
225
# Enable UART
222
- sudo apt install -y minicom
223
226
echo " Disabling Linux serial console (UART) so we can use it for pico"
224
227
sudo raspi-config nonint do_serial 2
225
228
echo " You must run sudo reboot to finish UART setup"
@@ -230,26 +233,26 @@ phase_1() {
230
233
echo " Entering phase 1: Setup minimum dev environment"
231
234
232
235
if mac; then
233
- install_toolchain_mac
236
+ install_dev_env_deps_mac
234
237
else
235
- install_toolchain_linux
238
+ install_dev_env_deps_linux
236
239
fi
237
240
238
241
create_working_dir
239
242
setup_sdk
240
243
241
- if raspbian && raspberry_pi ; then
244
+ if raspberry_pi && which raspi-config >> /dev/null ; then
242
245
enable_uart
243
246
else
244
- echo " Not configuring UART because this is not running Raspberry Pi OS on a Raspberry Pi computer "
247
+ echo " Not configuring UART because this is not a Raspberry Pi computer, or raspi-config is unavailable. "
245
248
fi
246
249
}
247
250
248
251
build_examples () {
249
252
# Build a couple of examples
250
253
echo " Building selected examples"
251
254
252
- cd " $WORKING_DIR /pico-examples"
255
+ cd " $TARGET_DIR /pico-examples"
253
256
mkdir -p build
254
257
cd build
255
258
cmake ../ -DCMAKE_BUILD_TYPE=Debug
@@ -267,7 +270,7 @@ phase_2() {
267
270
echo " Entering phase 2: Setting up tutorial repos"
268
271
269
272
for REPO_NAME in pico-examples pico-extras pico-playground; do
270
- clone_repo " ${REPO_NAME} "
273
+ clone_raspberrypi_repo " ${REPO_NAME} "
271
274
done
272
275
273
276
build_examples
@@ -277,10 +280,10 @@ setup_picotool() {
277
280
# Downloads, builds, and installs picotool
278
281
echo " Setting up picotool"
279
282
280
- cd " ${WORKING_DIR } "
283
+ cd " ${TARGET_DIR } "
281
284
282
- clone_repo picotool
283
- cd " ${WORKING_DIR } /picotool"
285
+ clone_raspberrypi_repo picotool
286
+ cd " ${TARGET_DIR } /picotool"
284
287
mkdir -p build
285
288
cd build
286
289
cmake ../
@@ -294,10 +297,10 @@ setup_openocd() {
294
297
# Download, build, and install OpenOCD for picoprobe and bit-banging without picoprobe
295
298
echo " Setting up OpenOCD"
296
299
297
- cd " ${WORKING_DIR } "
300
+ cd " ${TARGET_DIR } "
298
301
299
- clone_repo openocd picoprobe --depth=1
300
- cd " ${WORKING_DIR } /openocd"
302
+ clone_raspberrypi_repo openocd picoprobe --depth=1
303
+ cd " ${TARGET_DIR } /openocd"
301
304
./bootstrap
302
305
OPTS=" --enable-ftdi --enable-bcm2835gpio --enable-picoprobe"
303
306
if linux; then
@@ -313,10 +316,10 @@ setup_picoprobe() {
313
316
# Download and build picoprobe. Requires that OpenOCD is already setup
314
317
echo " Setting up picoprobe"
315
318
316
- cd " ${WORKING_DIR } "
319
+ cd " ${TARGET_DIR } "
317
320
318
- clone_repo picoprobe
319
- cd " ${WORKING_DIR } /picoprobe"
321
+ clone_raspberrypi_repo picoprobe
322
+ cd " ${TARGET_DIR } /picoprobe"
320
323
mkdir -p build
321
324
cd build
322
325
cmake ..
@@ -326,16 +329,14 @@ setup_picoprobe() {
326
329
install_vscode_linux () {
327
330
# Install Visual Studio Code
328
331
329
- # VS Code is specially added to Raspberry Pi OS repos. Need to add the right repos to make it work on Debian/Ubuntu.
330
- if debian || ubuntu ; then
331
- echo " Not yet implemented: testing Visual Studio Code on Debian/Ubuntu "
332
+ # VS Code is specially added to Raspberry Pi OS repos, but might not be present on Debian/Ubuntu. So we check first .
333
+ if ! apt list code ; then
334
+ echo " It appears that your APT repos do not offer Visual Studio Code. Skipping. "
332
335
return
333
336
fi
334
337
335
338
echo " Installing Visual Studio Code"
336
339
337
- cd " ${WORKING_DIR} "
338
-
339
340
sudo apt install -y code
340
341
341
342
# Get extensions
@@ -374,7 +375,7 @@ main() {
374
375
phase_2
375
376
phase_3
376
377
377
- echo " Congratulations, installation is complete. 😁 "
378
+ echo " Congratulations, installation is complete. :D "
378
379
}
379
380
380
381
main
0 commit comments