http://supp.iar.com/Support/?note=64424&from=note+11927
Background
The STM32 devices from ST Micro have a built-in hardware CRC32 calculator. (So using CRC32 in an application does not use up code space for the algorithm.)
Problem
The CRC32 algorithm used in STM32 devices could not be reproduced by the ielftool utility before EWARM version 5.50.
Options are added to Project > Options > Linker > Checksum to enable ielftool to make CRC32 calculation in the same way as the hardware in the STM32 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: 0xFFFFFFFF [ ]Use as input [unchecked] Checksum unit size: 32-bit
This example shows source code, the linker configuration file and the corresponding settings in the linker options dialog.
#include "stm32f10x_crc.h" extern uint32_t __checksum; uint32_t calcCrc32( uint8_t* data, uint32_t len ) { uint32_t* pBuffer = (uint32_t*) data; uint32_t BufferLength = len / 4; uint32_t index = 0; RCC_AHBPeriphClockCmd( RCC_AHBPeriph_CRC, ENABLE ); CRC_ResetDR( ); for ( index = 0; index < BufferLength; index++ ) { CRC->DR = pBuffer[ index ]; } return CRC->DR; } void main( void ) { ... uint32_t valCrc32 = calcCrc32((uint8_t*)0x08000000, 0x040000 - 4); if ( valCrc32 == __checksum ) { // TBD } else { // TBD } ... }
Linker configuration file (snippet)
define symbol __ICFEDIT_region_ROM_start__ = 0x08000000; define symbol __ICFEDIT_region_ROM_end__ = 0x0803FFFB; place at address mem:0x0803FFFC { readonly section .checksum };
In version 5.50, ielftool can be configured to calculate CRC32 in the same manner as the calculation of CRC32 using the STM32 hardware. This ability is not documented and it can only be invoked as a command line option.
The details that concern the STM32 CRC32 algorithm are
0xFFFFFFFF as initial value.
Utilize the two new ielftool algorithm flags i and r.
The string to enter in Project > Options > Build Actions > Post-build command line is...
ielftool --fill 0xFF;__checksum_begin-__checksum_end --checksum __checksum:4,crc32:ir,0xFFFFFFFF;__checksum_begin-__checksum_end --verbose $TARGET_PATH$ $TARGET_PATH$
...where these substrings are placeholders that needs to changed for the project in use:
__checksum |
The name of the symbol where the checksum value should be stored. |
__checksum_begin |
The first address on which the checksum should be calculated. |
__checksum_end |
The last address on which the checksum should be calculated. |
The preceding command line should be combined with all options reset (unchecked) in Project > Options > Linker > Checksum
ProjectOptionsLinkerChecksum(6.40) (32 KB)
ProjectOptionsLinkerChecksum(6.10-6.30) (31 KB)
Example (6.40) ZIP, 654 KB)
Example (6.21) (ZIP, 645 KB)
Technical note 11927
Checksum calculation with IELFTOOL after linking with ILINK