2011-10-20 10:54 AM
I have set CRC in IAR builds, can;t find out how to do it in Keil builds
Erik2011-10-21 07:44 AM
I have set CRC in IAR builds, can;t find out how to do it in Keil builds
Not sure I've encountered a method as simple as IAR's, but Keil offers the ability to run external applications pre/post compile/link that can be used to automate such things.2011-10-24 12:45 AM
We use the feature ''run external program'' in Keil: Project Properties, Tab ''User''.
The checksum is calculated by the srecord tools (http://srecord.sf.net) and added to both hex file and axf file. The axf file is a little tricky, you need to find the correct offset in the axf file to put the checksum. Since our checksum is at address 0x8000000 (replacing the reset stack pointer) this was fairly simple. An example batch file for using srecord tools to put the checksum in an intel hex file at address 0x8000000 is: rem set some defaults: rem srecord tools are in ''tools'' subdirectory of current Keil project set srec_''cat=tools\srec_cat.exe'' rem objectdir-Path is where the hex-file is stored (relative to project dir) set objdir=''obj'' rem Filename of Hex File set Hex_File=''h200ng.hex'' rem Start adress in FLASH set /a start=0x08000000 rem Offset in FLASH (if you want CRC not at the beginning, but elsewhere set /a _CRC_Chksum_Address_Offset = start set /a _CRC16_Chksum_Address_End = _CRC_Chksum_Address_Offset + 0x2 set /a _CRC_Chksum_Address_End = _CRC_Chksum_Address_Offset + 0x4 :::::::::::::::::::::::::::::::::::::::::::::::: rem calculate CRC of Intel Hex File and save in file :::::::::::::::::::::::::::::::::::::::::::::::: %srec_cat% %objdir%/%Hex_File% -Intel -Exclude %_CRC_Chksum_Address_Offset% %_CRC_Chksum_Address_End% -Little_Endian_CRC16 %_CRC_Chksum_Address_Offset% -broken -Fill 0x00 %_CRC16_Chksum_Address_End% %_CRC_Chksum_Address_End% -o %objdir%/%Hex_File% -Intel -Line_Length 43 rem ''Exclude'': remove area where CRC is stored from hex file rem -Little_Endian_CRC16: Calculate and store checksum rem -Fill: CRC-16 is only 2 Bytes, thus fill the rest with zero ===================Admittedly this looks a bit convoluted at first, but the srecord tools are a very powerful set of tools to convert and modify hex files as well as binary files
Definitely worth learning. They replaced a plethora of home-grown tools here. jens2011-10-24 06:07 AM
Nice, but
the STM32 generates 32-buit CRC, why not use it2011-10-24 06:48 AM
Nice, but the STM32 generates 32-buit CRC, why not use it.
Probably because it's not a byte orientated solution. I have tools that could do this if there is general interest that could output a hex or binary file from ELF/AXF.
2011-10-24 06:48 AM
the question was how to put the CRC in the Hex-File.
This could be used e.g. to check the contents of the Flash after every Reset. Of course it makes sense to put a CRC in the hex-file which uses the same CRC-algortihm ST built into the STM32. We decided to use a CRC-16 for ''historical reasons'', though. The above is just an example, ready for further improvement ;) jens2011-10-24 07:07 AM
I think Erik is coming from the tangent that IAR's solution is better integrated, and very flexible.
Problem is everyone tends to have there own solution too this, or a cross platform method, and this is compounded by ST's choice of a backassward CRC implementation given the bit/byte endian model of the M3. Doing it in Hex files is particularly problematic as they can be sparse, and do you put the CRC at the end of the object data, or at the end of the ROM. Which means you need to consider the fill pattern, and ROM size.2011-10-24 07:19 AM
I think Erik is coming from the tangent that IAR's solution is better integrated, and very flexible.
I do not know about flexible, but after at my previous contract implementing CRC with IAR, I was surprised that Keil did not have it. Yes, I have implemented ''after the link'' functions in builds beforeST's choice of a backassward CRC implementation given the bit/byte endian model of the M3.
just curious, what is ''backassward ''Doing it in Hex files is particularly problematic as they can be sparse, and do you put the CRC at the end of the object data, or at the end of the ROM. Which means you need to consider the fill pattern, and ROM size.
anything but @ end of ROM can be problematic. I do not remember what the 'experience' was, but I remember it. Erik
2011-10-24 07:48 AM
just curious, what is ''backassward''
http://en.wiktionary.org/wiki/backasswards#English
It's one of a number of spellings to describe a design that was implemented completely the wrong way around. ie goes backward when you want to go forward. Fred installed the rear-differential backassward, and now the car will run backward in forward gears.2011-10-24 09:51 AM
sorry, should l;earn to be more concise
just curious, what is ''backassward '' about the ST CRC implementation?