2023-03-28 11:24 PM
Hey,
I went through the manual of the STM Programmer command line interface and implemented a post build CRC calc with the Safety lib command -sl.
C:\PROGRA~1\STMicroelectronics\STM32Cube\STM32CubeProgrammer\bin\STM32_Programmer_CLI.exe -sl MESOL_CAN_Gateway.elf 0x08000000 0x08100000 0x4000
In software then I ran a CRC calc with the standard settings of my STM32F767ZI, but unfortunately the values don´t agree. Does anybody know which polynomial the CLI uses or what I did wrong?
part of header file:
/* Public defines -----------------------------------------------------------*/
#define FLASH_BANK1_END 0x080FFFFF
#define PROG_FLASH_END 0x08007FFF // This might need to be extended if program grows, Remember to update AddCRC.bat
#define CRC_LOW_ADDR 0x080FFF00
#define CRC_HIGH_ADDR 0x080FFF04
#define CRC_SLICE_SIZE 0x4000
c file:
uint32_t CRCValueLow = 0x00000000;
uint32_t CRCValueHigh = 0x00000000;
uint32_t ExpectedCRCValueLow = 0x00000000;
uint32_t ExpectedCRCValueHigh = 0x00000000;
void CRCDiagnostics(void){
ExpectedCRCValueLow = *(uint32_t*)CRC_LOW_ADDR;
ExpectedCRCValueHigh = *(uint32_t*)CRC_HIGH_ADDR;
RCC->AHB1ENR |= RCC_AHB1ENR_CRCEN;
CRC->CR |= CRC_CR_RESET;
for(uint32_t *n = (uint32_t *)FLASH_BASE; n < (uint32_t *)(FLASH_BASE + CRC_SLICE_SIZE + 1); n ++)
{
CRC->DR = *n;
}
CRCValueLow = CRC->DR;
RCC->AHB1ENR |= RCC_AHB1ENR_CRCEN;
CRC->CR |= CRC_CR_RESET;
for(uint32_t *n = (uint32_t *)(FLASH_BASE + CRC_SLICE_SIZE + 1); n < (uint32_t *)(PROG_FLASH_END + 1); n ++)
{
CRC->DR = *n;
}
CRCValueHigh = CRC->DR;
return;
}
Thanks for the help!
Andre
2023-04-05 02:33 AM
Hello Andre,
This command in STM32CubeProgrammer is dedicated to user who use the safety library.
The CRC is calculate for areas devided in 1024 Bytes.
What is you use case, you want to compute a postbuild CRC?
If you are not doing safety tests I advise you to have a look to this article :
https://community.st.com/s/article/CRC-computation-in-STM32-MCUs-and-post-build-creation
Best Regards
2023-04-05 05:02 AM
From a software / online calculator perspective the words are done 32-bit at a time, the endian order is backward. The last bytes MSB is processed first.
2023-04-05 02:57 PM
Hey Chloe,
it´s a functional safety feature. I want verify that software is being installed corrected and not corrupted during runtime. Therefor I would like to compare an expected CRC (added to a separate flash area at build) with one calculated at boot.
Am I interpreting your answer correctly that the chunk size of 16 kB I chose is too big for the safety library?
Why is it an argument to the function if the size is fixed?
Best Regards
Andre
2023-04-05 05:07 PM
Probably because the math is more viable over smaller runs of the data, and perhaps that you can isolate the defective block, whilst still running code from ones with integrity.