• AVR Freaks

Hot!PIC18F55K42 CRC and Scanner don't match HEXMATE generated value

Author
unmanned_player
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2018/09/17 15:03:04
  • Location: 0
  • Status: offline
2018/10/07 15:45:11 (permalink)
0

PIC18F55K42 CRC and Scanner don't match HEXMATE generated value

I'm writing a simple method to checksum region of flash starting 0x1000 to (0x7FF0 - 1). The scanner does produce results, but it doesn't seem to match the ones I generate using HEXMATE. When I passed bytes from TBLAT as is, the CRC module at least reports the correct values matching that of HEXMATE. When I use scanner to do the same, this doesn't work.
 
Does anyone know why scanner is generating incorrect values?
 
Here's my code that doesn't work:
 

 void checksum_region(void)
{
    uint8_t status;
    uint16_t crc;

    CRCCON0bits.EN = 1;
    CRCCON0bits.ACCM = 1;
    CRCCON0bits.SHIFTM = 0;

    CRCCON1bits.DLEN = 8 - 1;
    CRCCON1bits.PLEN = 16 - 1;

    CRCACC = 0xffff;
    CRCXOR = 0x1021;

    CRCCON0bits.CRCGO = 1;

    asm("BANKSEL PRLOCK");
    asm("MOVLW 0x55");
    asm("MOVWF PRLOCK");
    asm("MOVLW 0xaa");
    asm("MOVWF PRLOCK");
    asm("BSF PRLOCK,0");

    SCANCON0 = 0;
    SCANCON0bits.TRIGEN = 1;
    SCANCON0bits.MREG = 1;
    SCANCON0bits.BURSTMD = 0;
    SCANCON0bits.EN = 1;

    SCANHADR = 0x7fff - 1;
    SCANLADR = 0x1000;
    CRCCON0bits.CRCGO = 1;
    SCANCON0bits.SGO = 1;
    do {
        status = (PIR0bits.SCANIF && PIR0bits.CRCIF);
        if (status) {
            PIR0bits.CRCIF = 0;
            PIR0bits.SCANIF = 0;
        }
    } while (!status);
    SCANCON0bits.SGO = 0;
    CRCCON0bits.CRCGO = 0;

    crc = CRCACC;
    CRCCON0bits.EN = 0;
    SCANCON0bits.EN = 0;

    return crc;
}
 

 
And here's the code that works and produces the same result as HEXMATE would:
 

 
void checksum_region(void)
{
    uint16_t i, crc;
    uint8_t v;

    CRCCON0bits.EN = 1;
    CRCCON0bits.ACCM = 1;
    CRCCON0bits.SHIFTM = 0;

    CRCCON1bits.DLEN = 8 - 1;
    CRCCON1bits.PLEN = 16 - 1;

    CRCACC = 0xffff;
    CRCXOR = 0x1021;

    CRCCON0bits.CRCGO = 1;

    /* Clear NVMCON for clarity. */
    NVMCON1 = 0;
    NVMCON1bits.REG0 = 0;
    NVMCON1bits.REG1 = 1;
    TBLPTRU = 0x00;
    TBLPTRH = 0x10;
    TBLPTRL = 0x00;

    for (i = 0x1000; i < 0x7fff; i++) {
        asm("TBLRD *+");
        v = TABLAT;
        while (CRCCON0bits.FULL) {
            ;
        }
        CRCDATL = v;
    }

    while (CRCCON0bits.BUSY) {
        ;
    }

    crc = CRCACC;

    CRCCON0bits.EN = 0;

    return crc;
}
 

 
Note, this is the HEXMATE command line argument passed:
hexmate image.hex -FILL=w1:0xFF@0x1000:0x7FEF -CK=1000-7FEF@7FF0+FFFFw-2g5p1021 -oout.hex

 
I can't seem to find any difference. Any help would be great.
 
Thanks
post edited by unmanned_player - 2018/10/07 15:57:27
#1

4 Replies Related Threads

    ani777
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2018/11/21 09:24:53
    • Location: 0
    • Status: offline
    Re: PIC18F55K42 CRC and Scanner don't match HEXMATE generated value 2018/11/28 16:22:26 (permalink)
    0
    Hi , 
    Have you tried using the CRC calculator mentioned on:
    https://www.microchip.com/design-centers/home-appliance/class-b-safety-software
     
    Do the HEXMATE value match that of this calculator ? Can you verify this first ?
     
     
    Thanks!
    #2
    Reward
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2019/03/04 09:15:19
    • Location: 0
    • Status: offline
    Re: PIC18F55K42 CRC and Scanner don't match HEXMATE generated value 2019/03/05 03:29:51 (permalink)
    +1 (1)
    Hi,
     
    I too have found this, which bought me to this post. i.e. the checksum generated by hexmate cannot be reproduced using the CRC / Scanner in PIC18 devices. This appears to be due to a byte order mismatch between hexmate and the data read via the scanner & presented to the CRC generator - I can correctly calculate the CRC generated by the PIC by using a byte swap
     
    In summary, hexmate calculates it's CRC byte wise, 8 bits high bit first, the scanner presents the data as 16 bit words, high bit first, hence the two methods do not calculate the same CRC.
     
    I have yet to find hexmate options / scanner & crc configuration that are compatible with each other and suspect I will be using external tools. 
     
     
    post edited by Reward - 2019/03/05 05:29:25
    #3
    mrzed
    New Member
    • Total Posts : 1
    • Reward points : 0
    • Joined: 2017/05/17 23:34:34
    • Location: 0
    • Status: offline
    Re: PIC18F55K42 CRC and Scanner don't match HEXMATE generated value 2019/04/17 21:06:46 (permalink)
    0
    Hello. How did you solve this problem? I have the same situation... Scanner module don't work?
    #4
    Danno
    Super Member
    • Total Posts : 263
    • Reward points : 0
    • Joined: 2005/09/07 10:12:10
    • Status: offline
    Re: PIC18F55K42 CRC and Scanner don't match HEXMATE generated value 2019/04/24 16:30:57 (permalink)
    0
    I "solved" the problem by not using the scanner.  Instead I read program memory a byte at a time and feeding them manually into the CRC peripheral.
    #5
    Jump to:
    © 2019 APG vNext Commercial Version 4.5