summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAdrian Kummerlaender2021-10-09 23:41:40 +0200
committerAdrian Kummerlaender2021-10-09 23:41:40 +0200
commitb006b3c355616c89d66084880b5a5a87f0241009 (patch)
treec4a35025ff183154d8ef3d6c63535b82d605c25d /test
downloadteensy-env-b006b3c355616c89d66084880b5a5a87f0241009.tar
teensy-env-b006b3c355616c89d66084880b5a5a87f0241009.tar.gz
teensy-env-b006b3c355616c89d66084880b5a5a87f0241009.tar.bz2
teensy-env-b006b3c355616c89d66084880b5a5a87f0241009.tar.lz
teensy-env-b006b3c355616c89d66084880b5a5a87f0241009.tar.xz
teensy-env-b006b3c355616c89d66084880b5a5a87f0241009.tar.zst
teensy-env-b006b3c355616c89d66084880b5a5a87f0241009.zip
Basic build environment for Teensy 4.0 programs
Diffstat (limited to 'test')
-rw-r--r--test/Makefile26
-rw-r--r--test/blink.cpp13
-rw-r--r--test/counter.cpp19
3 files changed, 58 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..0891b70
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,26 @@
+MCU = IMXRT1062
+MCU_DEF = ARDUINO_TEENSY40
+
+OPTIONS = -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH
+OPTIONS += -D__$(MCU)__ -DARDUINO=10813 -DTEENSYDUINO=154 -D$(MCU_DEF)
+
+CPU_OPTIONS = -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb
+
+CPPFLAGS = $(NIX_CFLAGS_COMPILE) -Wall -g -O2 $(CPU_OPTIONS) -MMD $(OPTIONS) -I. -ffunction-sections -fdata-sections
+CXXFLAGS = -std=gnu++20 -felide-constructors -fno-exceptions -fpermissive -fno-rtti -Wno-error=narrowing
+
+LDFLAGS += -Os -Wl,--gc-sections,--relax $(CPU_OPTIONS)
+
+LIBS = -lm -lstdc++ -lteensy-core
+
+CPP_FILES := $(wildcard *.cpp)
+TARGETS := $(CPP_FILES:.cpp=.hex)
+
+%.elf: %.o
+ $(CC) $(LDFLAGS) -o $@ $< $(LIBS)
+
+%.hex: %.elf
+ $(SIZE) $<
+ $(OBJCOPY) -O ihex -R .eeprom $< $@
+
+all: $(TARGETS)
diff --git a/test/blink.cpp b/test/blink.cpp
new file mode 100644
index 0000000..ec7b3bd
--- /dev/null
+++ b/test/blink.cpp
@@ -0,0 +1,13 @@
+#include <Arduino.h>
+
+extern "C" int main(void) {
+ pinMode(13, OUTPUT);
+
+ while (true) {
+ digitalWrite(13, HIGH);
+ delay(500);
+ digitalWrite(13, LOW);
+ delay(500);
+ }
+}
+
diff --git a/test/counter.cpp b/test/counter.cpp
new file mode 100644
index 0000000..680e233
--- /dev/null
+++ b/test/counter.cpp
@@ -0,0 +1,19 @@
+#include <Arduino.h>
+
+extern "C" int main(void) {
+ for (unsigned iPin=16; iPin <= 20; ++iPin) {
+ pinMode(iPin, OUTPUT);
+ }
+
+ std::size_t i = 0;
+
+ while (true) {
+ digitalWrite(16, (i % 2) > 0);
+ digitalWrite(17, (i % 4) > 1);
+ digitalWrite(18, (i % 8) > 3);
+ digitalWrite(19, (i % 16) > 7);
+ digitalWrite(20, (i % 32) > 15);
+ delay(analogRead(7));
+ i++;
+ }
+}