Teensy 3.6 FreeRTOS Template Save

Teensy 3.6 template project with FreeRTOS 9.0.0

Project README

Teensy 3.6 FreeRTOS Project Template


Starting point for a Teensy 3.x RTOS project based on Teensyduino 1.32 and FreeRTOS 9.0.0 to be used without the Arduino IDE and build environment.


Install the Teensy udev rule: sudo cp tools/49-teensy.rules /etc/udev/rules.d/

Then unplug your Teensy and plug it back in.


  1. Put your code in src/main.cpp
  2. Put any libraries you need in libraries
  3. Set the TEENSY variable in Makefile according to your teensy version
  4. Build your code make
  5. Upload your code make upload

Make Targets

  • make alias for make hex
  • make build compiles everything and produces a .elf
  • make hex converts the elf to an intel hex file
  • make post_compile opens the launcher with the correct file
  • make upload uploads the hex file to a teensy board
  • make reboot reboots the teensy

Where everything came from

Modifications to Makefile include

  • Add support for FreeRTOS

Modifications to teensy3/FreeRTOSConfig.h include

  • Disable configCREATE_LOW_POWER_DEMO: to keep delay() and micros() functions in arduino files operational
  • Keep configTICK_RATE_HZ at 1000: anything else than 1000 Hz causes timing trouble in arduino files
  • Disabled several handlers not required for this initial port

Modifications to teensy3/mk20dx128.c include


#include "FreeRTOS.h"
#include "task.h"

add FreeRTOS handler prototypes and replace SysTickHandler

// from FreeRTOS port
void xPortPendSVHandler( void ) __attribute__ (( naked ));
void xPortSysTickHandler( void );
void vPortSVCHandler( void ) __attribute__ (( naked ));

// from Arduino port
extern volatile uint32_t systick_millis_count;

__attribute__ (( weak, naked )) void systick_isr(void) {
// increment the systick counter
systick_millis_count += 1000/configTICK_RATE_HZ;

// unconditionally branch to the systick handler
__asm volatile (
	"B	xPortSysTickHandler"

comment out isr's that will be replaced by FreeRTOS routines

void usage_fault_isr(void)	__attribute__ ((weak, alias("fault_isr")));
//void svcall_isr(void)		__attribute__ ((weak, alias("unused_isr")));
void debugmonitor_isr(void)	__attribute__ ((weak, alias("unused_isr")));
//void pendablesrvreq_isr(void)	__attribute__ ((weak, alias("unused_isr")));
//void systick_isr(void)		__attribute__ ((weak, alias("systick_default_isr")));

add FreeRTOS isr's

fault_isr,					// 10 --
vPortSVCHandler,				// 11 ARM: Supervisor call (SVCall)
debugmonitor_isr,				// 12 ARM: Debug Monitor
fault_isr,					// 13 --
xPortPendSVHandler,				// 14 ARM: Pendable req serv(PendableSrvReq)
systick_isr,					// 15 ARM: System tick timer (SysTick)

comment out SysTick counter initialization

// initialize the SysTick counter
// next 4 lines are commented out for FreeRTOS port, FreeRTOS configures SysTick
//	SYST_RVR = (F_CPU / 1000) - 1;
//	SYST_CVR = 0;
//	SCB_SHPR3 = 0x20200000;  // Systick = priority 32

Modifications to teensy3/mk66fx1m0.ld include

added heap memory section (add this to other .ld files when porting to other Teensy 3.x boards)

.heap (NOLOAD) : {
	. = ALIGN(4);
} > RAM

Modifications to teensy3/pins-teensy.c include

added delay_NoSysTick function that can safely be called before the SysTick counter is configured

Sources that were very helpful for this Teensy FreeRTOS port

Thank you all for posting your experiences!


This FreeRTOS port has only been tested on a Teensy 3.6 board with no real world application yet. If you find issues please post them or create a pull request.

Open Source Agenda is not affiliated with "Teensy 3.6 FreeRTOS Template" Project. README Source: vanbergeijk/teensy-3.6-FreeRTOS-template
Open Issues
Last Commit
1 year ago

Open Source Agenda Badge

Open Source Agenda Rating