Skip to main content
Visitor II
June 14, 2007
Question

st72F521 checksum problem

  • June 14, 2007
  • 2 replies
  • 769 views
Posted on June 14, 2007 at 07:36

st72F521 checksum problem

    This topic has been closed for replies.

    2 replies

    Visitor II
    June 12, 2007
    Posted on June 12, 2007 at 12:31

    Hi,

    I'm in front of a problem by the using of a function which should give the checksum of my software.

    #ifdef USE_HDFLASH_CHECKSUM

    /*-----------------------------------------------------------------------------

    ROUTINE NAME : HDFlashChecksum

    INPUT : Flash address, Frequency

    OUTPUT : Embedded Command Status

    Returned values of Checksum are in EMBLG_PARAM_ENDH and

    EMBLG_PARAM_ENDL addresses

    DESCRIPTION : Compute a Checksum

    -----------------------------------------------------------------------------*/

    unsigned char HDFlashChecksum(unsigned char *Flash, unsigned char Freq)

    {

    EMBLG_PARAM_ECMD = 0x06;

    EMBLG_PARAM_PTRL = ((int)Flash & 0xFF); // Flash Address Low Byte

    EMBLG_PARAM_PTRH = ((int)Flash >> 8); // Flash Address High Byte

    EMBLG_PARAM_FREQ = Freq;

    FCSR = 0x00; // Launch command (no need to wait end of operation)

    return EMBLG_PARAM_ECMD; // Return Embedded Command Status

    }

    #endif

    How can I know the ''Flash Address Low Byte'' of my soft? So what should be the value of ''Flash''?

    thanks for your help

    Visitor II
    June 14, 2007
    Posted on June 14, 2007 at 07:36

    Hi,

    although I don't really comprehend your problem in detail, I'll try to give some ideas.

    Declaring the EMBLG_PARAM_PTR as pointer to an unsigned character with

    char *EMBLG_PARAM_PTR;

    you'll get the two byte number EMBLG_PARAM_PTR as pointer to an unsigned char.

    To calculate the checksum you only have to add all the values of your flash from the first to the last byte.

    checksum = 0;

     

    for(EMBLG_PARAM_PTR = FLASH_FIRST_BYTE; EMBLG_PARAM_PTR <= FLASH_LAST_BYTE;) checksum += *(EMBLG_PARAM_PTR++);

    where FLASH_FIRST_BYTE and FLASH_LAST_BYTE are constant pointers to the first and to the last byte of your flash.

    But pay attention: If FLASH_LAST_BYTE == 0xFFFF you'll meet a serious problem: Increasing EMBLG_PARAM_PTR (== 0xFFFF) causes an overrun to 0x0000. Then the query EMBLG_PARAM_PTR <= FLASH_LAST_BYTE will give a wrong result and you might enter a deadloop!!!

    In this case better use

    checksum = 0;

     

    for(EMBLG_PARAM_PTR = FLASH_LAST_BYTE; EMBLG_PARAM_PTR >= FLASH_FIRST_BYTE;) checksum += *(EMBLG_PARAM_PTR--);

    Alternatively to declared constants you might take numerical constants as addresses:

    checksum = 0;

     

    for(EMBLG_PARAM_PTR = (unsigned char*)0xFFFF; EMBLG_PARAM_PTR >= (unsigned char*)0x8000;) checksum += *(EMBLG_PARAM_PTR--);

    Hope it will help you to find a solution,

    WoRo