Skip to content

Commit dc731c5

Browse files
Fix teensy compile and board discovery for arduino-cli (#1261) (#1273)
* Fix teensy compile and board discovery for arduino-cli * Updated CI workflow * Updated to newest platform.txt (cherry picked from commit 14f1a6c) Co-authored-by: fraxker <[email protected]>
1 parent 84d9cfd commit dc731c5

File tree

2 files changed

+57
-31
lines changed

2 files changed

+57
-31
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,21 @@ jobs:
2727
echo '''board_manager:
2828
additional_urls:
2929
- https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json
30-
- https://github.com/espressif/arduino-esp32/releases/download/2.0.2/package_esp32_index.json''' > arduino-cli.yaml
30+
- https://github.com/espressif/arduino-esp32/releases/download/2.0.2/package_esp32_index.json
31+
- https://www.pjrc.com/teensy/td_156/package_teensy_index.json''' > arduino-cli.yaml
3132
curl -fsSL https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json -o /github/home/.arduino15/package_opencr_index.json
3233
curl -fsSL https://github.com/espressif/arduino-esp32/releases/download/2.0.2/package_esp32_index.json -o /github/home/.arduino15/package_esp32_index.json
34+
curl -fsSL https://www.pjrc.com/teensy/td_156/package_teensy_index.json -o /github/home/.arduino15/package_teensy_index.json
3335
export PATH=$PATH:/github/workspace/bin:/__w/micro_ros_arduino/micro_ros_arduino/bin
3436
arduino-cli core install OpenCR:OpenCR -v
3537
arduino-cli core install arduino:samd -v
3638
arduino-cli core install arduino:sam -v
3739
arduino-cli core install arduino:mbed -v
3840
arduino-cli core install esp32:esp32 -v
39-
#
40-
# INSTALLING TEENSY SUPPORT
41-
wget https://downloads.arduino.cc/arduino-1.8.19-linux64.tar.xz
42-
tar -xf arduino-1.8.19-linux64.tar.xz
43-
wget https://www.pjrc.com/teensy/td_156/TeensyduinoInstall.linux64
44-
chmod 755 TeensyduinoInstall.linux64
45-
./TeensyduinoInstall.linux64 --dir=arduino-1.8.19
46-
# Faking Teensy loader
47-
TRUE_PATH=$(which true)
48-
rm -rf arduino-1.8.19/hardware/tools/teensy_post_compile
49-
cp $TRUE_PATH arduino-1.8.19/hardware/tools/teensy_post_compile
50-
cp -R arduino-1.8.19/hardware/teensy/ /github/home/.arduino15/packages/
51-
rsync -a arduino-1.8.19/hardware/tools/ /github/home/.arduino15/packages/tools/
52-
rm -rf arduino-1.8.19 arduino-1.8.19-linux64.tar.xz
41+
arduino-cli core install teensy:avr -v
5342
#
5443
# PATCHING TEENSY AND SAM
55-
cat checkout/extras/patching_boards/platform_teensy.txt > /github/home/.arduino15/packages/teensy/avr/platform.txt
44+
cat checkout/extras/patching_boards/platform_teensy.txt > /github/home/.arduino15/packages/teensy/hardware/avr/1.57.2/platform.txt
5645
# remove when https://github.com/arduino/ArduinoCore-sam/pull/115 merged
5746
cat checkout/extras/patching_boards/platform_arduinocore_sam.txt > /github/home/.arduino15/packages/arduino/hardware/sam/1.6.12/platform.txt
5847
#

extras/patching_boards/platform_teensy.txt

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
# http://www.pjrc.com/teensy/teensyduino.html
21
name=Teensyduino
32
version=1.8.5
43
rewriting=disabled
54

6-
compiler.path={runtime.hardware.path}/../tools/
5+
# Teensyduino Installer
6+
#compiler.path={runtime.hardware.path}/../tools/
7+
#teensytools.path={runtime.hardware.path}/../tools/
8+
9+
# Arduino Boards Manager
10+
compiler.path={runtime.tools.teensy-compile.path}/
11+
teensytools.path={runtime.tools.teensy-tools.path}/
12+
13+
14+
15+
## EEPROM Data
716
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
817
compiler.elf2hex.flags=-O ihex -R .eeprom
918
compiler.libraries.ldflags=
@@ -20,7 +29,7 @@ tools.arduino-preprocessor.cmd.path={path}/arduino-preprocessor
2029
tools.arduino-preprocessor.pattern="{cmd.path}" "{source_file}" "{codecomplete}" -- -std=gnu++14
2130

2231
## Precompile Arduino.h header
23-
recipe.hooks.sketch.prebuild.1.pattern="{compiler.path}precompile_helper" "{runtime.platform.path}/cores/{build.core}" "{build.path}" "{compiler.path}{build.toolchain}{build.command.g++}" -x c++-header {build.flags.optimize} {build.flags.common} {build.flags.dep} {build.flags.cpp} {build.flags.cpu} {build.flags.defs} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DF_CPU={build.fcpu} -D{build.usbtype} -DLAYOUT_{build.keylayout} "-I{runtime.platform.path}/cores/{build.core}" "{build.path}/pch/Arduino.h" -o "{build.path}/pch/Arduino.h.gch"
32+
recipe.hooks.sketch.prebuild.1.pattern="{teensytools.path}precompile_helper" "{runtime.platform.path}/cores/{build.core}" "{build.path}" "{compiler.path}{build.toolchain}{build.command.g++}" -x c++-header {build.flags.optimize} {build.flags.common} {build.flags.dep} {build.flags.cpp} {build.flags.cpu} {build.flags.defs} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DF_CPU={build.fcpu} -D{build.usbtype} -DLAYOUT_{build.keylayout} "-I{runtime.platform.path}/cores/{build.core}" "{build.path}/pch/Arduino.h" -o "{build.path}/pch/Arduino.h.gch"
2433

2534
## Compile c++ files
2635
recipe.cpp.o.pattern="{compiler.path}{build.toolchain}{build.command.g++}" -c {build.flags.optimize} {build.flags.common} {build.flags.dep} {build.flags.cpp} {build.flags.cpu} {build.flags.defs} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DF_CPU={build.fcpu} -D{build.usbtype} -DLAYOUT_{build.keylayout} "-I{build.path}/pch" {includes} "{source_file}" -o "{object_file}"
@@ -37,46 +46,74 @@ recipe.ar.pattern="{compiler.path}{build.toolchain}{build.command.ar}" rcs "{arc
3746
## Link
3847
recipe.c.combine.pattern="{compiler.path}{build.toolchain}{build.command.linker}" {build.flags.optimize} {build.flags.ld} {build.flags.ldspecs} {build.flags.cpu} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" {compiler.libraries.ldflags} "-L{build.path}" {build.flags.libs}
3948

40-
## Patch ELF - TODO: not supported by Arduino 1.6.6 builder
41-
recipe.elfpatch.pattern="{compiler.path}/hardware/tools/{build.elfpatch}" -mmcu={build.mcu} "{build.path}/{build.project_name}.elf" "{sketch_path}/disk"
49+
## Patch ELF - TODO: not supported by modern Arduino... :(
50+
recipe.elfpatch.pattern="{teensytools.path}/{build.elfpatch}" -mmcu={build.mcu} "{build.path}/{build.project_name}.elf" "{sketch_path}/disk"
4251

4352
## Create eeprom
4453
recipe.objcopy.eep.pattern="{compiler.path}{build.toolchain}{build.command.objcopy}" {compiler.objcopy.eep.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.eep"
4554

4655
## Create hex
4756
recipe.objcopy.hex.pattern="{compiler.path}{build.toolchain}{build.command.objcopy}" {compiler.elf2hex.flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
4857

58+
## EHEX file - for Teensy 4.x secure mode
59+
recipe.hooks.objcopy.postobjcopy.1.pattern="{teensytools.path}teensy_secure" encrypthex {build.board} "{build.path}/{build.project_name}.hex"
60+
61+
4962
## Post Build - inform Teensy Loader of new file
50-
recipe.hooks.postbuild.1.pattern="{compiler.path}stdout_redirect" "{build.path}/{build.project_name}.lst" "{compiler.path}{build.toolchain}{build.command.objdump}" -d -S -C "{build.path}/{build.project_name}.elf"
51-
recipe.hooks.postbuild.2.pattern="{compiler.path}stdout_redirect" "{build.path}/{build.project_name}.sym" "{compiler.path}{build.toolchain}{build.command.objdump}" -t -C "{build.path}/{build.project_name}.elf"
52-
recipe.hooks.postbuild.3.pattern="{compiler.path}teensy_post_compile" "-file={build.project_name}" "-path={build.path}" "-tools={compiler.path}" "-board={build.board}"
63+
recipe.hooks.postbuild.1.pattern="{teensytools.path}teensy_post_compile" "-file={build.project_name}" "-path={build.path}" "-tools={teensytools.path}" "-board={build.board}"
64+
recipe.hooks.postbuild.2.pattern="{teensytools.path}stdout_redirect" "{build.path}/{build.project_name}.sym" "{compiler.path}{build.toolchain}{build.command.objdump}" -t -C "{build.path}/{build.project_name}.elf"
65+
recipe.hooks.postbuild.3.pattern="{teensytools.path}teensy_size" "{build.path}/{build.project_name}.elf"
66+
#
67+
# objdump to create .lst file is VERY SLOW for huge files
68+
# https://forum.pjrc.com/threads/68121?p=288306&viewfull=1#post288306
69+
#
70+
# recipe.hooks.postbuild.4.pattern="{teensytools.path}stdout_redirect" "{build.path}/{build.project_name}.lst" "{compiler.path}{build.toolchain}{build.command.objdump}" -d -S -C "{build.path}/{build.project_name}.elf"
71+
5372

5473
## Compute size
5574
recipe.size.pattern="{compiler.path}{build.toolchain}{build.command.size}" -A "{build.path}/{build.project_name}.elf"
56-
recipe.size.regex=^(?:\.text|\.text\.progmem|\.text\.itcm|\.data)\s+([0-9]+).*
75+
recipe.size.regex=^(?:\.text|\.text\.progmem|\.text\.itcm|\.data|\.text\.csf)\s+([0-9]+).*
5776
recipe.size.regex.data=^(?:\.usbdescriptortable|\.dmabuffers|\.usbbuffers|\.data|\.bss|\.noinit|\.text\.itcm|\.text\.itcm\.padding)\s+([0-9]+).*
5877
recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
5978

60-
## Teensy Ports Discovery (Arduino 1.8.9 with pathPrefs patch)
61-
discovery.teensy.pattern="{runtime.hardware.path}/../tools/teensy_ports" -J2
79+
## Teensy Ports Discovery
80+
## Arduino 1.8.9 requires pathPrefs patch
81+
## discovery patters have only limited support for substitution macros,
82+
## so we can not use {teensytools.path} or {compiler.path} here
83+
84+
# Teensyduino Installer
85+
#discovery.teensy.pattern="{runtime.hardware.path}/../tools/teensy_ports" -J2
86+
87+
# Arduino Boards Manager
88+
discovery.teensy.pattern="{runtime.tools.teensy-tools.path}/teensy_ports" -J2
89+
pluggable_discovery.required=teensy:teensy-discovery
90+
pluggable_monitor.required.teensy=teensy:teensy-monitor
6291

63-
## Teensy Ports Discovery (Arduino 1.8.9)
64-
#discovery.teensy.pattern="{runtime.ide.path}/hardware/tools/teensy_ports" -J2
6592

6693
## Teensy Loader
67-
tools.teensyloader.cmd.path={runtime.hardware.path}/../tools
94+
95+
# Teensyduino Installer
96+
#tools.teensyloader.cmd.path={runtime.hardware.path}/../tools
97+
98+
# Arduino Boards Manager
99+
tools.teensyloader.cmd.path={runtime.tools.teensy-tools.path}
100+
68101
tools.teensyloader.upload.params.quiet=
69102
tools.teensyloader.upload.params.verbose=-verbose
70103
tools.teensyloader.upload.pattern="{cmd.path}/teensy_post_compile" "-file={build.project_name}" "-path={build.path}" "-tools={cmd.path}" "-board={build.board}" -reboot "-port={serial.port}" "-portlabel={serial.port.label}" "-portprotocol={serial.port.protocol}"
71104

105+
106+
107+
72108
## Export hex
73109
recipe.output.tmp_file={build.project_name}.hex
74110
recipe.output.save_file={build.project_name}.{build.board}.hex
111+
recipe.hooks.savehex.postsavehex.1.pattern="{teensytools.path}teensy_secure" encrypthex {build.board} "{sketch_path}/{build.project_name}.{build.board}.hex"
75112

76113
# TODO: missing patch in 1.6.6...
77114
recipe.output.tmp_file2={build.project_name}.elf
78115
recipe.output.save_file2={build.project_name}.elf
79116

80117

81118
# documentation on this file's format
82-
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification
119+
# https://arduino.github.io/arduino-cli/latest/platform-specification/

0 commit comments

Comments
 (0)