PIC24F Checksum Calculation

PIC24F Checksum Calculation

Postby matthewnevels » Fri Jun 22, 2018 10:13 pm

I recently signed up on the Microchip forum and have been unable to post there since I signed up.

I could use some help figuring out what I'm missing. Calculating the checksum of the PIC24F looks to be straightforward, according to section 6.1 from DS39919C - PIC24FXXKA1XX/FVXXKA3XX Flash Programming Specification - (see attached screen capture) the checksum is just the 16bit byte sum (one byte at a time) of the configuration block (only lower two bytes are summed) and the program memory (all 3 bytes are summed). There are two examples in the datasheet, but I'm not even get the first to work out:
I am using a PIC24F32KA302, and the erased checksum is given as 0x8158. If I add the configuration block (masked as shown in the datasheet) a PIC24FV32KA302 with default configuration block values would be 0x000F + 0x0003 + 0x00E7 + 0x00FF + 0x00FF + 0x00FF + 0x0083 + 0x00DF = 0x0558. I'm not sure what I need to change to get 0x8158. I've tried various modifications such as taking the inverse or the 2's complement but I'm just not getting there. I've searched the forums extensively as well as the internet and am not finding anything to get this to work.

Hopefully, if I can get past this, then the next step of calculating the checksum once we add in the program memory will be straightforward.

Any clues?
Attachments
DS39919C Checksum Calculation.PNG
DS39919C Checksum Calculation.PNG (82.01 KiB) Viewed 261 times
matthewnevels
 
Posts: 5
Joined: Fri Jun 22, 2018 10:03 pm
PIC experience: Professional 1+ years with MCHP products

Re: PIC24F Checksum Calculation

Postby AussieSusan » Mon Jun 25, 2018 4:31 am

What are you actually trying to do?
The document you reference is a little ambiguous in that to could reference either http://ww1.microchip.com/downloads/en/D ... 39919c.pdf or http://ww1.microchip.com/downloads/en/D ... 39919c.pdf. Both documents show how to use the ICSP interface to program the device.
Are you trying to come up with your own programmer?
Also be very careful about which documents you refer to with respect to any particular MCU. Microchip have a bit of a habit of abandoning documents (but leaving them on their web site) and/or updating them with different version numbers.
The most reliable way to make sure that any documents you use actually refer to the specific MCU you have is to look at the device web page and use the documents linked to from there.
Susan
AussieSusan
Verified identity
 
Posts: 86
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: PIC24F Checksum Calculation

Postby matthewnevels » Mon Jun 25, 2018 3:13 pm

Thank you AussieSusan! Let me give you a 2 part response:

1.
I looked at both documents you referenced, I don't see a difference in them, I am relatively new to the Microchip world and I am finding the support resources available to be a little bizarre to say the least. I'll keep my rants and puzzlings to a minimum here though as it's becoming obvious to me that I am not the first to be puzzled by the way they do things. I did, however go to the website for the product: http://www.microchip.com/design-centers/16-bit/products/pic24f and from that site I don't even see the datasheet for the PIC24F let alone the programming reference - though there are a number of documents there that make me think I'm in the right place to find the correct documents. I had been there before and found the product page to be pretty useless, but since you suggested that that the 'device web page' would have the correct documents, I was then able to look around and it turns out if I go to Design Support -> Documentation, I was able to dig in and find the DS-39919C document that you linked to. Thanks for giving me the direction to keep looking. honestly don't know how I came across the programming reference that I did get ahold of, it was likely the result of a google search... Good to know that I shouldn't trust what I see unless I can find it linked from the Design Support pages. Thank you!

2.
I am a Production Engineer (new to this company) that has been tasked with automating the installation of firmware on devices at production time. The developers of the software believe they have had an issue with a corrupt file in the past - so their current process is to open MPLAB8, import the HEX file and verify that the checksum noted in the menu bar matches the checksum that is recorded from when they made their original build (they append that to the filename) then they use the tools in MPLAB8 to program their device.
I will be automating the PK3CMD.EXE to program and verify the PIC24, but everyone would feel more comfortable if I could give them confirmation that the checksum of the file matches what MPLAB8 shows before I attempt to program the device. PK3CMD.EXE doesn't have an option to calculate this checksum like MPLAB8 does, though it does have the option to verify the programmed file - I have manually corrupted a line in a HEX file and verified that the Intel HEX checksum is incorrect for the corrupted line and have confirmed that the PK3CMD.EXE will still program that file without any warning or indication that the file is corrupt.
I recognize that the checksum that MPLAB8 calculates is only for the program memory and configuration registers - not everything in the HEX file, such as EEPROM data. I'd prefer to create a more thorough CRC such as MD5 and compare that each time I read the HEX file before it gets programmed but they would really like to see the Checksum match MPLAB8 - and I honestly thought this would be fairly trivial so I went with it as a first pass to give a comfort level. It's turning out to be a challenge to see if I can figure out what is going on and now I really want to do it for sake of learning what is going on.
I will say that when I open up MPLAB8 and select the PIC24FC32KA302 the tool bar then shows 0x8158 as the checksum before I import a hex file - which matches what DS-39919C shows for an erased checksum value (see attachment). I'd at least like to know how they're calculating that...

Any insight that anyone might have would be tremendously helpful. Thank you again, I am learning a lot about the PIC24 in this process .

Matthew
Attachments
MPLAB base checksum.PNG
MPLAB base checksum.PNG (6.16 KiB) Viewed 235 times
matthewnevels
 
Posts: 5
Joined: Fri Jun 22, 2018 10:03 pm
PIC experience: Professional 1+ years with MCHP products

Re: PIC24F Checksum Calculation

Postby matthewnevels » Mon Jun 25, 2018 4:28 pm

I apologize - - I stand corrected - PK3CMD.EXE will fail with a 'Failed to Load HEX File' if you give it a corrupt hex file. My mistake was that my HEX editor was automatically recalculating each end of line checksum whenever I changed a byte in the data section before I hit save, I thought I was corrupting the HEX file, but my editor was making the file itself a valid Intel HEX formatted file, so PK3CMD.EXE was happy with it and would program without question... I believe this reassurance will work for our needs, however - I'm still very curious at how to get the checksum calculation to match DS-39919 and MPLAB8. I realize that everyone's got their own work to do - feel free to respond if you're interested in helping satisfy my curiosity... Thanks,

Matthew
matthewnevels
 
Posts: 5
Joined: Fri Jun 22, 2018 10:03 pm
PIC experience: Professional 1+ years with MCHP products

Re: PIC24F Checksum Calculation

Postby jtemples » Mon Jun 25, 2018 6:42 pm

I would stick with your idea of the MD5 and forget about checksums...they're almost worthless. Two files having the same checksum doesn't mean the files are the same.
jtemples
Verified identity
 
Posts: 169
Joined: Sun May 25, 2014 2:23 am
Location: The 805
PIC experience: Professional 5+ years with MCHP products

Re: PIC24F Checksum Calculation

Postby matthewnevels » Mon Jun 25, 2018 7:42 pm

Thanks jtemples, I agree - checksums aren't worth much, and I intended to implement the MD5 verification on top anyway, which is how I've done this same thing with other projects. The checksum verification was just because I'm changing the production process from having the operator manually using MPLAB8 and clicking the right buttons and visually verifying the checksum to an automated programmer whose intent is that it would functionally replicate the current process. Now that I've dug in deeper and verified that PK3CMD.exe won't load a corrupt intel HEX file, and I can also inform the developers that the checksum is not calculated on the EEPROM in the HEX file, I believe I've got a better case to convince the original developers that the checksum verification step wasn't very useful anyway and switching to MD5 will be a more realistic verification - even though it is different than what has been done in the past.
matthewnevels
 
Posts: 5
Joined: Fri Jun 22, 2018 10:03 pm
PIC experience: Professional 1+ years with MCHP products

Re: PIC24F Checksum Calculation

Postby AussieSusan » Tue Jun 26, 2018 3:38 am

To finish off the side-thread about how to find the correct page for a device, I do the following:
- go to the main web side page and enter the part number in the 'Search' box (top right-hand corner)
- In the page that displays the results, typically the first one or two entries will be to the device page - in your case that will be https://www.microchip.com/wwwproducts/en/PIC24F32KA302
- From there you will get all of the relevant documentation, code examples, data sheets and errata etc. (particularly under the 'Documents tab)
I note that Microchip often rearrange their web pages which can make this process a bit tedious, but apparently their marketing people think its great.
Susan
AussieSusan
Verified identity
 
Posts: 86
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: PIC24F Checksum Calculation

Postby matthewnevels » Tue Jun 26, 2018 2:36 pm

Thanks AussieSusan - That is not a page I've been to yet... Interesting that it only seems to be available via search. Good info!
matthewnevels
 
Posts: 5
Joined: Fri Jun 22, 2018 10:03 pm
PIC experience: Professional 1+ years with MCHP products


Return to PIC24

Who is online

Users browsing this forum: No registered users and 0 guests