cancel
Showing results for 
Search instead for 
Did you mean: 

32- bit CRC Calculation of flash for STM32F070xB

Priyadarshini Solanki
Associate II
Posted on January 25, 2018 at 06:42

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-32
8 REPLIES 8
Posted on January 25, 2018 at 16:48

>>How I can ensure if the CRC calculation of my flash is correct.

Load the binary externally, and do the computation?

https://www.iar.com/support/tech-notes/general/calculate-crc32-as-in-stm32-hardware-v.5.50-and-later/

 

 

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

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 29, 2018 at 07:31

0690X00000609WfQAI.png

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.

Posted on January 29, 2018 at 18:19

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 30, 2018 at 04:12

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.

Posted on January 30, 2018 at 04:27

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 30, 2018 at 11:34

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

Posted on January 30, 2018 at 14:01

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

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 01, 2018 at 05:31

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.