Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 4.0 Serial downloader (ESP32)

  1. #1
    Junior Member
    Join Date
    Sep 2019

    Teensy 4.0 Serial downloader (ESP32)

    Hello there,

    I would like to program the Teensy 4.0 over-the-air using an ESP32. Whereby the ESP32 programs the Teensy 4.0 over UART.

    Read other topics on this with previous versions of Teensy boards but wasn't able to rule out whether it is possible to do it on the Teensy 4.0.
    Therefore my take on this by reading the reference manual of the RT1060.
    What is the best way to go about this if it's even possible?

    1. Serial downloader mode
    The RT1060's Reference Manual states a "Serial downloader" feature at page 265.

    First off the chip must boot into serial downloader mode by setting the BOOT_MODE[1:0] pins to 01.
    These pins GPIO_AD_B0_04/BOOT_MODE0 and GPIO_AD_B0_05/BOOT_MODE1 are connected to PTA4 of the MKL02Z32VFG4 chip and GND respectively. Therefore it would already be impossible to get a 01 value on these pins. So this doesn't work.

    Another way to go into serial downloader mode is by booting from the fuses with BT_FUSE_SEL = 0
    "If BT_FUSE_SEL = 0, indicating that the boot device (for example, flash, SD/ MMC) was not programmed yet, the boot flow jumps directly to the Serial Downloader."
    How do I boot from the fuses and make sure BT_FUSE_SEL = 0?

    I suppose the MKL02Z32VFG4 is responsible for booting the RT1060 from choosing between boot from fuses and internal boot using the BOOT_MODE0 pin.
    I suppose BT_FUSE_SEL must already be zero otherwise the USB upload wouldn't work.
    Does activating the Program pin boot from the internal fuses?

    After entering the serial downloader mode I should be able to use the Serial Download Protocol commands from the reference manual on the following pins:
    Pin 24 / AD_B0_12 / TX
    Pin 25 / AD_B0_13 / RX

    I'll figure the rest out later since I don't know whether it's feasible yet.

    2. ESP32-S2 USB upload
    An alternative would be using the new ESP32-S2 with USB feature to upload using USB.

    3. Write to flash from already running code
    Another alternative is to only replace a part of the code using code already running on the board uploaded using USB once.
    If this is thé way, how do I go about this? Are there examples somewhere?
    Last edited by seymar; 09-15-2019 at 03:58 PM.

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    Up to now, there isn’t a real and universal solution for OTA updates for any Teensy, be it 3.x or 4.x.

    This is related to the idea that it’s the MKL chip in conjunction with the main CPU which allows easy programming over USB in the well known and approved Arduino way and which thus makes very powerful CPUs accessible to non-professionals through the Arduino IDE. Paul Stoffregen made (and makes still) a great work by keeping almost everything Open Source, the Teensyduino Core files and the hardware schematics, but not the “magic sauce” in the MKL firmware which transforms an XYZ CPU into an easy to handle and easy to program Teensy, which is his business model.

    If you do not want to go the PJRC/Teensy way, you are always free to design your own iMX RT board and to write your own boot-loader code, but you should not expect any support from PJRC because you are about to work around their source of revenue.

    My own (I’m in no way related to PJRC and I can’t speak for them) thoughts about OTA updates in general are as follows:

    While the idea might sound appealing at a first glance (let’s do it because it’s a challenge), I can not see a true need for that in most real world use cases: If my software is well thought and anticipates future needs, well designed, and thoroughly tested, updates should not happen very often over the lifespan of an electronic product, bugs should be eliminated before sales start. And when the rare case happens that an update was necessary, connecting a USB cable to the Teensy or to a brought out USB port should not be a big affair. Out of that, OTA updates have always the danger of someone injecting malware included, or in case of transmission channel problems, bricking your device.

    At my day job, maintenance of network routers and switches is part of my daily bread. Thus, I’m used to downloading (security) updates to my notebook, go to the server room, connect my notebook via an USB to RS-232 adapter cable to the routers one after the other, and install the firmware updates one device at a time. So, where is the problem?

  3. #3
    There are scenarios where OTA updates are necessary. There is a working method on this forum for update via UART for Teensy 3.2, and maybe 3.5 and 3.6, too. The main limitation is that the new program must be temporarily stored in the same flash as contains the existing program, so programs can only be half the size of the flash. See these two related threads.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts