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.

Compiler: crc_table value does not match

Other Parts Discussed in Thread: MSP430F2274, MSP-FET

Tool/software: TI C/C++ Compiler

Hi,

I've tried to use the crc_table function in the linker command file, but in the application I'm not able the calculate the same value as the Linker.

My development enviroment looks like:

Operating System: Windows 10 64Bit

CCS: 6.6.2

Compiler: TI MSP430 16.9.3 LTS

MCU: MSP430F2274

A snippet from the linker command file:

.TI.crctab : > FLASH
.cinit      : {} > FLASH,PAGE=0,crc_table(_crc_table_cinit )	
.const      : {} > FLASH,PAGE=0,crc_table(_crc_table_const )    
.text       : {} > FLASH,PAGE=0,crc_table(_crc_table_text ) 

In the application I'm using the crc functions which are described in the document slaa221.pdf :

// CRC16 g(x) = x^16+ x^12 + x^5 + 1 (CCITT-Polynom).
// CCITT = CRC16_802_15_4  
#define CRC16_802_15_4 1
#define CRC16_POLY	    0x1021
#define CRC16_INIT_REM      0x0
#define CRC16_FINAL_XOR     0x0

unsigned int CRC_CheckROM(CRC_TABLE *tp) {
	int i;
	unsigned int uiResult = 0;
	for (i = 0; i < tp->num_recs; i++) {
		CRC_RECORD crc_rec = tp->recs[i];
		if (crc_rec.crc_alg_ID == CRC16_802_15_4 )          // CRC_CCITT, CRC16_802_15_4 = 1
		{
			uint16_t uiCrc = 0;
			uint16_t uiExpCrc = (uint16_t)crc_rec.crc_value;  // expected checksum
			unsigned char * pData = (unsigned char *) crc_rec.addr;  // start address
			// calculate the current checksum
			uiCrc =  CRC_CalcCRC16(CRC16_INIT_REM, CRC16_POLY, pData , crc_rec.size);
			// Validate CRC Sum
			if (uiCrc == uiExpCrc)
			{
				uiResult = 1;                               // pass
			}
			else
			{
				uiResult = 0;                               // fail
			}
		}
	}
	return uiResult;
}
unsigned short CRC_CalcCRC16(unsigned short crc, unsigned short poly,
			     unsigned char *pmsg, unsigned int msg_size)
{

	unsigned int i, j;
	unsigned short msg;

	for(i = 0 ; i < msg_size ; i ++)
	{
		msg = (*pmsg++ << 8);
		for(j = 0 ; j < 8 ; j++)
		{
			if((msg ^ crc) >> 15) crc = (crc << 1) ^ poly;
			else crc <<= 1;
			msg <<= 1;
		}
	}
	return(crc ^ CRC16_FINAL_XOR);
}

I've implemted a table based crc function as well.

Here are my results:

.text section:

Linker: crc_value 0x00005A9E

Linker: crc_alg_ID 0x0001

Linker: addr 0x8000

Linker: size 0x1000

application:

16 Bit calculation bitwise: 0x1CBC

16 Bit table calculation: 0x1CBC

Where is my fault?

Kind regards,

Arne

  • Hello Arne,

    Is there any chance that you can provide a test case that reproduces a discrepancy between the linker calculated CRC value for the .text section and your calculation of the CRC value for the .text section? Please include the input object files and libraries for the link step as well as any linker command files that were used. Finally, please include the details of the linker command that was used.

    Regards,

    Todd Snider

  • Hello Todd,

    at the moment I'm a littele bit confused.

    I build a litte project (see attached zip file) with my compiler and linker settings.

    And in this little test project everythings works as expected.

    All checksum: Linker crc_table(), Bitwise calculation and table calculation are comming to the same result: 0x76DB

    I'll compare my projects step by step, hoping to find the differnce ...

    Regards,

    Arne

    Test_crctable.zip

  • Hello Todd,

    I've compared my projects, but I did'nt find a significant difference.
    I've 5 little projects and only in one project the crc recalculation works stable.


    Regards,
    Arne
  • I've used the MSP but never used the crc_table() linker function. An obvious guess is that the CRC'ed image on your MSP is different than one on your Host IDE. Perhaps:
    1) You have included variables in the linker section for crc_table(). The variables change at run time and the runtime calc is different.
    2) There are uninitialized holes in the linker section for crc_table(). Check your map file to see if their unit holes. The linker is supposed to fill the holes with 0.
    3) A part of you code did not program properly. If you can, verify after program.
    4) Does you code use flash as nonvolatile storage. Maybe the storage has gotten included in the CRC area.
  • Hi,
    I've found the error reason: The Debugger!

    Sometimes while starting a debug session (MSP-FET Rev A, Spy-Bi-Wire) , even without setting a special breakpoint,
    the crc caluclation does not work correktly.

    But when I start my Firmware without a debugger it works correctly.
  • Sounds like you have reproducible case. Under the debug, the EEM is active but I don't see how it would modify the value read from flash memory.

    Hopefully a TI guy can comment.
  • Hello,

    This type of problem can occur when debugging if software breakpoints are used. When a software breakpoint is set, a Break instruction will be set in flash memory. This will make a checksum calculation over that memory range fail. As you've observed, the best way to confirm checksum functionality is to use hardware breakpoints or no breakpoints.

    Regards,

    James

    MSP Customer Applications