how can I make TeensyThreads work with Adafruit M4 or even Arduino Due?
Is there perhaps a standard Arduino portation?
no ideas anyone? what is so special that this lib doesn't work with standard Arduino boards?
It isn't written for standard Arduino boards, so it doesn't work with them. The Teensy series uses a completely different microcontroller to any of the Arduino boards. You may as well ask why the library doesn't work with a PIC or a Kinetis.
AFAIK the specific targeted Teensy board works with the ARM Cortex M4, But when I choose the Adafruit M4 with identical MCU (CMIIW) it does not compile though - why is that so?
And why can't it be ported (or how)?
dsyleixa:
AFAIK the specific targeted Teensy board works with the ARM Cortex M4, But when I choose the Adafruit M4 with identical MCU (CMIIW) it does not compile though - why is that so?
The 32bit Teensys (Teensies?) use the MK20DX256VLH7, MK64FX512VMD12 or MK66FX1M0VMD18 microcontollers, made by NXP. They are ARM M4, but they are not the ATSAMD51. They are not the same MCU.
dsyleixa:
And why can't it be ported (or how)?
I imagine it can be ported. I'm not sure of the exact process.
ok, I see, but why are the Teensys so specific? AFAICS the lib uses std::threads, IMO that should be applied by gcc (g++) to either target platform automatically...?
What error do you get when you try to compile for the Adafruit? I don't know where the problem lies but that might point you in the right direction.
source code Blink.ino
#include <Arduino.h>
#include "TeensyThreads.h"
const int LED = 13;
volatile int blinkcode = 0;
void blinkthread() {
while(1) {
if (blinkcode) {
for (int i=0; i<blinkcode; i++) {
digitalWrite(LED, HIGH);
threads.delay(150);
digitalWrite(LED, LOW);
threads.delay(150);
}
blinkcode = 0;
}
threads.yield();
}
}
void setup() {
delay(1000);
pinMode(LED, OUTPUT);
threads.addThread(blinkthread);
}
int count = 0;
void loop() {
count++;
blinkcode = count;
delay(5000);
}
target board: Adafruit Feather M4
the lib GitHub - ftrias/TeensyThreads has been installed correctly to the libraries directory.
tbh, strangely there were 2 extra unzipped enclosed .zip folders inside the downloaded .zip lib, but they had been extracted optionally, manually, additionally, too.
error:
Detecting libraries used...
"D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=120000000L -DARDUINO=10808 -DARDUINO_FEATHER_M4 -DARDUINO_ARCH_SAMD -D__SAMD51J19A__ -DADAFRUIT_FEATHER_M4_EXPRESS -D__SAMD51__ -DUSB_VID=0x239A -DUSB_PID=0x8022 -DUSBCON "-DUSB_MANUFACTURER="Adafruit LLC"" "-DUSB_PRODUCT="Adafruit Feather M4"" -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DENABLE_CACHE "-ID:\arduino\portable\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-ID:\arduino\portable\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\cores\arduino" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\variants\feather_m4" "C:\Users\hw\AppData\Local\Temp\arduino_build_133322\sketch\sketch_mar28a.ino.cpp" -o nul
"D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=120000000L -DARDUINO=10808 -DARDUINO_FEATHER_M4 -DARDUINO_ARCH_SAMD -D__SAMD51J19A__ -DADAFRUIT_FEATHER_M4_EXPRESS -D__SAMD51__ -DUSB_VID=0x239A -DUSB_PID=0x8022 -DUSBCON "-DUSB_MANUFACTURER="Adafruit LLC"" "-DUSB_PRODUCT="Adafruit Feather M4"" -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DENABLE_CACHE "-ID:\arduino\portable\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-ID:\arduino\portable\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\cores\arduino" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\variants\feather_m4" "-ID:\arduino\portable\sketchbook\libraries\TeensyThreads-master" "C:\Users\hw\AppData\Local\Temp\arduino_build_133322\sketch\sketch_mar28a.ino.cpp" -o nul
"D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=120000000L -DARDUINO=10808 -DARDUINO_FEATHER_M4 -DARDUINO_ARCH_SAMD -D__SAMD51J19A__ -DADAFRUIT_FEATHER_M4_EXPRESS -D__SAMD51__ -DUSB_VID=0x239A -DUSB_PID=0x8022 -DUSBCON "-DUSB_MANUFACTURER="Adafruit LLC"" "-DUSB_PRODUCT="Adafruit Feather M4"" -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DENABLE_CACHE "-ID:\arduino\portable\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-ID:\arduino\portable\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\cores\arduino" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\variants\feather_m4" "-ID:\arduino\portable\sketchbook\libraries\TeensyThreads-master" "D:\arduino\portable\sketchbook\libraries\TeensyThreads-master\TeensyThreads-asm.S" -o nul
"D:\arduino\portable\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++" -mcpu=cortex-m4 -mthumb -c -g -Os -w -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -w -x c++ -E -CC -DF_CPU=120000000L -DARDUINO=10808 -DARDUINO_FEATHER_M4 -DARDUINO_ARCH_SAMD -D__SAMD51J19A__ -DADAFRUIT_FEATHER_M4_EXPRESS -D__SAMD51__ -DUSB_VID=0x239A -DUSB_PID=0x8022 -DUSBCON "-DUSB_MANUFACTURER="Adafruit LLC"" "-DUSB_PRODUCT="Adafruit Feather M4"" -D__FPU_PRESENT -DARM_MATH_CM4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DENABLE_CACHE "-ID:\arduino\portable\packages\arduino\tools\CMSIS\4.5.0/CMSIS/Include/" "-ID:\arduino\portable\packages\arduino\tools\CMSIS-Atmel\1.2.0/CMSIS/Device/ATMEL/" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\cores\arduino" "-ID:\arduino\portable\packages\adafruit\hardware\samd\1.2.3\variants\feather_m4" "-ID:\arduino\portable\sketchbook\libraries\TeensyThreads-master" "D:\arduino\portable\sketchbook\libraries\TeensyThreads-master\TeensyThreads.cpp" -o nul
D:\arduino\portable\sketchbook\libraries\TeensyThreads-master\TeensyThreads.cpp:28:27: fatal error: IntervalTimer.h: No such file or directory#include <IntervalTimer.h>
^
compilation terminated.
Bibliothek TeensyThreads-master in Version 1.0 im Ordner: D:\arduino\portable\sketchbook\libraries\TeensyThreads-master wird verwendet
exit status 1
Fehler beim Kompilieren für das Board Adafruit Feather M4 Express (SAMD51).
indeed I can't find
IntervalTimer.h
anywhere inside...
as it turned out, IntervalTimer.h in the Teensy core: cores/IntervalTimer.h at master · PaulStoffregen/cores · GitHub (thanks for the information to the lib's original author)
So IIUC, it's not trivial to port that preemptive multithreading lib to standard Arduinos...
So what would be realy awesome is if there was such a thing available for M0, M3, M4 Arduino/Adafruit cores!
Had you read the readme section of the library, you would have seen this:
Teensy Threading Library implements preemptive threads for the Teensy 3.x platform
There is a preemptive, soft real-time (not deterministic) multitasker for the Arduino DUE:
ard_newbie:
Had you read the readme section of the library, you would have seen this:Teensy Threading Library implements preemptive threads for the Teensy 3.x platform
There is a preemptive, soft real-time (not deterministic) multitasker for the Arduino DUE:
I read this remark
Teensy Threading Library implements preemptive threads for the Teensy 3.x platform
but my original question was about a porting, if you had read it closely
Nonetheless, thanks for your link to GitHub - GO01260/uMT: uMT - a preemptive, soft real-time (not deterministic) multitasker for the ARDUINO AVR and SAM boards, unfortunately the handling is far too complicated. it should be more like std::threads and/or pthread like the Teensy lib.