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).
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
This example shows source code, the linker configuration file and the corresponding settings in the linker options dialog.
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
}
}
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};
All Product names are trademarks or registered trademarks of their respective owners.
© IAR Systems 1995-2019 - All rights reserved.
We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies