EWARM 6.40 STM32 CRC32

 1 uint32_t calcCrc32(uint8_t* data, uint32_t len)
 2 {
 3   uint32_t* pBuffer = (uint32_t*) data;
 4   uint32_t BufferLength = len/4;
 5   uint32_t index = 0;
 6   RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_CRC, ENABLE );
 7   CRC ->CR = CRC_CR_RESET;
 8   for(index = 0; index < BufferLength; index++)
 9     CRC->DR = pBuffer[index];
10   index = CRC->DR;
11   RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_CRC, DISABLE );
12   return index;
13 }
1   extern unsigned int __checksum;
2   if ( __checksum != calcCrc32( (unsigned char*)0x20000000 , 16 ) )
3     for ( ;; )
4       ;

"--fill" "0xFF;0x20000000-0x2000000f" "--checksum"  "__checksum:4,crc=0x4c11db7:Li,0xffffffff;0x20000000-0x2000000f" "--verbose"  "$TARGET_PATH$" "$TARGET_PATH$"

 

"--fill" "0xFF;0x20000000-0x2000000f" "--checksum" "__checksum:4,crc=0x4c11db7:ri,0xffffffff;0x20000000-0x2000000f" "--verbose" "$TARGET_PATH$" "$TARGET_PATH$"

 

两种选项, 相同结果

 

--checksum { symbol [+offset] | address }  :  size, algorithm[ : [1|2]  [m]  [L|W]  [r]  [i|p] ] [,start];  range   [;range...]

symbol : The name of the symbol where the checksum value should be stored. Note that it must exist in the symbol table in the input ELF file

offset : An offset to the symbol.

address :  The absolute address where the checksum value should be stored.

size : The number of bytes in the checksum: 1, 2, or 4; must not be larger than the size of the checksum symbol.

algorithm : The checksum algorithm used, one of :

    sum           a byte-wise calculated arithmetic sum. The result is truncated to 8 bits.
    sum8wide  a byte-wise calculated arithmetic sum. The result is truncated to the size of the symbol.
    sum32       a word-wise (32 bits) calculated arithmetic sum
    crc16        CRC16 (generating polynomial 0x11021); used by default
    crc32        CRC32 (generating polynomial 0x104C11DB7)
    crc=n       CRC with a generating polynomial of n

1|2 : If specified, can be one of: • 1 - Specifies one's complement.  • 2 - Specifies two's complement

m : Reverses the order of the bits within each byte when calculating the checksum.

L|W : Specifies the size of the unit for which a checksum should be calculated.
         Using these parameters does not add any additional error detection power to the checksum.
     Typically, this is useful to make the linker produce the same checksum as some hardware CRC implementations
         that calculate a checksum for more than 8 bits per iteration. Choose between: 

         L : calculates a checksum on 32 bits in every iteration
        W : calculates a checksum on 16 bits in every iteration.
        If you do not specify a unit size, 8 bits will be used by default.

r : Reverses the byte order of the input data within each word of size "size".

i|p : Use either i or p, if the start value is bigger than 0. If specified, can be one of:

       • i - Initializes the checksum value with the start value.
       • p - Prefixes the input data with a word of size "size" that contains the "start" value

start :  By default, the initial value of the checksum is 0x00000000 .
           If necessary, use start to supply a different initial value. If not 0x00000000, then either i or p must be specified

range :  The address range on which the checksum should be calculated. 
             Hexadecimal and decimal notation is allowed (for example, 0x8002–0x8FFF).

 

 

posted @ 2013-01-09 22:19  IAmAProgrammer  阅读(901)  评论(0编辑  收藏  举报