Skip to content

Commit 4dbe9b9

Browse files
Add Teensy to automatic fw builds.
1 parent 678a697 commit 4dbe9b9

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

.github/workflows/ports_sparkfun.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
path: 'micropython repo'
2121
- name: Install RP2 package
2222
run: source tools/ci.sh && ci_rp2_setup
23+
# - name: Install mimxrt package # Currently redundant since it does the same arm setup as rp2, but in future if these diverge, uncomment this...
24+
# run: source tools/ci.sh && ci_mimxrt_setup
2325
- id: idf_ver
2426
name: Read the ESP-IDF version (including Python version)
2527
run: source tools/ci.sh && echo "IDF_VER=${IDF_VER}-py${PYTHON_VER}" | tee "$GITHUB_OUTPUT"
@@ -35,4 +37,3 @@ jobs:
3537
asset_path: "micropython repo/sparkfun_release/*"
3638
github_token: ${{ secrets.GITHUB_TOKEN }}
3739
upload_url: ${{ github.event.release.upload_url }}
38-

sparkfun_build.sh

+62-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ function download_qwiic_release {
1919
# Builds all SparkFun boards for the given port
2020
# Options:
2121
# $1: Port name
22+
# $2: [Optional] Prefix for the SparkFun board directories for port(default: "-SPARKFUN_")
2223
function build_for_port {
2324
local TARGET_PORT_NAME=$1
24-
local SPARKFUN_PREFIX="SPARKFUN_"
25+
local SPARKFUN_PREFIX=${2:-SPARKFUN_}
2526
local SPARKFUN_BOARD_PREFIX="ports/${TARGET_PORT_NAME}/boards/${SPARKFUN_PREFIX}*"
2627

2728
for board in $SPARKFUN_BOARD_PREFIX; do
@@ -56,6 +57,17 @@ function build_all_sparkfun_boards_esp32 {
5657
build_for_port "esp32"
5758
}
5859

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+
5971
# Copies all files with the given prefix from the SparkFun build directories to the output directory
6072
# Options:
6173
# $1: Output directory
@@ -64,19 +76,31 @@ function build_all_sparkfun_boards_esp32 {
6476
# $4: File basename
6577
# $5: Extension
6678
# $6: Prefix to put on output files
79+
# $7: [Optional] Convert file to hex (default: false)
6780
function copy_all_for_prefix {
6881
local OUT_DIRECTORY=$1
6982
local PORT_DIRECTORY=$2 # The directory where the ports are located (e.g. ports/rp2)
7083
local BUILD_PREFIX=$3 # The prefix of the SparkFun build directories (e.g. build-SPARKFUN_)
7184
local FILE_BASENAME=$4 # the target base name of the file to copy from each SparkFun build directory (e.g. firmware)
7285
local EXTENSION=$5 # The extension of the file to copy (e.g. uf2)
7386
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+
7489

7590
mkdir -p ${OUT_DIRECTORY}
7691

7792
for file in $(find ${PORT_DIRECTORY} -wholename "*${BUILD_PREFIX}*/*${FILE_BASENAME}.${EXTENSION}"); do
7893
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
80104
done
81105
}
82106

@@ -117,15 +141,32 @@ function copy_all_for_prefix_esp32 {
117141
# $1: Qwiic directory
118142
# $2: BOARD directory
119143
# $3: Board prefix
144+
# $4: The file to add the frozen manifest line to (e.g. mpconfigboard.cmake or mpconfigboard.mk.) Default: mpconfigboard.cmake
120145
function add_qwiic_manifest {
121146
local QWIIC_DIRECTORY=$1 # The directory where the Qwiic drivers are located to be frozen
122147
local BOARD_DIRECTORY=$2 # The directory where the boards are located (e.g. ports/rp2/boards)
123148
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. )
124150

125151
for board in $(find ${BOARD_DIRECTORY} -type d -name "${BOARD_PREFIX}*"); do
152+
echo "Adding Qwiic drivers to manifest.py for $board"
126153
if [ ! -f ${board}/manifest.py ]; then
127154
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
129170
fi
130171

131172
echo "Adding freeze line to manifest.py for $board"
@@ -170,12 +211,18 @@ function build_sparkfun {
170211
# Perform minimal build for RP2
171212
build_all_sparkfun_boards_rp2 false
172213

214+
# Perform minimal build for mimxrt
215+
build_all_sparkfun_boards_mimxrt false
216+
173217
# Copy all esp32 binary files to the output directory
174218
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" "MINIMAL_${OUTPUT_FILE_PREFIX}"
175219

176220
# Copy all rp2 binary files to the output directory
177221
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/rp2" "build-SPARKFUN_" "firmware" "uf2" "MINIMAL_${OUTPUT_FILE_PREFIX}"
178222

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+
179226
echo "Downloading Qwiic library and adding to manifest.py for SparkFun boards"
180227
# Perform Qwiic download
181228
download_qwiic_release ${QWIIC_DIRECTORY}
@@ -186,18 +233,29 @@ function build_sparkfun {
186233

187234
# Add the downloaded Qwiic drivers to the manifest.py for each rp2 board
188235
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
189240

190-
echo "Performing full SparkFun build for ESP32 and RP2"
241+
echo "Performing full SparkFun build for ESP32, RP2, and mimxrt"
191242

192243
# Perform Qwiic Build for ESP32
193244
build_all_sparkfun_boards_esp32 false
194245

195246
# Perform Qwiic Build for RP2
196247
build_all_sparkfun_boards_rp2 false
197248

249+
# Perform Qwiic build for mimxrt
250+
build_all_sparkfun_boards_mimxrt false
251+
198252
# Copy all esp32 binary files to the output directory
199253
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" ${OUTPUT_FILE_PREFIX}
200254

201255
# Copy all rp2 binary files to the output directory
202256
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
203260
}
261+

0 commit comments

Comments
 (0)