2018-01-24 09:42 PM
I am using
♯
, where I tried to calculate the 32- bit CRC of my flash using♯
register.How I can ensure if the CRC calculation of my flash is correct.
CRC Configuration I used is :
hcrc.Instance = CRC;
hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_WORDS;/*ROM address*/
&sharpdefine ROM_START (( uint32_t * ) 0x08000000 )
&sharpdefine ROM_END (( uint32_t * ) 0x0801FFFB )Calculated CRC is stored in the variable.
#flash #crc #stm32f070xb #crc->dr #crc-322018-01-25 07:48 AM
>>How I can ensure if the CRC calculation of my flash is correct.
Load the binary externally, and do the computation?
https://community.st.com/0D50X00009XkWntSAF
2018-01-28 11:31 PM
ROM_END = 0x08000000
ROM_START = 0x0801FFFB
ROM_SIZE = ROM_END -ROM_START
FLASH_WORD_SIZE = 4
CRC_Calculate(&hcrc, (uint32_*)
pBuffer[index]
,uint32_t BufferLength){uint32_t index = 0U;
uint32_t temp = 0U;CRC_DR_RESET(hcrc);
for(index = 0U; index <
ROM_SIZE / FLASH_WORD_SIZE
; index++){ hcrc->Instance->DR = pBuffer[index]; }temp = hcrc->Instance->DR;
}
void main(void){
.....
uint32_t currentRomDataCrc;
currentRomDataCrc = CRC_Calculate(&hcrc,
0x08000000,(uint32_t)( ROM_SIZE / FLASH_WORD_SIZE));
if (currentRomDataCrc == __checksum)
{
//TODO
}
else
{
//TODO
}
}
RESULT:
currentRomDataCrc =
0x3BE8893E //Location: 0x200001B8__checksum = 0x49354A9E //Location: 0x08003578
I am not getting the same result in calculated CRC and __checksum.
2018-01-29 10:19 AM
So make sure it is going over exactly the same words. Check the computation externally with your own code reading the binary. I could check it but you'd need to provide the binary for me to inspect.
The size should be computed like this
ROM_SIZE = ((ROM_END - ROM_START) + 1) // The way you describe the start/end points describes N-1 rather than N bytes
If you CRC the 0x20000/4 words the residual should by ZERO, at 0x1FFFC/4 words the CRC computed by both sides should match the word at 0x0801FFFC
I'm not using IAR.
I'm open to reasonable offers for my time to work on this.
2018-01-29 08:12 PM
Actual ROM Start is 0x08000000
ROM End = 0x0801FFFF
as ROM Size = ROM_End - ROM_Start is not completly divisible by 4.
So, I assigned ROM_End as 0x0801FFFC.
So what is your suggestion, I should assign ROM_End as
0x0801FFFC or 0x0801FFFF
after assigning ROM_End.
ROM_Size should calculate as, (ROM_End - ROM_Start) + 1 ?
My Flash Size is 128K.
2018-01-29 08:27 PM
Use your head. The IAR parameters seem to specify an inclusive range, ie bytes from 0x08000000 to 0x0801FFFB, a total of 0x1FFFC bytes or 0x7FFF 32-bit words.
A 32-bit word at 0x0801FFFC (0x0801FFFC..0x0801FFFF) contains the computed 32-bit CRC value.
Of the STM32 you must do a computation that takes 0x7FFF words and pushed the through the CRC.
If you do 0x7FFE words you'll get a different number, which obviously won't match.
If you push 0x8000 word through the CRC i'd expect to see a zero drop out the end and the values cleanly divide into the polynomial.
2018-01-30 03:34 AM
Thanks for pointing the mistake. I didn't realize that 0x00 to 0x0B is actually 0x0C bytes. I made specific changes but still, I am in the same position with a different result.
&sharpdefine ROM_START (( uint32_t * ) 0x08000000 )
&sharpdefine ROM_END (( uint32_t * ) 0x0801FFFB )&sharpdefine ROM_SIZE ( uint32_t ) (( ROM_END - ROM_START )+1)
FLASH_WORD_SIZE = 4
CRC_Calculate(&hcrc, (uint32_*)
pBuffer[index]
,uint32_t BufferLength){uint32_t index = 0U;
uint32_t temp = 0U;CRC_DR_RESET(hcrc);
for(index = 0U; index <
ROM_SIZE / FLASH_WORD_SIZE
; index++){ hcrc->Instance->DR = pBuffer[index];/*
for CRC_INPUTDATA_FORMAT_WORDS
BufferLength is calculating as 32767
*/
}temp = hcrc->Instance->DR;
}
void main(void){
.....
uint32_t currentRomDataCrc;
currentRomDataCrc = HAL_CRC_Calculate(&hcrc,
0x08000000
,(uint32_t)ROM_SIZE
);if (currentRomDataCrc == __checksum)
{
//TODO
}
else
{
//TODO
}
}
RESULT:
currentRomDataCrc = 0x3ADE5652
//Location: 0x200001B8__checksum = 0xE017B1E8 //Location: 0x08003578
2018-01-30 06:01 AM
Not sure how __checksum can be located in the middle of the firmware. The variable should presumably be placed at 0x0801FFFC so it is outside the scope of the computation.
Very hard to debug via keyhole, I'd need to see a binary to understand what you've created in IAR
2018-01-31 09:31 PM
Thanks for your support.
__checksum should be located at
0x0801FFFC, My linker was not placing it at end of my ROM.
I have added below line at the end of *.icf file
place at end of ROM_region { ro section .checksum };
I am getting the accurate result I required.