Зачем конвертировать HEX в BIN?
Intel HEX stores compiled firmware as plain-text ASCII records; each byte is encoded as two hex digits wrapped in address and checksum fields. Many firmware flashing tools, bootloaders, and device update utilities expect a flat .bin image instead - for example, STM32 boards accept a .bin file dragged onto their USB drive while the Arduino toolchain outputs .hex. Converting lets you use firmware built by one toolchain with a flasher that expects the other format.
Способы конвертации HEX в BIN
avr-objcopy OPEN-SOURCE
Run avr-objcopy -I ihex -O binary firmware.hex firmware.bin in a terminal. On Linux the generic objcopy from system binutils accepts the same flags without the AVR-specific package.
SRecord OPEN-SOURCE
Run srec_cat firmware.hex -Intel -o firmware.bin -Binary. SRecord handles address gaps in the HEX file by filling them with 0xFF, matching erased flash memory.
Об этих форматах
Файл .hex - это файл Intel HEX: скомпилированная прошивка для микроконтроллера, такого как Arduino, AVR или PIC, хранящаяся в виде текстовых записей. Вы не запускаете его на ПК - вы…
Открыть детали .HEX →Файл BIN чаще всего представляет собой необработанную посекторную копию CD или DVD, которая поставляется вместе с сопутствующим текстовым файлом .cue, описывающим дорожки. Смонтируйте его с…
Открыть детали .BIN →Качество и на что обратить внимание
- The
.binoutput is smaller than the.hexbecause Intel HEX encodes each byte as two ASCII hex digits plus framing overhead. - If the HEX file has address gaps - common when both flash and EEPROM regions are covered - SRecord fills them with
0xFFby default. - avr-objcopy is bundled inside the Arduino IDE on Windows under
hardware/tools; on macOS it is available via Homebrew with the avr-gcc package.
Часто задаваемые вопросы
Does converting HEX to BIN lose any data?
Where do I find avr-objcopy on Windows?
hardware/tools directory, or available via the WinAVR package.Can I use this conversion for non-AVR chips?
objcopy from system binutils with the same flags; SRecord is also architecture-agnostic.