This is a basic port of FreeRTOS for the Teensy 3.5, Teensy 3.6, Teensy 4.0 and Teensy 4.1 boards.
To make FreeRTOS work on the teensy boards I had to adjust the EventResponder
class of the Teensy Arduino core library and optimized some minor parts. Therefore a custom platform setting is used (platform = https://github.com/tsandmann/platform-teensy
). It uses a more recent compiler toolchain (e.g. to support C++20) and a slightly modified Arduino core library. The latter is needed because FreeRTOS needs some interrupt vectors that are also used by the Arduino core (SysTick
and PendSV
for EventResponder
) to be set up for the RTOS. The modified core library supports these services by running them ontop of the RTOS.
Consider this as experimental code and work in progress. If it breaks, you get to keep both pieces.
malloc
or free
are thread-safe due to provided guards for newlib.git clone https://github.com/tsandmann/freertos-teensy
freertos-teensy/example/blink
teensy41
Build
button on the PlatformIO toolbar or shortcut (ctrl/cmd+alt+b
)Upload
button on the PlatformIO toolbar or shortcut (ctrl/cmd+alt+t
) and select "PlatformIO: Upload"Serial port setup
settings and set Serial Device
to your serial device (typically sth. like /dev/cu.usbmodemXXXXXXX
or /dev/tty.usbmodemXXXXXXX
)There is a test version available which can be used with Teensyduino. If you want to try it out:
blink.ino
.Currently there are the following limitations for Teensyduino projects:
std::thread
, std::jthread
or Futures (custom compiler options for the library would be necessary which is currently not possible with arduino's IDE).EventResponder
class, the EventResponder::attachInterrupt()
variant must not be used, otherwise FreeRTOS will stop working. An update of the Teenys core library is required to make this work (this Pull request needs to be merged for this).void HardFault_HandlerC(unsigned int* hardfault_args)
and _Unwind_Reason_Code trace_fcn(_Unwind_Context* ctx, void* depth)
) in case of a crash or an exception, the code must be compiled by using the -fasynchronous-unwind-tables
option to tell gcc to generate the needed unwind tables. Furthermore, an updated linker script is needed to put .ARM.exidx
and .ARM.extab
in the right place and some (startup) code to copy these tables into RAM. (libgcc's unwind code requires the unwind table at an address reachable by a 31-bit signed offset (+/- 0x3FFFFFFF) from executed instructions). To support call traces over C-library calls, newlib has to be compiled with -fasynchronous-unwind-tables
option as well.TBD