🛠 Premiers pas sur le Teensy 4.0 : Teensyduino, Loader et premier Blink
Objectives
Get to know the fastest board in its class: the Teensy 4.0 features an NXP MIMXRT1062DVL6 (Cortex-M7 at 600 MHz, officially overclockable to 912 MHz) in the compact 1.4 × 0.7 inch form factor of the Teensy 3.x series. This first tutorial lays the foundations: installing the Teensyduino environment, uploading a Blink sketch, understanding the Teensy Loader + Program button ecosystem (the board has NO hardware reset!), and measuring actual pin speed using the cycle counter.
Hardware
- 1 Teensy 4.0 (manufactured by SparkFun since March 2025, sold with or without soldered headers) + micro-USB data cable
- PC (Windows / Mac / Linux) with Arduino IDE
- No wiring required: the orange LED on pin 13 is sufficient
Installation and Uploading
- Install the Teensy add-on via https://www.pjrc.com/teensy/td_download.html (official alternatives: PlatformIO, Visual Micro, and the command-line Makefile provided with Teensyduino).
- In the IDE: Tools > Board > Teensy > Teensy 4.0, then Tools > USB Type > Serial (the list is long: MIDI, Keyboard, Mouse, Audio, MTP, RawHID…).
- Click Upload: Teensy Loader launches automatically. If it does not detect the board, press the Program button on the board — this is NOT a reset button; it requests USB programming mode.
- The red LED indicates the bootloader status: dim = waiting, bright = flash writing in progress.
Key architectural point: the bootloader resides in a physically separate chip (a GD32E230F8 on boards after June 2022). The main flash is 100% yours, and uploading cannot destroy it. However, there is no hardware reset pin: you can only reset via software watchdog or via the SCB_AIRCR register.
Complete Code
// Blink + mesure réelle de la vitesse GPIO via le compteur de cycles
// 32 bits ARM_DWT_CYCCNT, incrémenté à la fréquence CPU (600 MHz).
void setup {
Serial.begin(9600); // série USB : le baud est ignoré
pinMode(13, OUTPUT); // LED orange (JAMAIS en INPUT_PULLUP :
// la LED polarise la broche)
}
void loop {
uint32_t start = ARM_DWT_CYCCNT; // instantané du compteur
for (int i = 0; i < 100000; i++) {
digitalToggle(13); // écriture broche la plus rapide
}
uint32_t cycles = ARM_DWT_CYCCNT - start;
Serial.printf("moyenne %u cycles par bascule\n", cycles / 100000);
delay(1000);
}
Expected Verification
The orange LED blinks (visually almost off: the loop toggles the pin millions of times per second; digitalToggle compiles to a single bit write). The Serial Monitor displays the number of cycles per toggle — at 600 MHz, around ten cycles correspond to a signal of several tens of MHz on the pin. This is an immediate demonstration of the power of the dual-issue M7 with branch prediction and TCM memory.
Common Errors
- Using a charge-only micro-USB cable: the Serial Monitor and Loader see nothing — test with another cable.
- Looking for a reset button: there isn't one. To restart the program, unplug/replug the USB, or press Program to reprogram.
- Forgetting to select USB Type: by default, Serial works, but if you upload a MIDI or Keyboard sketch without changing the type, nothing appears on the PC side.
- Using pin 13 as an input with INPUT_PULLUP: the LED on the pin distorts the reading — the PJRC store page explicitly notes this.
- Thinking the board is dead if Teensy Loader remains "waiting": press Program once; the red LED should light up dimly.
- Watch the power supply: the board is powered by 5 V on VUSB/VIN; never power it via the 3.3 V pin (output only, onboard regulator, 250 mA max external).
Other tutorials for this board
- GPIO et PWM sous 3,3 V : les règles d'or du Teensy 4.0
- Entrées analogiques et capteur de température interne : le ADC et ses limites
- Piloter un ruban WS2812 sans bloquer le CPU : WS2812Serial et OctoWS2811
- Contrôleur MIDI USB : un potard qui joue du piano (MIDIx4/MIDIx16)
- Comprendre la mémoire : 2 Mo de flash, 1 Mo de RAM TCM/DMA, EEPROM émulée et LittleFS
- Deux ports USB simultanés : périphérique 480 Mbit/s ET hôte USB sur les pastilles
Code examples for this board
clignotante.inoArduinotouche-capacitive.inoArduinoanalogique-12-bits.inoArduinomidi-piano.inoArduinopwm-respiration.inoArduinoservo-angle.inoArduino