Calculate CRC32 as in K60 hardware

Technical Note 85753

Targets:
ARM

Component:
General

Updated:
10/9/2013 3:36 PM

Introduction

K60 devices from Freescale have a built-in hardware CRC32 calculator. (This means that using CRC32 in an application can be done without using code space for the algorithm).

Solution for IAR Embedded Workbench for ARM version 6.60

Options for 6.60

Options are added to Project > Options > Linker > Checksum to enable ielftool to make CRC32 calculation in the same way as the hardware in the K60 devices.

The options should be set as follows:

Size: 4 bytes
Alignment: 4
Algorithm: CRC32(0x4C11DB7)
Complement: As is
Bit order: MSB first
[ ]Reverse byte order within word [unchecked]
Initial Value: 0x0
[X]Use as input [checked]
Checksum unit size: 32-bit

Example for K60

This example shows source code, the linker configuration file and the corresponding settings in the linker options dialog.

  • Source code (snippet)
  • extern uint32_t __checksum;
    uint32_t valCrc32;

    uint32_t calcCrc32(uint32_t* data, uint32_t len, uint32_t startValue)
    {
    uint32_t result=0;
    uint32_t *memptr;

    memptr = data;

    SIM_SCGC6 |= SIM_SCGC6_CRC_MASK;

    CRC_CTRL = CRC_CTRL_WAS_MASK | CRC_CTRL_TCRC_MASK; /* 32bit CRC */
    CRC_CRC = startValue; /* Seed */
    CRC_CTRL = CRC_CTRL_TCRC_MASK; /* 32bit CRC */
    CRC_GPOLY = 0x04C11DB7; /* Poly to match
    IAR 32-bit default */
    for (uint32_t i=0; i < len; i++)
    {
    CRC_CRC = *memptr++;
    }

    result = CRC_CRC;

    return result;
    }

    void main (void)
    {
    // ROM content
    uint32_t start_address = 0x410;
    uint32_t end_address = 0x2ffb;

    uint32_t len = (end_address + 1 - start_address) / 4;

    valCrc32 = calcCrc32((uint32_t*)start_address, len, 0x0);

    if (valCrc32 == __checksum)
    {
    // TBD
    }
    else
    {
    // TBD
    }

    // ROM content, including checksum

    len++;

    valCrc32 = calcCrc32((uint32_t*)start_address, len, 0x0);

    if (valCrc32 == 0)
    {
    // TBD
    }
    else
    {
    // TBD
    }
    }
  • Linker configuration file (snippet)
  • define symbol __ICFEDIT_region_ROM_start__ = 0x00000000;
    define symbol __ICFEDIT_region_ROM_end__ = 0x00002ffb;

    "CHECKSUM":
    place at address mem:0x00002ffc { readonly section .checksum };
    keep { section .checksum};
  •  Linker options dialog

 

All Product names are trademarks or registered trademarks of their respective owners.

Related Tech Notes

© IAR Systems 1995-2016 - All rights reserved.