Teensy Loader in Javascript

coelacant1

New member
Hello everyone,

Just wanted to share here. I made a version of the Teensy Loader built in Javascript for project maintainers to be able to host their firmware and have users update through the browser.

I have a Github page here with an action for deploying a test page: https://github.com/coelacant1/Teensy-Loader-Javascript
You can view the test page here: https://coelacant1.github.io/Teensy-Loader-Javascript/Teensy-Loader-Example.html

I tried to port the main functionality from the CLI over. I only have Teensy 4.0s and 4.1s to test, so no guarantees on older versions.
  • Local Firmware Loading:
    • Reads .hex (Intel HEX) or .bin files from the user’s computer via a <input type="file">, converting them into 1KB blocks.
  • Intel HEX Parsing:
    • Processes .hex lines, checks checksums, and maps them into memory blocks (accounting for offset addresses).
  • WebHID Flashing:
    • Communicates with Teensy boards via the WebHID API to send firmware blocks.
    • Skips blocks that are all 0xFF except the first, to reduce unnecessary writes.
    • Sends “magic bytes” at the end to finalize the flashing.
  • Serial Communication:
    • Opens a browser Serial Port.
    • Reads lines of text, delivering them to a callback for logging or display.
    • Closes the port.

Here is a screencap of the example webpage:
Screenshot 2024-12-28 135531.png


I built this as a means for users to be able to upload my firmware builds from my Github deployment for ProtoTracer (3D rendering engine on Teensy's): https://coelacant.com/ProtoTracer/FirmwareUpload.html
 
This is very cool!

I played with this concept a few months ago - less about flashing the Teensy and more about just having the ability to find the Teensy and sending/receiving data via web browser APIs
 
This is really cool and super useful, I hope can support .ehex files in the future!
FlasherX supports EHEX, that's been tested by me and the author of FlasherX @joepasquariello. Lucky for us all the second part of EHEX is ignored which is fine, FlasherX stops after the first EOF. All nice and dandy!

FlasherX is very usable for end-user applications. And it's sort of "fool proof" as Teensy flashes itself, no "dumb user" can jank the cable mid-flash and make their device into a brick.

With that said this tool is great and definately have a place in the community I would say.
 
FlasherX supports EHEX, that's been tested by me and the author of FlasherX @joepasquariello. Lucky for us all the second part of EHEX is ignored which is fine, FlasherX stops after the first EOF. All nice and dandy!

FlasherX is very usable for end-user applications. And it's sort of "fool proof" as Teensy flashes itself, no "dumb user" can jank the cable mid-flash and make their device into a brick.

With that said this tool is great and definately have a place in the community I would say.
I'll take a look at FlasherX
 
Just an update and some notes: https://github.com/coelacant1/Teens...mmit/5b643a1c75802bc6b1246af6e1f549323ca35fe7

Even if power is pulled mid-flash or if the second part of the EHEX is missing, it “soft bricks” the Teensy. A 15 second press of the button will reset it back to the default blink - note that if you have yours locked, blink won't run but you can still get into bootloader mode.

The new version now parses the second EHEX segment (loader utility). It mimics how Teensy Loader handles encrypted firmware for Teensy 4.x. However, this code needs thorough testing, I don't have a locked Teensy to test but followed PJRCs documentation. The updated code sends both segments (main program + loader utility) to match PJRC’s secure loader logic.

This approach should also be “fool proof” because the Teensy’s bootloader handles recovery and self-flashing. No additional hardware intervention is needed beyond a button press if something goes wrong.

Please let me know if you find issues that need fixed!
 
Just an update and some notes: https://github.com/coelacant1/Teens...mmit/5b643a1c75802bc6b1246af6e1f549323ca35fe7

Even if power is pulled mid-flash or if the second part of the EHEX is missing, it “soft bricks” the Teensy. A 15 second press of the button will reset it back to the default blink - note that if you have yours locked, blink won't run but you can still get into bootloader mode.

The new version now parses the second EHEX segment (loader utility). It mimics how Teensy Loader handles encrypted firmware for Teensy 4.x. However, this code needs thorough testing, I don't have a locked Teensy to test but followed PJRCs documentation. The updated code sends both segments (main program + loader utility) to match PJRC’s secure loader logic.

This approach should also be “fool proof” because the Teensy’s bootloader handles recovery and self-flashing. No additional hardware intervention is needed beyond a button press if something goes wrong.

Please let me know if you find issues that need fixed!
Yes you are right about power being pulled. But in a real world product you’d most likely not have a button to press. That’s where FlasherX is gold.

When flashing an EHEX with FlasherX the second part is not needed, it works anyway. I’m not sure if that’s the case when it comes to boot mode flashing(?).

Hoping that we can make a collab where your tool can have a version that works with FlasherX.
 
I'll start digging into FlasherX and seeing how to work with it! Also will start digging into the auto reset to bootloader.
FlasherX has an example, it allows sending data over serial or being fed a file from SD Card or Flash Drive (USB Host).

Sending line by line over serial along with a CRC32 would be a great solution. That’s how I do it today with a computer program.

Each lines CRC32 is verified in the Teensy which makes sure that all is good.

I’ve used FlasherX a lot so if you wonder anything let me know. I’m here to help as much as I can. If I don’t know then @joepasquariello knows more since he’s the author.
 
Back
Top