This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Checksum with IAR

Other Parts Discussed in Thread: MSP430F1101A

Dear guys,

I am finishing my IAR project on the MSP430F1101A,

I want to add check-sum to my code, I added the code below to compute the check-sum on the run.

now, I am trying to determine the "saved_cs". I generated MSP-430_txt file and I computed the check-sum manually.

Unfortunately the saved_CS and the calc_cs are not equal.

Can someone help?

What is the best way to find out the saved_cs ?

Best,

Erez.


void CalcChecksum(void *Start, unsigned int len,void *cs_add)
{
unsigned long Sum = 0; //the calculation reg
unsigned int *pStart = Start; //programm read pointer
unsigned int *CS_add = cs_add; //cs read pointer

while (len) // sum all the memory words
{
Sum = Sum + *pStart++;
len = len - 2;
WDTCTL = WDTPW + WDTCNTCL; //Periodically clear an active watchdog
}

saved_cs=*CS_add;
calc_cs=(unsigned int)Sum;

if( saved_cs != calc_cs )
{
#ifdef ENABLE_CHECK_SUM
while(1)
WDTCTL = WDTPW + WDTCNTCL; //Periodically clear an active watchdog

#endif
}
}

  • First thing I noticed is: are you sure that len is always an even value? If not, your while loop will never exit.

    Next: why don't you put all teh checksum related stuff inside the #ifdef? If you don't use the result, there is no need to do the calculation or even keep the code required to do the calculation.

    However, this is not related to your problem. So let's see...

    Erez Shaul said:
    I want to add check-sum to my code, I added the code below to compute the check-sum on the run.

    When you added the checksum to your code, this changes the checksum of that code. You need to calculate the checksum without the stored checksum.

    if you calculate the checksum including the checksum, the checksum changes the checksum.

    However, you only posted your (quite simple) checksum algorithm, which looks okay so far.  (I'd say you took the name checkSUM literally. :) However, it gives a rough protection against random errors in the integrity of the stored code.)
    It would be of more interest to know how you call it and where your 'precalculated' checksum is stored. "cs_add" doesn't mean anything if its definition isn't known.

**Attention** This is a public forum