0

Here I am asking for the help to build the custom bootloader with PIC24FJ series micro-controller.

I am planning to use the UART for the parsing the .hex file.

Can you help?

How do I parse the .hex file? I don't have any idea about parsing of the .hex

Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
  • Can you explain why you want to parse the hex file? Why not use the binary? – Mahendra Gunawardena Apr 22 '21 at 02:16
  • @MahendraGunawardena, Yes i can use the binary but i was thinking to write the hex file data to the flash memory. But i am not sure how to do this.? i am aware of the flash writing method. But parsing i didn't even try anywhere, so if something went wrong my program will not start – Ketan Vadodariya Apr 22 '21 at 04:51
  • It is my understanding that you cannot flash a typical Intel Hex file to the microcontroller. I believe you might be aware of that. Therefore you need to extract the content related to micro controller before you flash the code to micro. Can you update the post with the IDE you are using to develop software related to pic24fj micro controller? – Mahendra Gunawardena Apr 22 '21 at 13:41
  • Were you able to resolve your issue? – Mahendra Gunawardena Apr 26 '21 at 10:45

1 Answers1

0

In order to parse a hex file you need to identify relevant format. Assuming you are using MPLAB X it is highly likely that the file format of interest is SQTP. Below are some fields an related descriptions. You will need to do some research to validate if the information below is relevant for your application.

Field Description
Field 1 Start Code – 1 character This character is an ASCII colon ‘:’
Field 2 Byte Count – 2 hexadecimal digits These two digits indicate the number of bytes (HEX digit pairs) in the data field. The maximum byte count is 255 (0xFF). For example, 16 (0x10) and 32 (0x20) byte counts are commonly used.
Field 3 Address – 4 hexadecimal digits These four digits represent the 16-bit beginning memory address offset of the data. The physical address of the data is computed by adding this offset to a previously established base address. This provides memory addressing beyond the 64-kilobyte limit of 16-bit addresses. The base address, which defaults to zero, can be changed by various types of records. Base addresses and address offsets are always expressed as big endian values.
Field 4 Record Type – 2 hexadecimal digits, 00 to 05 These two digits define the meaning of the data field. For SQTP, only three types are used; 00, 01, and 04 (see Table 1-1).
Field 5 Data – a sequence of n bytes of data Data is represented by 2n hexadecimal digits. Some records omit this field (n equals zero). The meaning and interpretation of the data bytes depends on the application.
Field 6. Checksum – 2 hexadecimal digits These two digits represent a computed value that is used to verify the record has no errors by ensuring the summation of each of the bytes in the line add upChecksum – 2 hexadecimal digits These two digits represent a computed value that is used to verify the record has no errors by ensuring the summation of each of the bytes in the line add up add up to 0.

Additional UART is a communication protocol. UART will not parse the file. You will be develop software the parse the hex file. To the best of my knowledge the microcontroller will need a binary file.

Lastly this is a solved problem. There are plenty of open source resources that will minimize your work.

Per comment below, if are using Kiel as IDE you can fromelf to create bin file.

Keil elf to bin

fromelf.exe --bin --output=user_application.bin User_Application\User_Application.axf

References

Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
  • First let's talk about the parsing, As I see hex file of my application there area some address is extended (record byte 04) , so that means if i have record by as 04 so i will get the lower address byte. and upper address would be the next line of the hex file, that fine I can parse it, but let me explain that should i have to write hex data directly to the address ? (means of Couse i have to ) but if something went wrong then it will be the problem with application. – Ketan Vadodariya Apr 23 '21 at 13:14
  • I have MCC generate 16-bit bootloader code. there just UART parsing by the unified bootloader, and that is like command and response, I try to bug the unified bootloader host application but i did not understand that how they parse hex file,I had compare the host application log which can be generate by the log-level as FINEST, with actual loaded hex file to the host application but i did understand how they parsed hex file, because there was not match case with actual hex file data. – Ketan Vadodariya Apr 23 '21 at 13:25
  • How about we step back and understand a few basics. What it IDE you are using to develop the software for the Microcontroller. Do you already have a Host Application of your choice to load the bootloader. If so what is the host application. Updating the post with these basic questions will help the community to help you achieve your goal. – Mahendra Gunawardena Apr 23 '21 at 13:31
  • I am using PIC24FJ256GL406, micro-controller with MPLAB IDEv5.40, I have my application code with out bootloader, which is i have dump by the PICKIT3 always, In field I was planning to use customize bootloader which will me the upgrade my framework with UART. – Ketan Vadodariya Apr 23 '21 at 13:36
  • Do have a host application that you plan to use in the field? I am assuming the host application will be on windows or ubuntu platform – Mahendra Gunawardena Apr 23 '21 at 13:43
  • Currently I have an unified bootloader host application but later I will develop my own Host application if I get to know hex parsing currently – Ketan Vadodariya Apr 23 '21 at 13:55
  • Are you referring to software from [here](https://www.microchip.com/promo/8-bit-bootloader). Are you using the Microchip Code Configurator to generate you code? Have you developed you own bootloader or are you using native bootloader to load the code? Per [Bootloader Generator User’s Guide](https://ww1.microchip.com/downloads/en/DeviceDoc/40001779B.pdf) chapter 6 you can only use Microchip Host applications for PIC8, and PIC1, your microcontroller is a PIC24. You might have discrepancies. I suggest you update the body of the question with additional details. – Mahendra Gunawardena Apr 23 '21 at 14:40