@@ -19,9 +19,10 @@ function download_qwiic_release {
19
19
# Builds all SparkFun boards for the given port
20
20
# Options:
21
21
# $1: Port name
22
+ # $2: [Optional] Prefix for the SparkFun board directories for port(default: "-SPARKFUN_")
22
23
function build_for_port {
23
24
local TARGET_PORT_NAME=$1
24
- local SPARKFUN_PREFIX=" SPARKFUN_"
25
+ local SPARKFUN_PREFIX=${2 :- SPARKFUN_}
25
26
local SPARKFUN_BOARD_PREFIX=" ports/${TARGET_PORT_NAME} /boards/${SPARKFUN_PREFIX} *"
26
27
27
28
for board in $SPARKFUN_BOARD_PREFIX ; do
@@ -56,6 +57,17 @@ function build_all_sparkfun_boards_esp32 {
56
57
build_for_port " esp32"
57
58
}
58
59
60
+ # Builds all Teensy mimxrt boards
61
+ # Options:
62
+ # $1: Whether to build the cross compiler
63
+ function build_all_sparkfun_boards_mimxrt {
64
+ if $1 ; then
65
+ make ${MAKEOPTS} -C mpy-cross
66
+ fi
67
+
68
+ build_for_port " mimxrt" " TEENSY"
69
+ }
70
+
59
71
# Copies all files with the given prefix from the SparkFun build directories to the output directory
60
72
# Options:
61
73
# $1: Output directory
@@ -64,19 +76,31 @@ function build_all_sparkfun_boards_esp32 {
64
76
# $4: File basename
65
77
# $5: Extension
66
78
# $6: Prefix to put on output files
79
+ # $7: [Optional] Convert file to hex (default: false)
67
80
function copy_all_for_prefix {
68
81
local OUT_DIRECTORY=$1
69
82
local PORT_DIRECTORY=$2 # The directory where the ports are located (e.g. ports/rp2)
70
83
local BUILD_PREFIX=$3 # The prefix of the SparkFun build directories (e.g. build-SPARKFUN_)
71
84
local FILE_BASENAME=$4 # the target base name of the file to copy from each SparkFun build directory (e.g. firmware)
72
85
local EXTENSION=$5 # The extension of the file to copy (e.g. uf2)
73
86
local OUTPUT_PREFIX=$6 # The prefix to put on the output files (e.g. MICROPYTHON_ or MINIMAL_MICROPYTHON_)
87
+ local CONVERT_TO_HEX=${7:- false} # Whether to convert the file to hex (default: false)
88
+
74
89
75
90
mkdir -p ${OUT_DIRECTORY}
76
91
77
92
for file in $( find ${PORT_DIRECTORY} -wholename " *${BUILD_PREFIX} */*${FILE_BASENAME} .${EXTENSION} " ) ; do
78
93
echo " Moving $file to ${OUT_DIRECTORY} "
79
- mv $file ${OUT_DIRECTORY} /${OUTPUT_PREFIX} $( echo $file | sed -n " s/.*${BUILD_PREFIX} \([^/]*\)\/${FILE_BASENAME} .${EXTENSION} /\1/p" ) .${EXTENSION}
94
+ # First, add the check to see if we need to convert the file to hex
95
+ if $CONVERT_TO_HEX ; then
96
+ echo " Converting $file to hex"
97
+ OUTPUT_FILE=${OUT_DIRECTORY} /${OUTPUT_PREFIX} $( echo $file | sed -n " s/.*${BUILD_PREFIX} \([^/]*\)\/${FILE_BASENAME} .${EXTENSION} /\1/p" ) .hex
98
+ # Use objcopy to convert the file to hex and move it to the output directory (maybe unnecessary if the .hex file is already available from the build)
99
+ objcopy -O ihex $file $OUTPUT_FILE
100
+ else
101
+ # Just move the file without converting it
102
+ mv $file ${OUT_DIRECTORY} /${OUTPUT_PREFIX} $( echo $file | sed -n " s/.*${BUILD_PREFIX} \([^/]*\)\/${FILE_BASENAME} .${EXTENSION} /\1/p" ) .${EXTENSION}
103
+ fi
80
104
done
81
105
}
82
106
@@ -117,15 +141,32 @@ function copy_all_for_prefix_esp32 {
117
141
# $1: Qwiic directory
118
142
# $2: BOARD directory
119
143
# $3: Board prefix
144
+ # $4: The file to add the frozen manifest line to (e.g. mpconfigboard.cmake or mpconfigboard.mk.) Default: mpconfigboard.cmake
120
145
function add_qwiic_manifest {
121
146
local QWIIC_DIRECTORY=$1 # The directory where the Qwiic drivers are located to be frozen
122
147
local BOARD_DIRECTORY=$2 # The directory where the boards are located (e.g. ports/rp2/boards)
123
148
local BOARD_PREFIX=$3 # The prefix of the SparkFun board directories (e.g. SPARKFUN_)
149
+ local MPCONFIG_FILE=" ${4:- mpconfigboard.cmake} " # The file to add the frozen manifest line to (e.g. mpconfigboard.cmake or mpconfigboard.mk. )
124
150
125
151
for board in $( find ${BOARD_DIRECTORY} -type d -name " ${BOARD_PREFIX} *" ) ; do
152
+ echo " Adding Qwiic drivers to manifest.py for $board "
126
153
if [ ! -f ${board} /manifest.py ]; then
127
154
echo " Creating manifest.py for $board "
128
- echo " include(\" ${BOARD_DIRECTORY} /manifest.py\" )" > ${board} /manifest.py
155
+ echo " include(\"\$ (PORT_DIR)/boards/manifest.py\" )" > ${board} /manifest.py
156
+
157
+ # also add the necessary frozen manifest line to mpconfigboard.cmake: set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
158
+ # We will use the optional MPCONFIG_FILE argument to determine if we should add this line
159
+
160
+ if [ -n " $MPCONFIG_FILE " ]; then
161
+ if [[ $MPCONFIG_FILE == * .mk ]]; then
162
+ # For TEENSY which use mpconfigboard.mk instead of mpconfigboard.cmake
163
+ echo " Adding frozen manifest line to mpconfigboard.mk for $board "
164
+ printf " \nFROZEN_MANIFEST ?= \$ (BOARD_DIR)/manifest.py" >> ${board} /mpconfigboard.mk
165
+ elif [[ $MPCONFIG_FILE == * .cmake ]]; then
166
+ echo " Adding frozen manifest line to mpconfigboard.cmake for $board "
167
+ printf " \nset(MICROPY_FROZEN_MANIFEST \"\$ {MICROPY_BOARD_DIR}/manifest.py\" )" >> ${board} /mpconfigboard.cmake
168
+ fi
169
+ fi
129
170
fi
130
171
131
172
echo " Adding freeze line to manifest.py for $board "
@@ -170,12 +211,18 @@ function build_sparkfun {
170
211
# Perform minimal build for RP2
171
212
build_all_sparkfun_boards_rp2 false
172
213
214
+ # Perform minimal build for mimxrt
215
+ build_all_sparkfun_boards_mimxrt false
216
+
173
217
# Copy all esp32 binary files to the output directory
174
218
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} " ports/esp32" " build-SPARKFUN_" " MINIMAL_${OUTPUT_FILE_PREFIX} "
175
219
176
220
# Copy all rp2 binary files to the output directory
177
221
copy_all_for_prefix ${OUTPUT_DIRECTORY} " ports/rp2" " build-SPARKFUN_" " firmware" " uf2" " MINIMAL_${OUTPUT_FILE_PREFIX} "
178
222
223
+ # Copy all mimxrt teensy binary files to the output directory
224
+ copy_all_for_prefix ${OUTPUT_DIRECTORY} " ports/mimxrt" " build-TEENSY" " firmware" " elf" " MINIMAL_${OUTPUT_FILE_PREFIX} TEENSY_" true
225
+
179
226
echo " Downloading Qwiic library and adding to manifest.py for SparkFun boards"
180
227
# Perform Qwiic download
181
228
download_qwiic_release ${QWIIC_DIRECTORY}
@@ -186,18 +233,29 @@ function build_sparkfun {
186
233
187
234
# Add the downloaded Qwiic drivers to the manifest.py for each rp2 board
188
235
add_qwiic_manifest " ../../../../${QWIIC_DIRECTORY} " " ports/rp2/boards" " SPARKFUN_"
236
+
237
+ # Add the downloaded Qwiic drivers to the manifest.py for each mimxrt teensy board (this might not work because they might lose their 40 vs. 41 when added)
238
+ add_qwiic_manifest " ../../../../${QWIIC_DIRECTORY} " " ports/mimxrt/boards" " TEENSY40" " mpconfigboard.mk"
239
+ add_qwiic_manifest " ../../../../${QWIIC_DIRECTORY} " " ports/mimxrt/boards" " TEENSY41" " " # We don't need to add the frozen manifest line to mpconfigboard.mk for TEENSY41, it is already there
189
240
190
- echo " Performing full SparkFun build for ESP32 and RP2 "
241
+ echo " Performing full SparkFun build for ESP32, RP2, and mimxrt "
191
242
192
243
# Perform Qwiic Build for ESP32
193
244
build_all_sparkfun_boards_esp32 false
194
245
195
246
# Perform Qwiic Build for RP2
196
247
build_all_sparkfun_boards_rp2 false
197
248
249
+ # Perform Qwiic build for mimxrt
250
+ build_all_sparkfun_boards_mimxrt false
251
+
198
252
# Copy all esp32 binary files to the output directory
199
253
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} " ports/esp32" " build-SPARKFUN_" ${OUTPUT_FILE_PREFIX}
200
254
201
255
# Copy all rp2 binary files to the output directory
202
256
copy_all_for_prefix ${OUTPUT_DIRECTORY} " ports/rp2" " build-SPARKFUN_" " firmware" " uf2" ${OUTPUT_FILE_PREFIX}
257
+
258
+ # Copy all mimxrt teensy binary files to the output directory
259
+ copy_all_for_prefix ${OUTPUT_DIRECTORY} " ports/mimxrt" " build-TEENSY" " firmware" " elf" " ${OUTPUT_FILE_PREFIX} TEENSY_" true
203
260
}
261
+
0 commit comments