View previous topic :: View next topic |
Author |
Message |
Requan
Joined: 11 May 2008 Posts: 74
|
How to calculate this crc16 |
Posted: Sun Dec 30, 2012 12:52 pm |
|
|
I trigger my bootloader by sending rs232 command, so I have to write my own program on PC instead of siow function: "download software". I listened what siow program send by rs232 and i saw that before last row (hex file): "00000001FF" program send CRC (for hex file below is "FEE7").
Code: |
:1000000015EF00F0EA6A050EE96EEF500DE0060EFE
:10001000016E006A002EFED7012EFBD77B0E006E0C
:10002000002EFED7EF2EF3D71200F86AD09EEA6AB0
:10003000E96AC180C182C184C19693988A88C80E3A
:10004000056EE0DF93988A98C80E056EDBDFF5D762
:020050000300AB
:020000040030CA
:0E00000000220E0E000181000FC00FE00F4025
:00000001FF
;PIC18F452
;CRC=2F20 CREATED="30-gru-12 19:03"
|
CCS told me this is CRC16, but i looked for algorithm how to calculate as below:
http://www.lammertbies.nl/comm/info/crc-calculation.html
http://www.ccsinfo.com/forum/viewtopic.php?t=45645&highlight=crc16
but nothing fit.
I look into loader.c how it is calculate:
Code: |
for (i=1; i<(buffidx-3); i+=2)
checksum += atoi_b16 (&buffer[i]);
checksum = 0xFF - checksum + 1;
|
but this 8bit crc for each row of hex file, i need to calculate all bytes in hex file.
Anybody know how to calculate it?
Best Regards,
Martin |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Dec 30, 2012 1:58 pm |
|
|
You didn't tell why you want to calculate the CCS-private CRC? It's not checked anywhere as far as I'm aware of. |
|
|
Requan
Joined: 11 May 2008 Posts: 74
|
|
Posted: Sun Dec 30, 2012 2:49 pm |
|
|
asmboy
I am not lazy, i checked it also.
FvM
I would like to use bootloader in modbus line, so i have to create my own software to upload firmware(switch between rx and tx)
CCS told me that it is crc16 so i thought that is ordinary CRC16, but as You wrote i was wrong
I dont know what for is this crc because each row of hex contains crc and in loader.c after receiving each row, program calulate crc. I didn't see if in ccs bootloader example this crc is checking |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Mon Dec 31, 2012 4:41 am |
|
|
Sounds like you are confusing two points:
- Hex files have a 8-Bit checksum at the end of each line. It's checked e.g. by the bootloader
- CCS hex files have a CRC16 in the last comment line. It's generation method is undocumented, but I assume you can get the information from CCS. It's not checked by the bootloader. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19568
|
|
Posted: Mon Dec 31, 2012 7:06 am |
|
|
and, seriously, a bootloader, really can't use it.
Problem is that a PIC has a lot less RAM than ROM. So the bootloader has to have already written most of the memory, by the time it reaches the the CRC. If it's bad, what has been written is screwed.
It almost certainly is standard CRC16. Have you read the Intel Hex format definitions?. They specify a CRC _option_ for the format, and quite a few programs can generate this. It check-sums the memory block, _not_ the transmitted data. So the block of memory represented by the file, has a checksum calculated on it using standard CRC16, and this is then appended as a 'comment' line to the end of the file. If you are trying to checksum the 'file', then it won't work.
Best Wsihes |
|
|
|