Teensyduino 1.59 Beta #3

Should IntervalTimer.h have two versions of update()?

IntervalTimer.h now has just one version of begin() that uses "template <typename period_t" and handles both integer and float period arguments, but there are still two versions of update(). One takes unsigned int and the other uses the template approach. Is this correct? Can update(unsigned int) be removed?

EDIT: I tested by commenting out the update(unsigned int), and the template version seems to work correctly for both integer and float arguments.

	template <typename period_t>
	bool begin(callback_t funct, period_t period) {
		uint32_t cycles = cyclesFromPeriod(period);
		return cycles >= 17 ? beginCycles(funct, cycles) : false;

	// Change the timer's interval.  The current interval is completed
	// as previously configured, and then the next interval begins with
	// with this new setting.
	void update(unsigned int microseconds) {
		if (microseconds == 0 || microseconds > MAX_PERIOD) return;
		uint32_t cycles = (24000000 / 1000000) * microseconds - 1;
		if (cycles < 17) return;
		if (channel) channel->LDVAL = cycles;

	// Change the timer's interval.  The current interval is completed
	// as previously configured, and then the next interval begins with
	// with this new setting.
	template <typename period_t>
	void update(period_t period){
		uint32_t cycles = cyclesFromPeriod(period);
		if (cycles < 17) return;
		if (channel) channel->LDVAL = cycles;
Did the F() macro get broken for Teensy4 somewhere along the line?
According to https://www.pjrc.com/store/teensy41.html "F()" is meant to be able to place strings in PROGMEM (Flash). But because of this definition in WString.h:
// Brian Cook's "no overhead" Flash String type (message on Dec 14, 2010)
// modified by Mikal Hart for his FlashString library
class __FlashStringHelper;
#ifndef F
#define F(string_literal) ((const __FlashStringHelper *)(string_literal))
... all it does it cast the const string to a different type of pointer, which then gets cast back to char* when printed.

As an alternative the PSTR() macro does properly place strings in PROGMEM, but that isn't mentioned at all on the store page (and seems to be used less commonly in arduino-based libraries).
Although it seems the compiler can still be a bit over-aggressive in those cases - it automatically transforms code such as
printf(PSTR("Hello World\n"));
puts("Hello World");
and somehow the modification of the string to remove the newline makes it end up in the regular data section (DTCM) instead of PROGMEM (Flash.)
Last edited:
Changes since Teensyduino 1.59-beta2:

Fix const init on Wire, SPI, HardwareSerial
The SPI constexpr constructor fix works for T4.1, but the T3.x code section was not fixed. I posted issue #69 on github with a fix in the first comment.

I know T3 is no longer produced, but there are a lot of T3.6 boards out there and a lot of code that passes an SPI instance as a constructor parameter...
After patching SPI.h for T3.x, beta3 is working for me without errors on a moderate-sized project using many commonly used hardware elements. The code (minus the external hardware) also compiles and executes on T4.1.

I should note that to achieve high non-blocking throughput on the T3 (sending to a windows application) I do have to apply the patch to usb_serial.h, usb_serial2.h, and usb_serial3.h as discussed here: https://github.com/PaulStoffregen/cores/issues/10#issuecomment-61514955.

Stuff exercised x 8-hour sessions includes
  • two IMUs (one i2c and one uart)
  • Oximeter (uart)
  • Respiratory activity sensor (ADC)
  • Buttons (ADC)
  • two SD cards (one on the T3.6, one on the Audioadaptor)
  • SerialFlash drive on the audioadaptor
  • Microphone recording via audioadaptor
  • audio out via audioadaptor
  • FFT (not done by the audioadaptor) and spectrogram
  • Multiple preallocated 1 Gb files open and writing on the same SD drive
  • Multiple audio files playing from the serial flash drive
  • continuous writing to 3 usb serial ports, including more than 15 waveform data channels on a single port
  • continuous writing 8 waveforms through spi to an external dac
common libraries exercised:
#include <Adafruit_Sensor.h>
#include <ADC.h>
#include <algorithm>
#include ArduinoJson.hpp
#include "AudioAdaptor.h"
#include <arm_math.h>
#include "Bounce2.h"
#include <BufferedPrint.h>
#include "BufferedPort.h"
#include "Button.h"
#include "cff_Adafruit_BNO055.h" // modified to support debugging calls
#include "cff_Audio.h" // wrapper for audio.h
#include "chip_ads1115_adc.h"
#include "chip_bno08x_rvc.h"
#include "Drives.h" // wrapper for SD and serial flash drives to allow a mostly unified syntax for common functions
#include <FreeStack.h>
#include "i2c_device.h" // wrapper for TwoWire interfaces
#include <inttypes.h>
#include <cff_LTC2636.h>
#include "SD.h"
#include "SdFatConfig.h"
#include "SerialFlash.h"
#include "stdlib.h"
#include <sdios.h>
#include <SPI.h>
#include <sstream>
#include <stdarg.h>
#include <stdio.h>
#include "TeensyID.h"
#include <TimeLib.h>
Last edited: