@@. PC USB Projects HEX Editor v3.0

Why edit a HEX file?

Hex file contains firmware code that may be directly programmed to a microcontroller’s flash RAM (EEPROM). The file also contains microcontroller’s default configuration, which determines its operation mode during startup.

PC USB Projects firmware is intended for general use therefore all presets are neutral. It is presumed that the microcontroller will be operated by a PC via USB. A PC application sets the appropriate operation mode. The firmware must only prepare the microcontroller to accept commands via USB. Independent microcontroller operation therefore requires a programmer to change presets in a HEX file. PC USB Projects HEX Editor enables him or her to do this.

How it works?

PC USB Projects HEX Editor (get it from Downloads section) enables a human programmer and a hardware designer to easily interpret and change the contents of a HEX file. It tends to preserve the file format as much as possible. Only the user required changes are made.

A single hexadecimal code line in the HEX file is interpreted and may be easily altered by a user. As the code line is selected it is split to a sequence of 8, 16 or 32-bit values on the corresponding addresses. The split of the contents to particular addresses is governed by predefined microcontroller features and preferred data format. By default PIC18 has a 16-bit (2 bytes) preferred format, while PC32 has a 32-bit (4 bytes) preferred format. This is also in accordance with microcontrollers flash RAM organizations.

Another PC USB Projects HEX Editor feature is the ability to interpret firmware information (FWI) files, which contain information of user selectable settings embedded in a HEX file. Though each FWI file is tailored to a specific microcontroller and its firmware, it may still be used with other HEX files for the same microcontroller. The microcontroller configuration words would be correctly interpreted, but firmware specific default values may be on different locations or missing. However, PC USB Projects firmwares are built incrementally, so earlier versions lack some parameters, or use the same EEPROM locations for program code. It is therefore advisable to use the FWI file only with the firmware it is intended for, or with a newer version for the firmware for the same microcontroller.

Quick start instructions

Prerequisites

PC USB Projects HEX Editor works with all Windows versions starting from Windows XP. It additionally requires .NET 2.0 or newer .NET framework to be installed. There are 4 precompiled subversions of PC USB Projects HEX Editor (EXE files) for each version. There are two 32-bit subversions for .NET 2.0 and .NET 4.0 and two 64-bit subversions for .NET 2.0 and .NET 4.0. The .NET 4.0 versions are intended for newer Windows operating systems with only .NET 4.0 or newer .NET framework installed.

However, all the subversions offer the same functionality. When one of the required .NET frameworks is installed, just copy the appropriate application EXE file to any directory on your disk drive, where FWI and HEX files are located and run PC USB Projects HEX Editor.

NOTE: The order of parameters in FWI file is important. Optional feature parameters preset and values must be placed at the end of a parameter definition. They should precede definition of formatting.

<DEVCFG0: Code-Protect bit> [1FC00BFC] {28} values={<Enabled>=0,<Disabled>=1}

<RFM69CW transceiver initialization> [1D01E780] {2B} values={<Enabled>=1,<Disabled>=0}

<DEVCFG0: Program Flash Write-Protect bits> [1FC00BFC] {10,11,12,13,14,15,16}

<default TRIS A value> [8483] {1B} preset={FF}

<default AN0 input type> [8487] {0} preset={0} values={<analog>=0,<digital>=1}

Let us observe the three examples above. They all include a feature name and EEPROM address. The length of address depends on the microcontroller family. Next, there is data formating in bow shaped brackets. The formatting description is used for data presentation as well as for data recoding after alteration. There are two types of formatting: list of bits that the value is composed of, and the length in bytes. The first kind for formatting presumes that bits with a higher bit number are more important. Therefore the value to be edited is represented as a hexadecimal number composed only of the values of the declared bits.

Example:

{10,11,12,13,14,15,16}

The default EEPROM word length of 4 bytes in this case means that from 32 bits only bits 10,11,12,13,14,15 and 16 are relevant.

The feature value is given by the following expression: (<32-bit value> and (0x7F)) >> 9. This means that bit 0 of the value is bit 10 in EEPROM word and bit 6 is bit 16 in EEPROM location. After pressing appropriate “Set” button a new feature is inserted into the EEPROM word in the desired location.

If letter “B” is used in the formatting, it means that the preceding number is the length of the data type in bytes. This enables a FWI file writer to declare different byte based features instead of bit-based features that we have just mentioned.

The last part of a feature declaration is optional. Sometimes it is useful to declare a list of values and their descriptions. There may be an almost arbitrary number of different values which appear in the combo box selection.

Here is another example:

<DEVCFG0: In-Circuit Emulator/Debugger Communication Channel Select bits> [1FC00BFC] {3,4} values={<PGEC1/PGED1 pair is used>=3,<PGEC2/PGED2 pair is used>=2,<PGEC3/PGED3 pair is used>=1,<PGEC4/PGED4 pair is used>=0}

Each values has a name in “<” and “>” brackets followed by its value. Delimiter is of course equality sign (“=”). The values must be coded in hexadecimal, so decimal “10” is hexadecimal “A” and decimal “16” is hexadecimal “10”.

Firmware information file reference

Firmware information file (FWI) is an ANSI text file with descriptions of particular features of one or more HEX files that can be programmed to a certain family of microcontrollers. It also contains parameters that determine PC USB Projects HEX Editor operation.

The following parameters alter the editor defaults. All parameters have the following format:

<parameter name> = <parameter value>.

Both parameter name and its value are basically strings of an arbitrary length, but PC USB Projects HEX Editor converts them to appropriate data types as they are processed.

Currently, the following parameters are supported:

microcontroller=<microcontroller name>

EEPROMwordlen=<length of EEPROM word>

LoadHEXFile=<Name of the preloaded HEX file that resides in the same folder as the PC USB Projects HEX Editor application>

AutoConfigureAndSave=<0 – user click save to store HEX file, 1 – save dialog box opens automatically wfter presets are loaded and application closes after saving HEX file.

If some of the parameters are omitted, PC USB Projects HEX Editor defaults are used. For example: EEPROM word length is determined heuristically from the number of memory segments. EEPROMwordlen = 2, if there is just one segment. And 4, if there are more than one segment.

NOTE: PC USB Projects HEX Editor currently has almost no inbuilt error handling for FWI files, so each mistake my cause it to crush. It is though advisable to alter the content of a FWI file with great care. You may also decide to solely rely on FWI files provided on PC USB Projects website.

The format of a feature is the following:

<feature name in “<” and “>” brackets> [<address>] {formatting} preset={<value>} values={<value name in “<” and “>” brackets>=<value>, …. }

Examples:

Click on the screenshot to enlarge it.

Editing a HEX file with FWI

There are five list boxes to help this process: Microcontrollers Firmware Features List, Line Editor, Detail Editor, Feature Editor and Reports. Click on “Load firmware information file *.FWI” button and select an appropriate FWI file. If FWI file already contains a HEX file name to load, the later will load automatically after the FWI file is loaded. If you prefer to use another HEX file, just click on “Load *.HEX file” button. However, the HEX file must be compatible with FWI file.

Next, select a desired feature from Microcontroller Firmware Features list box and double-click it. The appropriate HEX file line will be automatically selected in Line Editor list box and split to values in the Detail Editor list box on the right hand side. The appropriate values will be selected and Feature Editor list box will interpret its contents. One or more features will appear on the top of the listed features in Feature Editor list box.

As you double-click on any of the features listed in Feature Editor list box, a combo box for editing its contents will open on the right hand side. You may expand it and select any of the predefined values from the FWI file. You may edit particular bits of the value by double-clicking on “<bit xx> = y” line. Press set button when you decide to make change to the HEX file in RAM. Use “Save *.HEX file” button on the left hand side of the PC USB Projects HEX Editor window to save the altered HEX file to disk.

Editing a HEX file without FWI

Editing a HEX file without FWI file is also easy, but requires the user to know EEPROM location of particular default values. By clicking on “Load *.HEX” file button her or she loads a HEX file, while Microcontroller Firmware Features list box remains empty. A double-click to the selected HEX file line in Line Editor list box shows the contained values. Each of them can be edited by double-clicking. A double-click opens also the value in Feature Editor list box, where it’s bits are directly assessable. However, no features are offered in the Feature Editor.

ALSO READ:

PC USB Projects HEX Editor User Guide

SOURCE CODE:

Source code is only available for PC USB Projects HEX Editor v1.0. Get it from Downloads section. All other versions are also available from Downloads section.

Disclaimer

PC USB Projects HEX Editor is provided as it is. You use it entirely on your own risk. Though it has been thoroughly tested the author cannot guarantee its proper operation. The author is also not responsible for any kind of damage that might result from PC USB Projects website HEX files or any other HEX files that are altered using PC USB Projects HEX Editor.