Teensy 4.1 compiling .bin file

I am trying to have the compile process generate a firmware.bin file. In the .pio/build/teensy41 directory I see firmware.hex and firmware.elf but not firmware.bin. I have searched the forums but only found posts that say the firmware.bin file should be in the directory with the other files.

I am using VScode, PlatformIO Core 6.1.16 on a Mac.

The ElfToBin builder in platform-teensy goes unused. Seems like since no uploader tool uses the .bin format, but rather the .elf or .hex format, the platform doesn’t see any need to actually build a bin file.

Which in turn also begs the question why you would need the file that is more work to handle (needs base address, 0x60000000).

In any case, the advanced scripting documentation shows you how to post-process the firmware.elf file, to e.g. run arm-none-eabi-objcopy on it to turn it into a .bin file.

So, you should be able to add to the platformio.ini

extra_scripts = to_bin.py

with the to_bin.py file being

Import("env")
env.AddPostAction(
    "$BUILD_DIR/${PROGNAME}.elf",
    env.VerboseAction(" ".join([
        "$OBJCOPY", "-O", "binary", "-R", ".eeprom",
        "$BUILD_DIR/${PROGNAME}.elf", "$BUILD_DIR/${PROGNAME}.bin"
    ]), "Building $BUILD_DIR/${PROGNAME}.bin")
)

Thanks again for your help Max. I really appreciate it. We are looking at the mongoose.ws library for Teensy IP stack and web GUI. They have a firmware update widget and code but it needs .bin files. I will put in a feature request on their Github to use .hex files with the firmware update widget.

Oh, if that file is going to downloaded via the network by the Teensy, then .hex will be a bigger file format and more complicated to process than a raw start address info and bin file. In that case it would be understandable and preferable to use a .bin file.

The Python script and platformIO settings you provided work perfectly. I was able to use the .bin file with Mongoose to update the Teensy over the network. Thanks again.