http://supp.iar.com/Support/?note=64424&from=note+11927
Background
The STM32 devices from ST Micro has a built-in hardware CRC32 calculator. (So using CRC32 in a application does not use up code space for the algorithm.)
Problem
The CRC32 algorithm used in STM32 devices could is not being reproduced by the Ielftool utility before Ewarm version 5.50.
Solution for Ewarm version 6.40 and lateroptions for 6.40 and later
Options is added to Project > Options > Linker > Checksum to enable Ielftool to make CRC32 calculation In the same, the hardware in the STM32 devices.
The options should be set as follows:
4 bytes 4 algorithm:crc32 (0x4c11db7) is Bit ORDER:MSB First byte order within Word [unchecked] 0xFFFFFFFF as input [unchecked] -bit
Example for stm32f10x
This example shows source code, the linker configuration file and the corresponding settings in the Linker Options dialog.
#include"stm32f10x_crc.h"externuint32_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]; } returnCrc->DR;}voidMainvoid) {... 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;d efine symbol __icfedit_region_rom_end__ 0X0803FFFB ;p lace at address mem: 0X0803FFFC readonly section. Checksum};
Solution for Ewarm version 5.50
In version 5.50, Ielftool can is configured to calculate CRC32 in the same manner as the calculation using the ST M32 hardware. This ability was not documented and it can have only been invoked as a command line option.
The details that concern the STM32 CRC32 algorithm is
0xFFFFFFFF as initial value.
Utilize the new Ielftool algorithm flags I and R.
The string to enter in Project > Options > Build Actions > Post-build command line is ...
0xFF; __checksum_begin-__checksum_end--checksum __checksum:4, Crc32:ir,0xFFFFFFFF ; __checksum_begin-__checksum_end--verbose $TARGET _path$ $TARGET _path$
... where these substrings is placeholders that needs to changed for the project in use:
__checksum |
The name of The symbol where the checksum value should be stored. Note that it must exist in the symbol table in the the input ELF file. |
__checksum_begin |
the first address on which the checksum should is calculated. |
__checksum_end |
the last address on which the checksum should is calculated . |
The preceding command line should is combined with all options reset (unchecked) in Project > Options > Linker & Gt Checksum
Projectoptionslinkerchecksum (6.40) (+ KB)
Projectoptionslinkerchecksum (6.10-6.30) (KB)
Example (6.40) ZIP, 654 KB)
Example (6.21) (ZIP, 645 KB)
Technical Note 11927
Checksum calculation with Ielftool after linking with ILINK
Calculate CRC32 as in STM32 hardware (Ewarm v.5.50 and later)