PlatformIO Community

How to make and install binary firmware file?


I have a very basic question:

I am developing a new radio control system on Teensy 4.1 in PlatformIO. A few other people are testing and using this system to fly their models. When the software is updated, I would like to create a binary file and upgrade the teensy 4.1 firmware easily for these people.

Can anyone tell me how best to do this?

I’m ashamed I don’t know! :grin:

Thank you very much in advance!

Malcolm Messiter
07979 647831

PlatformIO already generates the binary output files for you in the build directory. If you named your environment in the platformio.ini the standard teensy41, after a compile, you will find .pio/build/teensy41/firmware.hex and related (.elf, .bin). The .hex file can be used in the standard Teensy flasher tools, e.g. here, and then the teensy can with that be programmed with the click of a button.

1 Like

Thank you Max !

I guessed it must be simple enough - when you know.

I shall explore - and there may be an annoyingly loud shout of EURIKA! When I get it to work. :grin:

I guess that Teensy ‘loader’ app is therefore needed by users to upgrade the firmware? I better ask them to download it.

Thanks again


Eurika!!! It is working thank you!

But I see the reset button must be pressed. That means opening up the transmitter case which is five screws… Is there a way of doing this without pressing a button on the teensy manually?

Oh right I forgot about that. The teensy tools (and thus also PlatformIO) can reboot the teensy automatically into bootloader mode if the firmware exposes the standard USB serial. But for that an extra teensy program called teensy_reboot must be used. Once the teensy.exe GUI is open and says “press reset button”, you can just execute the teensy_reboot program and then teensy.exe will see the device, no reboot button pressing needed. This has already outlined in

Note that these tools are for some reason not available for a precompiled download from the Teensy website, only when one would install the full Teensyduino Arduino IDE extension. However, you can grab the files (that is, actually all teensy related tools) from PlatformIO. The API request shows the available OSes and download links, e.g.

(needs e.g. 7zip to extract the .tar.gz)

There’s also a more automated way of doing it with all these tools available. One can just put the two tools teensy_reboot.exe and teensy_loader_cli.exe in the same folder as the firmware.hex and the following simple upload.bat script (this is Windows specific of course)

@echo off
echo Rebooting device
teensy_reboot.exe -s 
echo Flashing firmware
teensy_loader_cli.exe -w -s -mmcu=TEENSY41 -v firmware.hex


So, simply double-clicking on upload.bat will do a reboot & flash & reboot to firmware, then ask to press a key to close the window.


The script can be trivially written for Unix-like OSes (aka, Linux & Mac) too. They will need the appropriate version of the tools for their OS too, of course.

And finally, if your users are themselves developers who already have PlatformIO, you can just compile locally once, then clear the .pio\build\<env>\ folder while not deleting the needed firmware.hex. Users can then do a upload without compile (taking the existing firmware.hex) with pio run -t nobuild -t upload as explained in Upload Latest build without a Compile/Link - #4 by ivankravets. Then PlatformIO would also automatically take care of downloading the correct version of the tools since it draws those from the PlatformIO registry. This would need a whole PlatformIO installation of course, and the distribution package above there is more compact.

1 Like

Fantastic! Thank you a million times.
An amazing answer! Perfect!
The nostalgic batch file approach appeals to me a lot as I was brought up on MS-DOS 2.11 and 8086 assembler :grin: I’ll do it …

… it occurs to me (during tests this evening) Windows is less than perfectly reliable especially via Parallels on usb / com ports…

But I could add an option into my Teensy 4.1 code that would trigger a reset simply by rapidly overfeeding the watchdog.

This could allow a simple firmware upgrade without removing the back of the case.

I’ll try this tomorrow morning. Thank you again!


Something not working as expected, or not every time? Maybe some delay / sleep 1 is needed in between rebooting and flashing?

Please check an upload output, PlatformIO hints you with multiple upload protocols. Have you tried to add to platformio.ini?

bord = ...
upload_protocol = teensy-cli

That was in reference to doing it the custom way with just teensy.exe, not with PlatformIO :smiley:

Ah… Sorry, marked your post as the “SOLUTION” :wink:

P.S: We plan to update our docs for Teensy and add information about uploading via CLI without Tensy GUI.

Indeed I have more work to do.

My watchdog reset idea certainly reset it as expected, but this disappointingly failed to get the loader to load the firmware and I don’t yet know why.

All ideas gratefully accepted! It’s so nearly there!

I did succeed this morning in reading the Teensy 4.1 MAC address and using this as a unique pipe address for RF binding (I’m using an nRF24L01 transceiver). So that’s a big step in the right direction. Now I can send identical update files to all users. :grin:

I guess getting into bootloader mode is not simply doing a reset, but something more. Can you explain in more detail what happens when you do it with teensy_reboot -s? Have you tried adding -v in there to see if there are any errors?

I think your suggestion is probably very helpful but I can’t understand it yet sorry! Could you explain more completely as if to a beginner like me ?!

Ivan assumed you had trouble uploading through PlatformIO, and said to make sure to set the upload_protocol in the platformio.ini to that value. It’s not relevant if you are right now having problems with a custom upload script.

1 Like

Ok - Eurika ^2!! :grin:

It’s working now!

Under latest Mac OS, if I use and teensy_reboot it successfully loads the firmware!

Now I must make a Mac version of a batch file to automate this for the more simple folk!

Thank you for your help! :grin::grin:


1 Like