Seeking help - is there a reasonable way I can "clone" older Teensy 4.0 firmware to a pair of new chips?

tew468

Member
I built a one-off assembly Teensy 4.0-powered assembly back in 2021 as part of a proof-of-concept project to track flying birds near wind turbines. It used a Teensy 4.0 with Ublox M8 GPS module to generate precisely-timed video camera sync pulses, and USB messages with the corresponding timestamps to the millisecond were sent to a linux host computer that captured and assembled the video frames from multiple synchronized cameras. This was created on Arduino 1.<something> and TeensyDuino 1.53(I think), and has been running well ever since. The Tennsy 4 / TeensyDuino environment enabled some good science that otherwise would have been too difficult to achieve in the budget available.

Now, my colleague has been asked to field two more systems, but I am working in a different city on the other side of the state. A co-worker has duplicated my original Teensy circuit and sensor configuration, but when he tries to compile and burn the Teensy 4.0 code on his Windows machine using the modern Arduino 2.3.2 and TeensyDuino 1.59, it appears to compile and install, but there seems to be a race condition now exposed preventing the system from starting up. (At least, this is as best as I can tell from teensy_serialmon output over an SSH connection to the new system on the other side of the state). On a hunch, the coworker pulled the old Teensy 4.0 from the board from several years ago and plonked it onto the new board, and everything starts up and runs fine.

My question for the Teensy gurus of the board: Is there a (relatively) simple method by which I can "bitwise clone" the existing Teensy 4.0 firmware and then "re-burn" it to two new blank Teensy 4.0 parts? If there is such a method and I can practice it locally, I'm hopeful I could then talk my colleague through the process remotely so that he can field the other two systems.

I know this isn't the "right" way to address a logic race condition. The underlying code should be refactored/reworked to identify and remove the race condition, as well as modernized to take advantage of / play nicely with the updated software environment, etc. But the original development system was declared obsolete and excessed, I am several hundred miles away from where the system is being set up, and I know that a Teensy 4.0 with the old firmware will make the systems run.

Before I burn two weeks "vacation time" trying to recreate the lab environment needed to try to recreate the wheel, I have to ask: is there a reasonably understandable method for cloning from one (non-locked / non-encrypted) Teensy 4.0 to another that does not require physically removing a chip from the Teensy 4 board? If so, what tools are necessary to achieve it (e.g. JTAG reader vs mBed SWD device vs USB code vs ?)?

Based on the answer to a similar question on Teensy 4.1 at https://forum.pjrc.com/index.php?threads/teensy-4-1-copy-code-from-a-programmed-board.72865/ I'm guessing the answer is going to be "no", but I really have to ask before starting down that rabbit hole.

Any pointers to relevant resources, documents, other people's hackeries are welcome.

Thank you,
-Tom
 
No, there isn't any easy way to do this. There are very difficult ways, unless it's Lockable Teensy running in secure mode. But even with Lockable Teensy, you could program your key into the fuses and then desolder the flash chip and use special hardware to extract the encrypted code. If you program another flash chip with encrypted code, it should run as long as you've written your key into the RT1062's fuses.

Since you do have the original code, your path of least resistance is probably to try old versions of Teensyduino. In Arduino IDE 2.3.2, you can use Boards Manager to revert to older versions. Just click the version number drop-down menu. Maybe one of those will "just work" and you'll be done with just a few mouse clicks and uploads to see if those versions work.

You might try version 1.57 first. It was the last before we updated to a new gcc toolchain.

But if you need to go back farther (before Arduino IDE 2.x.x existed), you'll need Arduino IDE 1.8.19. You can get Arduino IDE 1.8.19 from Arduino's website. For old versions of Teensyduino installers, so to the download page and scroll down to the stuff for Arduino 1.8.x. Right click and copy the link. Then go to your browsers address bar and paste. But don't press Enter yet. Look for the 3 digit number in the URL and edit it to older version you want. Then pretty Enter to download that file. Run the Arduino IDE installer, then the Teensyduino installer. Hopefully you'll find the version which worked previously.
 
Last edited:
No, there isn't any easy way to do this. There are very difficult ways, unless it's Lockable Teensy running in secure mode. But even with Lockable Teensy, you could program your key into the fuses and then desolder the flash chip and use special hardware to extract the encrypted code. If you program another flash chip with encrypted code, it should run as long as you've written your key into the RT1062's fuses.

Since you do have the original code, your path of least resistance is probably to try old versions of Teensyduino. In Arduino IDE 2.3.2, you can use Boards Manager to revert to older versions. Just click the version number drop-down menu. Maybe one of those will "just work" and you'll be done with just a few mouse clicks and uploads to see if those versions work.

You might try version 1.57 first. It was the last before we updated to a new gcc toolchain.

But if you need to go back farther (before Arduino IDE 2.x.x existed), you'll need Arduino IDE 1.8.19. You can get Arduino IDE 1.8.19 from Arduino's website. For old versions of Teensyduino installers, so to the download page and scroll down to the stuff for Arduino 1.8.x. Right click and copy the link. Then go to your browsers address bar and paste. But don't pretty Enter yet. Look for the 3 digit number in the URL and edit it to older version you want. Then pretty Enter to download that file. Run the Arduino IDE installer, then the Teensyduino installer. Hopefully you'll find the version which worked previously.
Hi Paul,
Thank you for the rapid and detailed reply (in addition to all the work you've put into the TeensyDuino environment).
While nothing is locked or secured on the old Teensy 4.0 project, you've given me a good idea that will be fairly easy to try.

(I'm frankly surprised at myself for not thinking of just manually load the older version combination of Arduino IDE / Teensyduino to just recreate my old build environment. I guess I've become too reflexive about just automatically installing all software updates when prompted...)

I think your suggestion has a good chance of solving my immediate issue while then buying me time to develop a better long-term fix.
Thanks also for the note about the compiler change after 1.57, and for keeping the prior TeensyDuino versions easily available (which will make this recovery attempt possible).

-Tom
 
You don’t by any chance have the compiled hex file from the previous build, do you?

One good habit to get into is, when releasing any sort of software, save the compiled hex and elf files, etc. (i.e. all the artifacts.)
 
You don’t by any chance have the compiled hex file from the previous build, do you?

One good habit to get into is, when releasing any sort of software, save the compiled hex and elf files, etc. (i.e. all the artifacts.)
Alas, I don't have the original artifacts any more. I had actually preserved the whole development computer (files and everything) until just last year; it was a 2013 iMac that was required to be retired last year after Apple's MacOS releases stopped supporting it. There was limited time to migrate stuff off the hardware before it had to be pulled, and I didn't think at the time to save all the artifacts since I had the source in version control and I assumed that that would be sufficient on the off chance there was renewed interest in a several-year-old-project...

42+ years of computing "oops"es, and yet I am still not sufficiently paranoid regarding my backup strategy...

I'll keep your advice for future iterations.

-Tom
 
Back
Top