CRCCU calculation problem

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

Posts: 34
Joined: Sun Jun 30, 2013 7:08 pm

CRCCU calculation problem

Fri Jul 24, 2015 6:26 pm

I am having problem reproducing the CRCCU calculation on the host computer using C. I am using the SAM4L MCU and CCITT-16 which I understand has a polynomial of 0x11021. The result doesn't match any of the online calculators or any of the test programs I have found. Does anyone have an example that matches the algorithm use in the hardware?
Also, the Technical Support link at the top of this page doesn't seem to connect to a valid web page.
Posts: 34
Joined: Fri Jul 01, 2011 9:39 pm

Re: CRCCU calculation problem

Sat Jul 25, 2015 3:42 am

The polynomial for CCITT-16 implemented is 0x1021 (the most significant bit is assumed in the algorithm and not listed in the polynomial define). The implementation of the CRC-CCITT depends on the initial value (also no reverse byte, reverse result or swap result). Here is a website that you can put some ASCII characters and see that it matches the SAMx hardware CRC generator. ... ation.html

For the ASCII string "ABCDEFG" results in the CRC-CCITT (0xFFFF) = 0x47D0.

Here is a code snippet for the D21 which should be close or the same for the SAM4L.

Code: Select all

  uint8_t mytestCRC[] = "ABCDEFG";
  crc = CalCRC16((uint8_t *)&mytestCRC, 7);

Code: Select all

uint16_t CalCRC16(uint8_t *pSrc, uint32_t len)
  uint32_t i;

  /* disable the CRC engine */
  /* initialize start CRC value for the CRC16 */

  /* configure the CRC engine */
  DMAC_CRCCTRL_Type crcctrl =
    .bit.CRCSRC = DMAC_CRCCTRL_CRCSRC_IO_Val, /* I/O interface */
    .bit.CRCBEATSIZE = DMAC_CRCCTRL_CRCBEATSIZE_BYTE_Val, /* Byte bus access */
  DMAC->CRCCTRL.reg = crcctrl.reg;

  /* enable the CRC engine */

  /* write all values that are used for the CRC calculation */
  for (i = 0; i < len; i++)
    DMAC->CRCDATAIN.reg = *pSrc++;

  /* clear the busy bit */

  /* get final CRC value */
  return ((uint16_t) DMAC->CRCCHKSUM.reg);
Hope that helps
Posts: 34
Joined: Sun Jun 30, 2013 7:08 pm

Re: CRCCU calculation problem

Tue Aug 04, 2015 3:51 pm

I found the problem. Atmel is using the low bit instead of the high bit so reversing the values before calculation did the trick. Here is a calculator that matches (click CCITT and check the 'reverse data bytes' to get the correct value).

The SAM4L calculates 0x1541 for ABCDEFG.

Thanks Chris for your answer.

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest