cancel
Showing results for 
Search instead for 
Did you mean: 

CRC Calculation on STM32L072CZ

Deepu joy
Associate II

Hey STM32 Community, I'm currently working on a project involving the STM32L072CZ microcontroller and could use some guidance on CRC calculation procedures. Here's a rundown of what I'm trying to accomplish: I'm downloading a FOTA .bin file in 1024-byte chunks, totaling 60kb. These chunks are stored in a data buffer, and my task is to calculate the CRC of the entire file for verification purposes. Here's the approach I've taken so far:

  1. For each incoming chunk of data, I'm accumulating its CRC using the function: chunkDataCrcValue = HAL_CRC_Accumulate(&hcrc, (uint32_t*)dataBuffer, BUFFER_SIZE);
  1. Once all data chunks are downloaded and their CRCs accumulated, I calculate the final CRC using: uint32_t finalCrcValue = hcrc.Instance->DR;

I'm seeking confirmation on whether this procedure is correct. Additionally, I need to determine the correct CRC (expected CRC) of the .bin file to ensure file integrity. I've kept default settings for both polynomial and initial values, and the CRC used is CRC 32. I've tried using J-Flash to generate the CRC of the .bin file, but the results don't match those obtained using the HAL function in STM32 Cube IDE. I'm not sure if J-Flash uses the same polynomial as the default polynomial set in STM32 Cube IDE. Any insights or recommendations you can provide would be greatly appreciated. If there are alternative applications or methodologies available for generating the CRC of the file, I'm all ears. Looking forward to your responses!

1 REPLY 1
TDK
Guru

> I'm seeking confirmation on whether this procedure is correct.

Confirmed, procedure is correct.

> Any insights or recommendations you can provide would be greatly appreciated.

First perform a CRC on a few bytes, say 4 bytes, and ensure the value matches your expectations based on online CRC calculators. Note that 32-bit values are stored in little endian format, so bytes may need swapped depending on what calculation you're expecting. If you don't care about how it calculates, only that it gets a CRC, this is less important.

> I'm not sure if J-Flash uses the same polynomial as the default polynomial set in STM32 Cube IDE.

Also not sure. Surely J-Flash documentation has this written down.

If you feel a post has answered your question, please click "Accept as Solution".