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.

Msp430 CRC calculation of Flash



Hi ,

I am using the crc-engine in the MSP430F5435A, for checking FLASH and I am having confusion in implementation. I am a new to this platform.

 

Do I have to do:

if(crc16Check()!= 0)
  {
    printf("CRC16 Error"); //enable alarm LED
  
    while(1);
  }


UINT16 crc16Check(void)
{
  unsigned int length;
  unsigned short crc16;
 
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
 
  length = sizeof(CRC_TEST_SEQ)-1;
  printf("\nMessage: %s (len = %d)\n\n", CRC_TEST_SEQ, length);
 
  // calculate CRC with table method
  crc16 = crc16MakeTableMethod(CRC16_INIT_REM, crc16Table, msg, length);
  printf("CRC16_tab: 0x%X(N)\n", crc16);
 
  return (0);
}

unsigned short crc16MakeTableMethod(unsigned short crc, TBL_MEM unsigned short *table,
                                    unsigned char *pbuffer, unsigned int length)
{
    while(length--)
        crc = table[((crc >> 8) ^ *pbuffer++)] ^ (crc << 8);    // normal

    return(crc ^ CRC16_FINAL_XOR);
}

#############################################################

OR

Do i have to calculate as per Note :

Checksum calculation made by XLINK

You can use these options either in your linker command file (filename .XCL) or in the Embedded Workbench.

In the EW you set up calculation of the checksum in the Project > Options > Linker (XLINK) > Processing. The options that corresponds to the examples are Fill unused code memory (command line option H); Fill pattern (any pattern); Generate checksum (command line option J); size = 2 bytes; CRC16; Complement = as is; Bit order = MSB first.

From command line (or in the .xcl file) you use the -J and -H linker options for calculating the checksum. Note that you must use the -H filler byte option to be able to use -J.

There are some requirements that you have to fulfil to make this work.

You must ensure that the segment in which the checksum itself is stored has a proper address and address range.

-Z(CODE)CHECKSUM=1000-1001 /* In this example a two byte checksum */

You should have both a start and stop address defined for all code segments.

-Z(CODE)CODE_SEGMENT /* Wrong */

-Z(CODE)CODE_SEGMENT=2000 /* Wrong */

-Z(CODE)CODE_SEGMENT=2000-4FFF /* Correct */

As long as you have both start and stop addresses you can have more than one CODE memory range.

-Z(CODE)FIRST_CODE_SEGMENT=2000-4FFF

-Z(CODE)SECOND_CODE_SEGMENT=7000-9FFF

 

Regards,

Ran

  • The CRC module int he 5438 doe sthe whoel CRC calculation for a CCITT compliant CRC16. The only non-obvious thing is that you need to use teh reverse registers for a CCITT compliant result.

    Just write the seed (usually 0xffff), then stuff the data bytes in the reverse byte register, and when done, read the CRC from the reverse result register.

    It's about 4 times faster than the software algorithm (for byte-wise CRC16) I used before and gives the same results.

  • Thanks, for clearing the confusion. I will surely try it out

  • I have downloaded BSL source code SLAA450.zip.  I could see that as you have mentioned above same algorithm is there.

    int BSL430_crcCheck(unsigned long addr, unsigned int length, int* result)
    {
        unsigned long i;

        CRCINIRES = 0xFFFF;
        for (i = addr; i < addr + length; i++)
        {
            if (LockedStatus == UNLOCKED)
            {
                CRCDIRB_L = __data20_read_char(i);
            }
            else
            {
                return BSL_LOCKED;
            }
        }
        *result = CRCINIRES;
        return SUCCESSFUL_OPERATION;

    }

    Does the BSL directly checks the CRC of flash application code? What are the steps to be followed to verify CRC of application code ?

    Regards,

    ran

  • I think (but I may be wrong, I never dealt with the BSL personally), that there is a CRC command that just amkes a CRC over a goven address range. So the program that accesses the BSL can request a CRC for identifying the existing firmware, or verifying the integrity of the just written one. Or it may do a config CRC check to check whether a stored configuration is valid or needs to erased/rebuilt. (remember, if you append the CRC of a data block to th edata block and do a CRC over the whole, you'll get 0 if everything is correct)
    Even without using the BSL, I store my configs with CRC, so I can easily verify integrity without even knowing the 'right' CRC.

  • Without using BSL , how to verify CRC of application image. What are the steps involved?

     

    Also using BSL , how to verify CRC of application image. What are the steps involved?

  • An applicaiton immage does not have a CRC. YOu may add a CRC by any means you can think of, and later test it with the same CRC algorithm.

    It's possible that the BSL scripter applicaiton builds a CRC over the image by itself, and later calls this CRC function over the flashed image to compare it with the CRC it calculated itself before flashing. But that's purely internal to this specific tool then.

**Attention** This is a public forum