Skip to content

Commit d503357

Browse files
committed
Added support for Teensy
1 parent 206dee7 commit d503357

File tree

7 files changed

+91
-12
lines changed

7 files changed

+91
-12
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# http://www.pjrc.com/teensy/teensyduino.html
2+
name=Teensyduino
3+
version=1.8.5
4+
rewriting=disabled
5+
6+
compiler.path={runtime.hardware.path}/../tools/
7+
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
8+
compiler.elf2hex.flags=-O ihex -R .eeprom
9+
compiler.libraries.ldflags=
10+
11+
## Preprocessor Includes
12+
recipe.preproc.includes="{compiler.path}{build.toolchain}{build.command.g++}" -M -MG -MP -x c++ -w {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} {includes} "{source_file}"
13+
14+
## Preprocessor Macros
15+
recipe.preproc.macros="{compiler.path}{build.toolchain}{build.command.g++}" -E -CC -x c++ -w {compiler.cpp.flags} {build.flags.common} {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} {includes} "{source_file}" -o "{preprocessed_file_path}"
16+
17+
## New Preprocessor for Arduino 1.9
18+
tools.arduino-preprocessor.path={runtime.tools.arduino-preprocessor.path}
19+
tools.arduino-preprocessor.cmd.path={path}/arduino-preprocessor
20+
tools.arduino-preprocessor.pattern="{cmd.path}" "{source_file}" "{codecomplete}" -- -std=gnu++14
21+
22+
## 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"
24+
25+
## Compile c++ files
26+
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}"
27+
28+
## Compile c files
29+
recipe.c.o.pattern="{compiler.path}{build.toolchain}{build.command.gcc}" -c {build.flags.optimize} {build.flags.common} {build.flags.dep} {build.flags.c} {build.flags.cpu} {build.flags.defs} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DF_CPU={build.fcpu} -D{build.usbtype} -DLAYOUT_{build.keylayout} {includes} "{source_file}" -o "{object_file}"
30+
31+
## Compile S files
32+
recipe.S.o.pattern="{compiler.path}{build.toolchain}{build.command.gcc}" -c {build.flags.optimize} {build.flags.common} {build.flags.dep} {build.flags.S} {build.flags.cpu} {build.flags.defs} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DF_CPU={build.fcpu} -D{build.usbtype} -DLAYOUT_{build.keylayout} {includes} "{source_file}" -o "{object_file}"
33+
34+
## Create archives
35+
recipe.ar.pattern="{compiler.path}{build.toolchain}{build.command.ar}" rcs "{archive_file_path}" "{object_file}"
36+
37+
## Link
38+
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}
39+
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"
42+
43+
## Create eeprom
44+
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"
45+
46+
## Create hex
47+
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"
48+
49+
## 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}"
53+
54+
## Compute size
55+
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]+).*
57+
recipe.size.regex.data=^(?:\.usbdescriptortable|\.dmabuffers|\.usbbuffers|\.data|\.bss|\.noinit|\.text\.itcm|\.text\.itcm\.padding)\s+([0-9]+).*
58+
recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
59+
60+
## Teensy Ports Discovery (Arduino 1.8.9 with pathPrefs patch)
61+
discovery.teensy.pattern="{runtime.hardware.path}/../tools/teensy_ports" -J2
62+
63+
## Teensy Ports Discovery (Arduino 1.8.9)
64+
#discovery.teensy.pattern="{runtime.ide.path}/hardware/tools/teensy_ports" -J2
65+
66+
## Teensy Loader
67+
tools.teensyloader.cmd.path={runtime.hardware.path}/../tools
68+
tools.teensyloader.upload.params.quiet=
69+
tools.teensyloader.upload.params.verbose=-verbose
70+
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}"
71+
72+
## Export hex
73+
recipe.output.tmp_file={build.project_name}.hex
74+
recipe.output.save_file={build.project_name}.{build.board}.hex
75+
76+
# TODO: missing patch in 1.6.6...
77+
recipe.output.tmp_file2={build.project_name}.elf
78+
recipe.output.save_file2={build.project_name}.elf
79+
80+
81+
# documentation on this file's format
82+
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification

extras/library_generation/teensy32_toolchain.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++)
88
SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
99
SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
1010

11-
set(FLAGS "-O2 -fsingle-precision-constant -ffunction-sections -fdata-sections -fno-exceptions -mcpu=cortex-m4 -nostdlib -mthumb" CACHE STRING "" FORCE)
11+
set(FLAGS "-O2 -fsingle-precision-constant -ffunction-sections -fdata-sections -fno-exceptions -mcpu=cortex-m4 -nostdlib -mthumb -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE)
1212

1313
set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)
1414
set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)

extras/library_generation/teensy4_toolchain.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(CMAKE_CXX_COMPILER $ENV{TOOLCHAIN_PREFIX}g++)
88
SET(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
99
SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
1010

11-
set(FLAGS "-O2 -mfloat-abi=hard -mfpu=fpv5-d16 -ffunction-sections -fdata-sections -fno-exceptions -nostdlib -mcpu=cortex-m7 -mthumb" CACHE STRING "" FORCE)
11+
set(FLAGS "-O2 -mfloat-abi=hard -mfpu=fpv5-d16 -ffunction-sections -fdata-sections -fno-exceptions -nostdlib -mcpu=cortex-m7 -mthumb -D'RCUTILS_LOG_MIN_SEVERITY=RCUTILS_LOG_MIN_SEVERITY_NONE'" CACHE STRING "" FORCE)
1212

1313
set(CMAKE_C_FLAGS_INIT "-std=c11 ${FLAGS} -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)
1414
set(CMAKE_CXX_FLAGS_INIT "-std=c++14 ${FLAGS} -fno-rtti -DCLOCK_MONOTONIC=0 -D'__attribute__(x)='" CACHE STRING "" FORCE)

src/arduino_transports.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdio.h>
22
#include <stdbool.h>
33

4-
#if defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY32)
4+
#if defined(ARDUINO_TEENSY41) || defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY32)
55
#include "teensy_transports.c.in"
66
#elif defined(ARDUINO_ARCH_OPENCR)
77
#include "opencr_transports.c.in"
-81.2 KB
Binary file not shown.

src/mk20dx256/libmicroros.a

-81.8 KB
Binary file not shown.

src/teensy_transports.c.in

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
#include <stdbool.h>
44
#include <sys/time.h>
55

6-
extern volatile uint32_t systick_millis_count;
7-
86
int clock_gettime(clockid_t unused, struct timespec *tp)
97
{
108
(void) unused;
11-
uint64_t m = systick_millis_count * 1000;
9+
uint64_t m = micros();
1210
tp->tv_sec = m / 1000000;
1311
tp->tv_nsec = (m % 1000000) * 1000;
1412
return 0;
@@ -34,21 +32,20 @@ size_t arduino_serial_platform_write(uint8_t* buf, size_t len, uint8_t* errcode)
3432
// Place here your writing bytes platform code
3533
// Return number of bytes written
3634
(void) errcode;
37-
usb_serial_write(buf, len);
38-
usb_serial_flush_output();
39-
return len;
35+
size_t sent = usb_serial_write(buf, len);
36+
return sent;
4037
}
4138

4239
size_t arduino_serial_platform_read(uint8_t* buf, size_t len, int timeout, uint8_t* errcode)
4340
{
4441
// Place here your reading bytes platform code
4542
// Return number of bytes read (max bytes: len)
4643
(void) errcode;
47-
uint32_t start_time = systick_millis_count;
44+
uint32_t start_time = micros() * 1000;
4845
size_t readed = 0;
4946

50-
while((systick_millis_count - start_time) < (uint32_t) timeout){
51-
while(usb_serial_available()){
47+
while((readed < len) && ((micros() * 1000) - start_time) < (uint32_t) timeout){
48+
if(usb_serial_available()){
5249
buf[readed++] = usb_serial_getchar();
5350
}
5451
}

0 commit comments

Comments
 (0)