Hello everyone, I am a ruffian balance, is a serious technical ruffian. Today ruffian balance to share with you is to open the CRC integrity check IAR project generated. Out and. Bin file sequence problems.

Ruffian heng wrote an article “Method of enabling CRC integrity check function for projects under IAR Development environment” before, some colleagues encountered problems about the generation sequence of. Out /. Bin files when using CRC check function. When we debug the IAR project online, the debugger actually downloads the executable file (.out), there is no any error in the.out file, but most of the time we use the image file (.bin) to download the CRC, sometimes the CRC is not enabled in the.bin file, why is this? Rascal balance for you to solve your doubts:

First, use IAR to generate image files

For a normal embedded project, for example, \ sdk_2.8.2_frdM-k64f \boards\ FRDMk64f \demo_apps\hello_world\iar\, This project will generate.out executables (essentially standard.elf files) when the link is properly compiled. If we want to generate a.bin image file at the same time, we need to use the project option Output Converter:

In Output Converter, you can specify the image file format to be generated. Common image formats (.bin/ HEX /.s19) are supported. If you know about IAR you should know that this function is actually implemented by calling the \IAR Systems\Embedded Workbench 8.50.6\ ARM \bin\ ielfTool.exe tool:

ielftool --bin sourceFile.out destinationFile.bin
ielftool --ihex sourceFile.out destinationFile.hex
ielftool --srec sourceFile.out destinationFile.s19
Copy the code

Compile the project we see the compilation of information, from the point of log output sequence, first created the hello_world. Out (marked blue box), and then call the ielftool tools to perform the conversion command (marked green box), and finally generates the hello_world. Bin (marked red box) :

2. Compare the two CRC check enabling methods

Methods of enabling CRC integrity check for Projects in IAR Development Environment are introduced in this paper. Two methods of enabling CRC integrity check are introduced. We analyze the results from the perspective of the order of generating.out/.bin files:

2.1 Based on Checksum function

If the Checksum function is enabled, the log output sequence is as follows:

1. Call ielfTool to add CRC (blue box) 2. Generate. Out file with correct CRC check value (green box) 3. Call ielfTool for file format conversion (red box) 4. Generated.bin file with correct CRC values (yellow box)Copy the code

In this case, although the.out and.bin files are generated in different order, they both contain the correct CRC check values and are therefore consistent in their use of CRC verification.

2.2 Based on post-build function

If the post-build function is enabled, the log output sequence is as follows:

The. Out file (blue box) that generates the default CRC check value 2. Call ielfTool for file format conversion (green box) 3. A. Bin file containing the default CRC value is generated (red box) 4. Call ielfTool to add CRC (yellow box) 5. Generated.out file with correct CRC check values (purple box)Copy the code

In this case,.out files and.bin files are generated in different order, but.bin only has default CRC checks (all zeros), not the correct CRC checks expected, so it cannot be used for subsequent CRC verification. This is also a problem encountered by my colleague.

Bin /.out consistency in post-build

Now let’s solve the problem that my colleague encountered in the post-build. Bin and. Out CRC check value inconsistency, obviously cannot directly use the project option Output Converter function, because it can not change the execution order in the IAR.

We need to write an additional post-build.bat script as follows to implement CRC verification and file format conversion in the BAT script, so that we can control the file generation order.

set OUT=%1.out
set BIN=%1.bin

ielftool --fill="0xFF; __checksum_begin-__checksum_end" --checksum="__checksum:4,crc32:p,0xffffffff; __checksum_begin-__checksum_end" --verbose %OUT% %OUT%

ielftool --bin --verbose %OUT% %BIN%
Copy the code

Bat to the same path as the project file, and re-use the post-build script to execute the script with the parameter $TARGET_BPATH$, i.e. the full path without the project object file suffix. After compiling the project again, you can get the.bin file containing the correct CRC values.

Note: The post-build.bat script can be executed only when the ielftool path is in the system environment variable.

At this point, open the CRC integrity check IAR project generated. Out and. Bin file sequence problem ruffian balance will be introduced to the end, applause where ~~~

Welcome to subscribe to

The article will be published on my blog park homepage, CSDN homepage, Zhihu homepage and wechat public account at the same time.

Wechat search “ruffian balance embedded” or scan the following two-dimensional code, you can see the first time on the phone oh.