PlatformIO Community

Where to find a .bin file

Hi, I need to find/ generate a .bin or .hex file from the current project. Where can i find/generate that file?
Im using platformIO in Visual Studio Code on a Mac.

See .pio\ folder within your project?

2 Likes

I see that folder, but no .hex or .bin file

Tell me what files you see in that folder.

These 17

So can you show me what’s in this hifive1 folder?

13

Well the .elf file is the already linked binary, you should be able to use it with flasher software like openocd etc.

If you want a hex file then you can go to your <user home folder>/.platformio/platforms/sifive/builder/main.py and replace this line by

target_buildprog = env.Alias("buildprog", target_hex, target_hex)

after recompilng there is a firmware.elf and firmware.hex file.

Alternatively you can invoke the objcopy yourself in a shell in the directory where the firmware.elf is.

<home folder>/.platformio/packages/toolchain-riscv/bin/riscv64-unknown-elf-objcopy -O ihex firmware.elf firmware.hex

(can also be used with -O binary)

However I agree that it would be usefull to build this by default. You can open an issue at the repository for it.

2 Likes

I need a similar solution for platform-atmelavr. Unfortunately @maxgerhardt’s solution as above does not work there, the compile process will terminate with:

NameError: name 'target_hex' is not defined:
  File "C:\Users\Micha\.platformio\penv\lib\site-packages\platformio\builder\main.py", line 168:
    env.SConscript("$BUILD_SCRIPT")
  File "C:\Users\Micha\.platformio\packages\tool-scons\script\..\engine\SCons\Script\SConscript.py", line 541:
    return _SConscript(self.fs, *files, **subst_kw)
  File "C:\Users\Micha\.platformio\packages\tool-scons\script\..\engine\SCons\Script\SConscript.py", line 250:
    exec _file_ in call_stack[-1].globals
  File "C:\Users\Micha\.platformio\platforms\atmelavr\builder\main.py", line 165:
    target_buildprog = env.Alias("buildprog", target_hex, target_hex)

So how do I manage to get the firmware.hex file being built and preserved?

Are you using up-to-date PlatformIO and platform versions? This already builds a hex file:

$ pio run 
Processing uno (platform: atmelavr; board: uno; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR 2.2.0 > Arduino Uno
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr 5.0.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 7 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/uno/src/main.cpp.o
Archiving .pio/build/uno/libFrameworkArduinoVariant.a
Indexing .pio/build/uno/libFrameworkArduinoVariant.a
Compiling .pio/build/uno/FrameworkArduino/CDC.cpp.o
Compiling .pio/build/uno/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/uno/FrameworkArduino/HardwareSerial0.cpp.o
Compiling .pio/build/uno/FrameworkArduino/HardwareSerial1.cpp.o
Compiling .pio/build/uno/FrameworkArduino/HardwareSerial2.cpp.o
Compiling .pio/build/uno/FrameworkArduino/HardwareSerial3.cpp.o
Compiling .pio/build/uno/FrameworkArduino/IPAddress.cpp.o
Compiling .pio/build/uno/FrameworkArduino/PluggableUSB.cpp.o
Compiling .pio/build/uno/FrameworkArduino/Print.cpp.o
Compiling .pio/build/uno/FrameworkArduino/Stream.cpp.o
Compiling .pio/build/uno/FrameworkArduino/Tone.cpp.o
Compiling .pio/build/uno/FrameworkArduino/USBCore.cpp.o
Compiling .pio/build/uno/FrameworkArduino/WInterrupts.c.o
Compiling .pio/build/uno/FrameworkArduino/WMath.cpp.o
Compiling .pio/build/uno/FrameworkArduino/WString.cpp.o
Compiling .pio/build/uno/FrameworkArduino/abi.cpp.o
Compiling .pio/build/uno/FrameworkArduino/hooks.c.o
Compiling .pio/build/uno/FrameworkArduino/main.cpp.o
Compiling .pio/build/uno/FrameworkArduino/new.cpp.o
Compiling .pio/build/uno/FrameworkArduino/wiring.c.o
Compiling .pio/build/uno/FrameworkArduino/wiring_analog.c.o
Compiling .pio/build/uno/FrameworkArduino/wiring_digital.c.o
Compiling .pio/build/uno/FrameworkArduino/wiring_pulse.S.o
Compiling .pio/build/uno/FrameworkArduino/wiring_pulse.c.o
Compiling .pio/build/uno/FrameworkArduino/wiring_shift.c.o
Archiving .pio/build/uno/libFrameworkArduino.a
Indexing .pio/build/uno/libFrameworkArduino.a
Linking .pio/build/uno/firmware.elf
Checking size .pio/build/uno/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.4% (used 9 bytes from 2048 bytes)
Flash: [          ]   1.4% (used 444 bytes from 32256 bytes)
Building .pio/build/uno/firmware.hex
============================================================================================ [SUCCESS] Took 3.91 seconds ============================================================================================
$ ls -l .pio/build/uno/
total 344
-rwxrwxr-x 1 max max   7080 Jul 30 16:13 firmware.elf
-rw-rw-r-- 1 max max   1265 Jul 30 16:13 firmware.hex
drwxrwxr-x 2 max max   4096 Jul 30 16:13 FrameworkArduino
-rw-rw-r-- 1 max max 326804 Jul 30 16:13 libFrameworkArduino.a
-rw-rw-r-- 1 max max      8 Jul 30 16:13 libFrameworkArduinoVariant.a
drwxrwxr-x 2 max max   4096 Jul 30 16:13 src

I stand corrected - I seem to have been chasing a phantom again… Sorry for bothering you!