intel hex to hex conversion utilities...

Thread Starter

dtvonly

Joined Dec 14, 2012
44
Hi. I am doing in-circuit programming project using a Microchip PIC18 family microcontroller. Once the project had been successfully built, a *.hex file was created. However, this is an intel formatted hex file.

I would like to use just the "raw" hex file representing the code to be programmed into flash.

Is there, or are there, any free software or utilities that will do this conversion - strip away all headers of an intel hex and produce a raw hex file?

Please see attached intel hex file.

Thank you.
 

Attachments

Last edited:

Thread Starter

dtvonly

Joined Dec 14, 2012
44
Hi Bertus. I have tried that but the output seems to be "pure" binary. Please see attachment. Just for kicks, I tried changing the extension of the output file from *.bin to *.hex. This cause hex2bin to generate an error. So I don't think this is what I want to use. I am looking for...

rom const uint8 progMem[] = {
0x10, 0x00, 0x00, 0x00, 0x04, 0x30, 0x8A, 0x00,.......

as the final output from intel to raw hex.

Any other suggestions. Thank you though.
 

Attachments

ErnieM

Joined Apr 24, 2011
8,415
I did a programmer for a PIC16 device on a PIC18 device once. The hex file was read to create an array for the C compiler to read with data to fill continuous memory locations.

I found it useful to write my own parser using VB2010 express. Nothing fancy, you hit a button, that opens a file dialog to find the hex file, it gets parsed and presented in a text box so I could copy and paste it into some source code. My script just extracted the address (which it put into C comments), then arrayed the following data in ASCII hex notation also readable by a C compiler.

One thing a hex file will do to mess you up is it does not cover every address. Here's part of my program's output:

Rich (BB code):
/* 0x0000*/    0x2B31, 
/* 0x0004*/    0x00FF, 0x0E03, 0x1283, 0x00DC, 
/* 0x0008*/    0x0E0A, 0x00DD, 0x0E04, 0x00DE, 0x118A, 0x120A, 0x2B34, 
/* 0x0010*/    0x3001, 0x07EB, 0x0CEB, 0x30FF, 0x05EB, 0x0000, 0x0BEB, 0x2815, 
/* 0x0018*/    0x0008, 0x08EB, 0x1D03, 0x281D, 0x0008, 0x30F9, 0x0000, 0x0000, 
/* 0x0020*/    0x0000, 0x0000, 0x3EFF, 0x1D03, 0x281E, 0x0000, 0x0000, 0x0000, 
... 
/* 0x03B8*/    0x2BBB, 0x1105, 0x01E7, 0x0E5E, 0x0084, 0x0E5D, 0x008A, 0x0E5C, 
/* 0x03C0*/    0x0083, 0x0EFF, 0x0E7F, 0x0009, 
/* 0x2007*/    0x3FD2,
You can see at the beginning of memory some addresses are skipped, so I had some hand editing to do there to insert dummy data to unused memory locations. Also, the very last address is the configuration settings which also need their own special handeling.

You may find the attachment useful.
 

Attachments

Thread Starter

dtvonly

Joined Dec 14, 2012
44
Hello,

What compiler are you using?
Has the compiler options to change the output format?

Bertus
Hi. I am using MPLAB v8.76 IDE along with C-18 compiler. I looked at the hex output format and there are only 4:
INHX32, INHX8S, INHX8M and Suppress (don't even know what this is).

I have tried all and they all generated the intel hex file.
 

Papabravo

Joined Feb 24, 2006
22,111
Hi. I am doing in-circuit programming project using a Microchip PIC18 family microcontroller. Once the project had been successfully built, a *.hex file was created. However, this is an intel formatted hex file.

I would like to use just the "raw" hex file representing the code to be programmed into flash.

Is there, or are there, any free software or utilities that will do this conversion - strip away all headers of an intel hex and produce a raw hex file?

Please see attached intel hex file.

Thank you.
I don't understand your definition of "raw". Any of the Intel HEX formats is about as raw as you can get. You still need to know where to put the data and how many bytes are in each record. The checksums are not difficult to deal with either.

What exactly do you mean when you talk about headers?
 

Ian Rogers

Joined Dec 12, 2012
1,136
rom const uint8 progMem[] = {
0x10, 0x00, 0x00, 0x00, 0x04, 0x30, 0x8A, 0x00,.......

as the final output from intel to raw hex.
It's binary..... Just because C uses hex doesn't mean it's a hex file...

hex2bin will give you what your after..... you can still store a const rom array like this.

rom const uint8 progMem[] = {
16, 0, 0, 0, 4, 48, 138, 0,.......

as a raw binary file.
 

Thread Starter

dtvonly

Joined Dec 14, 2012
44
I don't understand your definition of "raw". Any of the Intel HEX formats is about as raw as you can get. You still need to know where to put the data and how many bytes are in each record. The checksums are not difficult to deal with either.

What exactly do you mean when you talk about headers?
Please see attached intel hex format (from Wikipedia).
I want a utility/software that will give me only the (cyan) data part, preferrable in 0xff, 0xab, 0xaa format and so on...
 

Attachments

Papabravo

Joined Feb 24, 2006
22,111
Please see attached intel hex format (from Wikipedia).
I want a utility/software that will give me only the (cyan) data part, preferrable in 0xff, 0xab, 0xaa format and so on...
You don't even have to write a program; you could use a text editor with regular expressions and a Search/Replace feature. Why can't you just process the strings as they are? How do you know where the data without headers is supposed to go?
 

ErnieM

Joined Apr 24, 2011
8,415
You don't even have to write a program; you could use a text editor with regular expressions and a Search/Replace feature. Why can't you just process the strings as they are? How do you know where the data without headers is supposed to go?
Well that would be quite tedious, would it not? People really suck at simple repetitive tasks, even more so for those blessed with an intellect. There just ain't no meat to keep the mind interested. Plus a hex file stores each instruction as 2 byte quantities in big endian, mening you have to swap each and every pair of data bytes. That ain't no job for any search and replace tool.

And if you make any changes to the code then you have to do it all over again...
 

WBahn

Joined Mar 31, 2012
33,122
Hi Bertus. I have tried that but the output seems to be "pure" binary. Please see attachment. Just for kicks, I tried changing the extension of the output file from *.bin to *.hex. This cause hex2bin to generate an error. So I don't think this is what I want to use. I am looking for...

rom const uint8 progMem[] = {
0x10, 0x00, 0x00, 0x00, 0x04, 0x30, 0x8A, 0x00,.......

as the final output from intel to raw hex.

Any other suggestions. Thank you though.
Clearly you are doing programming of some kind. You know the format of the text file you want to read and you know the format of the text file you want to write. What is preventing you from spending the hour or so it would take to write a program accomplishes that your exact needs?
 
Top