Teensy debug builds - Teensy fails to start

Hi Guys,

if I have the following code:

#include <Arduino.h>
#include <ILI9341_t3n.h>

#define TFT_RST 8
#define TFT_DC  9
#define TFT_CS 10
#define TFT_MOSI 11
#define TFT_MISO 12
#define TFT_SCK 13
#define TOUCH_CS  6

ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);

void setup() 
{
  pinMode(13, OUTPUT); // LED pin
  digitalWrite(13, 1);

  Serial.begin(115200); 

  Serial.printf("Started\n");
  tft.begin(100'000'000);  

  tft.fillScreen(ILI9341_BLACK);
  tft.fillScreen(ILI9341_YELLOW);
}

void loop() 
{
  Serial.printf("running\n");
  tft.fillScreen(ILI9341_BLACK);
  delay(1000);
  unsigned long start = micros();
  tft.fillScreen(ILI9341_YELLOW);
  Serial.printf("took %lu\n", micros() - start);
  delay(1000);
}

And the following ini file:

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino

build_type = debug

upload_protocol = teensy-cli

monitor_port = /dev/cu.usbmodem79500901
monitor_speed = 115200

lib_deps = kurte/ILI9341_t3n @ 0.0.0-alpha+sha.f1bfb81825

Then when flashed the teensy fails to startup, the led is not lit and the serial ports are not available. It is dead and requires the button to be used to flash it.

If I change the ini file to

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino

build_type = debug
build_unflags = -Og 
build_flags = -O1
debug_build_flags = -O1

upload_protocol = teensy-cli

monitor_port = /dev/cu.usbmodem79500901
monitor_speed = 115200

lib_deps = kurte/ILI9341_t3n @ 0.0.0-alpha+sha.f1bfb81825

Now the teensy starts fine.

Anyone any idea why using -Og would cause the teensy not to startup?

Does this also happen with the simplest posisble blink example, i.e., no TFT libary used?

Hi,

Thanks for the reply.

No it only happens when certain code is linked in (not necessarily the lcd lib), a simple Blinky program works fine.

This is not just with PlatformIO but also with the Arduino IDE, same issue.

The solution is to add at the top of cores\teensy4\startup.c :

#pragma GCC optimize ("O2")

Then all optimisation levels work.

From: PJRC (Teensy) Forum