Skip to content

Commit a10cef3

Browse files
Add Teensy to automatic builds.
1 parent d41af30 commit a10cef3

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

Diff for: .github/workflows/ports_sparkfun.yml

+2
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"

Diff for: sparkfun_build.sh

+61-5
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,33 @@ 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+
# Convert the file to hex using hex using the command objcopy -O ihex <file> <output_file>
98+
# We need to get the output file name from the input file name
99+
OUTPUT_FILE=${OUT_DIRECTORY}/${OUTPUT_PREFIX}$(echo $file | sed -n "s/.*${BUILD_PREFIX}\([^/]*\)\/${FILE_BASENAME}.${EXTENSION}/\1/p").hex
100+
# 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)
101+
objcopy -O ihex $file $OUTPUT_FILE
102+
else
103+
# Just move the file without converting it
104+
mv $file ${OUT_DIRECTORY}/${OUTPUT_PREFIX}$(echo $file | sed -n "s/.*${BUILD_PREFIX}\([^/]*\)\/${FILE_BASENAME}.${EXTENSION}/\1/p").${EXTENSION}
105+
fi
80106
done
81107
}
82108

@@ -117,19 +143,32 @@ function copy_all_for_prefix_esp32 {
117143
# $1: Qwiic directory
118144
# $2: BOARD directory
119145
# $3: Board prefix
146+
# $4: The file to add the frozen manifest line to (e.g. mpconfigboard.cmake or mpconfigboard.mk.) Default: mpconfigboard.cmake
120147
function add_qwiic_manifest {
121148
local QWIIC_DIRECTORY=$1 # The directory where the Qwiic drivers are located to be frozen
122149
local BOARD_DIRECTORY=$2 # The directory where the boards are located (e.g. ports/rp2/boards)
123150
local BOARD_PREFIX=$3 # The prefix of the SparkFun board directories (e.g. SPARKFUN_)
151+
local MPCONFIG_FILE="${4:-mpconfigboard.cmake}" # The file to add the frozen manifest line to (e.g. mpconfigboard.cmake or mpconfigboard.mk. )
124152

125153
for board in $(find ${BOARD_DIRECTORY} -type d -name "${BOARD_PREFIX}*"); do
154+
echo "Adding Qwiic drivers to manifest.py for $board"
126155
if [ ! -f ${board}/manifest.py ]; then
127156
echo "Creating manifest.py for $board"
128157
echo "include(\"\$(PORT_DIR)/boards/manifest.py\")" > ${board}/manifest.py
129158

130159
# also add the necessary frozen manifest line to mpconfigboard.cmake: set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
131-
echo "Adding frozen manifest line to mpconfigboard.cmake for $board"
132-
printf "\nset(MICROPY_FROZEN_MANIFEST \"\${MICROPY_BOARD_DIR}/manifest.py\")" >> ${board}/mpconfigboard.cmake
160+
# We will use the optional MPCONFIG_FILE argument to determine if we should add this line
161+
162+
if [ -n "$MPCONFIG_FILE" ]; then
163+
if [[ $MPCONFIG_FILE == *.mk ]]; then
164+
# For TEENSY which use mpconfigboard.mk instead of mpconfigboard.cmake
165+
echo "Adding frozen manifest line to mpconfigboard.mk for $board"
166+
printf "\nFROZEN_MANIFEST ?= \$(BOARD_DIR)/manifest.py" >> ${board}/mpconfigboard.mk
167+
elif [[ $MPCONFIG_FILE == *.cmake ]]; then
168+
echo "Adding frozen manifest line to mpconfigboard.cmake for $board"
169+
printf "\nset(MICROPY_FROZEN_MANIFEST \"\${MICROPY_BOARD_DIR}/manifest.py\")" >> ${board}/mpconfigboard.cmake
170+
fi
171+
fi
133172
fi
134173

135174
echo "Adding freeze line to manifest.py for $board"
@@ -174,12 +213,18 @@ function build_sparkfun {
174213
# Perform minimal build for RP2
175214
build_all_sparkfun_boards_rp2 false
176215

216+
# Perform minimal build for mimxrt
217+
build_all_sparkfun_boards_mimxrt false
218+
177219
# Copy all esp32 binary files to the output directory
178220
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" "MINIMAL_${OUTPUT_FILE_PREFIX}"
179221

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

225+
# Copy all mimxrt teensy binary files to the output directory
226+
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/mimxrt" "build-TEENSY" "firmware" "elf" "MINIMAL_${OUTPUT_FILE_PREFIX}TEENSY_" true
227+
183228
echo "Downloading Qwiic library and adding to manifest.py for SparkFun boards"
184229
# Perform Qwiic download
185230
download_qwiic_release ${QWIIC_DIRECTORY}
@@ -190,18 +235,29 @@ function build_sparkfun {
190235

191236
# Add the downloaded Qwiic drivers to the manifest.py for each rp2 board
192237
add_qwiic_manifest "../../../../${QWIIC_DIRECTORY}" "ports/rp2/boards" "SPARKFUN_"
238+
239+
# 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)
240+
add_qwiic_manifest "../../../../${QWIIC_DIRECTORY}" "ports/mimxrt/boards" "TEENSY40" "mpconfigboard.mk"
241+
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
193242

194-
echo "Performing full SparkFun build for ESP32 and RP2"
243+
echo "Performing full SparkFun build for ESP32, RP2, and mimxrt"
195244

196245
# Perform Qwiic Build for ESP32
197246
build_all_sparkfun_boards_esp32 false
198247

199248
# Perform Qwiic Build for RP2
200249
build_all_sparkfun_boards_rp2 false
201250

251+
# Perform Qwiic build for mimxrt
252+
build_all_sparkfun_boards_mimxrt false
253+
202254
# Copy all esp32 binary files to the output directory
203255
copy_all_for_prefix_esp32 ${OUTPUT_DIRECTORY} "ports/esp32" "build-SPARKFUN_" ${OUTPUT_FILE_PREFIX}
204256

205257
# Copy all rp2 binary files to the output directory
206258
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/rp2" "build-SPARKFUN_" "firmware" "uf2" ${OUTPUT_FILE_PREFIX}
259+
260+
# Copy all mimxrt teensy binary files to the output directory
261+
copy_all_for_prefix ${OUTPUT_DIRECTORY} "ports/mimxrt" "build-TEENSY" "firmware" "elf" "${OUTPUT_FILE_PREFIX}TEENSY_" true
207262
}
263+

0 commit comments

Comments
 (0)