cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate CRC for large file in STM32F030RC

Treacy Yao
Associate II
Posted on February 03, 2018 at 07:45

I want to calculate CRC for large file, the large file have been added the CRC value in the end of the whole .bin file(Get this CRC data via IAR tool). I read the file and calculate CRC of it in part(HAL_CRC_Calculate(&CrcHandle,  (uint32_t *)data, len).  So I will get lots of crc data because I read it in part.

1. How can I deal with these crc data then the final crc vlue will be equal to the one calculated in the IAR?

2. Will it be any prolem if the last file part is not divided to 4 bytes(

Considered the Byte alignment

), then cause the final CRC data is not equal to the one calculated in the IAR? How to deal with this problem?
1 ACCEPTED SOLUTION

Accepted Solutions
straubm
Associate III
Posted on February 03, 2018 at 10:31

When doing CRC in parts, use HAL_CRC_Calculate(&CrcHandle,  (uint32_t *)data, len) for the first part and then HAL_CRC_Accumulate (CRC_HandleTypeDef * hcrc, uint32_t pBuffer, uint32_t BufferLength) for subsequent parts. The CRC returned by the respective .._Accumulate calls will reflect the accumulated CRC.

View solution in original post

6 REPLIES 6
straubm
Associate III
Posted on February 03, 2018 at 10:31

When doing CRC in parts, use HAL_CRC_Calculate(&CrcHandle,  (uint32_t *)data, len) for the first part and then HAL_CRC_Accumulate (CRC_HandleTypeDef * hcrc, uint32_t pBuffer, uint32_t BufferLength) for subsequent parts. The CRC returned by the respective .._Accumulate calls will reflect the accumulated CRC.

Posted on February 03, 2018 at 14:29

Do the computation in sections as needed.

The default 32-bit CRC in the STM32 parts really needs to work on aligned words. Where you lack natural alignment you should zero stuff.

There have been other threads were the application of the CRC in a 'PKZIP' type manner can be achieved, but it requires manipulation, and special handling of the odd bytes at the end. It would really require a better understanding of the math and data representation to get into a deep discussion about this.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on February 03, 2018 at 17:05

https://community.st.com/0D50X00009XkbNMSAZ

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on February 06, 2018 at 07:12

I want to use a fix part(8020000-

80200C8

) which can divided by 4 byte to do the crc, so I can avoid the odd bytes. I tried to modify the configurations in IAR. But it has errors when make. How shold I do?0690X00000609crQAA.png
Posted on February 06, 2018 at 07:23

0x8020000-0x80200C8 are 0xC9 bytes.

0x8020000-0x80200C7 are 0xC8 and hence dividable by 4
Alexander Kolpakov
Associate