EEVblog® Electronics Community Forum

Electronics => Microcontrollers => Topic started by: hamdi.tn on January 21, 2016, 10:49:26 am

Title: STM32 CRC Flash
Post by: hamdi.tn on January 21, 2016, 10:49:26 am
Hi,

Am trying to add CRC32 in the end of the Flash memory of an STM32F101 using IAR tool. So far so good , IAR generate "a" CRC32 and write it in the end of memory.
I wrote a function that calculate CRC using integrated CRC hardware

Code: [Select]

#define MEM_START       0x08000000
#define MEM_END         0x0803FFF8
#define MEM_CRC         0x0803FFFC

uint32_t CheckFlashCRC()
{

CRC_ResetDR();
CRC_CalcBlockCRC((u32 *)MEM_START,((MEM_END-MEM_START)/4)+1);

return(*(u32 *)MEM_CRC));
}


The result of this routine is 0x784888AC
the IAR CRC is 0x60D8E753

and i couldn't make those two equal no matter what i change in IAR parameters , the previous values match the parameters in the picture.

Thanks

Title: Re: STM32 CRC Flash
Post by: hamdi.tn on January 21, 2016, 11:37:59 am
Problem solved, solution here for anyone that may need it
https://www.iar.com/support/tech-notes/general/calculate-crc32-as-in-stm32-hardware-v.5.50-and-later/ (https://www.iar.com/support/tech-notes/general/calculate-crc32-as-in-stm32-hardware-v.5.50-and-later/)
Title: Re: STM32 CRC Flash
Post by: dgtl on January 21, 2016, 11:02:03 pm
Alternatively, you can use the STM32's CRC unit to calculate the real ethernet crc32 with a little software workaround (they connected the bit order wrong). In some projects, the real crc32 calculation is needed too and then accelerating it is useful. See this c++ example here; with a little help you can de-obfuscate it back to C: https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F4%20CRC%20-%20Preload%20CRC-DR&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=2071#{295C81A5-7BF1-49F8-B25A-73D6FB23E2E1}