intel hex to hex conversion utilities...

Discussion in 'Embedded Systems and Microcontrollers' started by dtvonly, Dec 14, 2012.

  1. dtvonly

    Thread Starter Member

    Dec 14, 2012
    43
    0
    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.
     
    Last edited: Dec 14, 2012
  2. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,347
  3. dtvonly

    Thread Starter Member

    Dec 14, 2012
    43
    0
    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.
     
  4. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,347
    Hello,

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

    Bertus
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    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:

    Code ( (Unknown Language)):
    1. /* 0x0000*/    0x2B31,
    2. /* 0x0004*/    0x00FF, 0x0E03, 0x1283, 0x00DC,
    3. /* 0x0008*/    0x0E0A, 0x00DD, 0x0E04, 0x00DE, 0x118A, 0x120A, 0x2B34,
    4. /* 0x0010*/    0x3001, 0x07EB, 0x0CEB, 0x30FF, 0x05EB, 0x0000, 0x0BEB, 0x2815,
    5. /* 0x0018*/    0x0008, 0x08EB, 0x1D03, 0x281D, 0x0008, 0x30F9, 0x0000, 0x0000,
    6. /* 0x0020*/    0x0000, 0x0000, 0x3EFF, 0x1D03, 0x281E, 0x0000, 0x0000, 0x0000,
    7. ...
    8. /* 0x03B8*/    0x2BBB, 0x1105, 0x01E7, 0x0E5E, 0x0084, 0x0E5D, 0x008A, 0x0E5C,
    9. /* 0x03C0*/    0x0083, 0x0EFF, 0x0E7F, 0x0009,
    10. /* 0x2007*/    0x3FD2,
    11.  
    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.
     
  6. dtvonly

    Thread Starter Member

    Dec 14, 2012
    43
    0
    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.
     
  7. Papabravo

    Expert

    Feb 24, 2006
    10,144
    1,791
    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?
     
  8. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    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.

     
  9. dtvonly

    Thread Starter Member

    Dec 14, 2012
    43
    0
    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...
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    You can write a simple program to extra the information you are after.
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Yeah that's what I did.
     
  12. Papabravo

    Expert

    Feb 24, 2006
    10,144
    1,791
    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?
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    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...
     
  14. WBahn

    Moderator

    Mar 31, 2012
    17,748
    4,796
    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?
     
Loading...