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 @   IAmAProgrammer  阅读(907)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示