Do you maybe have a lot of projects named "main"? How about one source base that through conditional compilation could produce any one of six hex files? Maybe you just need to know exactly what version the hex file for a project is from? This article describes the technique to get specifically named hex files, different from the project name.
The fundamental principle is to use #export to define the name of the hex file. The simple syntax is:
#export(file="myproject.hex", hex)
You need to give it the filename and the format (hex). This alone can help a lot for many situations.
The next example shows how to include a version in the hex file name:
#define FW_VER_MAJOR 1
#define FW_VER_MINOR 14
#define strzz(x) #x
#define strz(x) strzz(x)
#export(file="myproject_" \
strz(FW_VER_MAJOR) "." strz(FW_VER_MINOR) ".hex" , hex)
The strz/strzz macros are used to convert the text define to a quoted string. In C, consecutive strings are appended together as if there was a single long string. The resulting filename for this example will be:
myproject_1.14.hex
Finally consider adding in the product name, that may be different based on conditional compilation. We will also show how to identify a release with diagnostics.
#if PRODUCT==PROD_WIZBANG
#define APP_NAME "WIZBANG" #elif PRODUCT==PROD_WIZBANG_PLUS
#define APP_NAME "WIZBANG_PLUS" #elif PRODUCT==PROD_SUPERBANG
#define APP_NAME "SUPER-BANG" #else
#error Unknown Product #endif
#ifdef DEBUG
#define HEX_TAIL "_diagnostic.hex" #else
#define HEX_TAIL ".hex" #endif
#export(file=APP_NAME "_" \
strz(FW_VER_MAJOR) "." strz(FW_VER_MINOR) HEX_TAIL, hex)
If you use the CCS IDE for development then the IDE will know the correct hex file name from the last build. Debugging and programming will work as expected.
Sometimes the filename is not enough. The compiler also allows you to put the same kind of information inside the hex file. For example:
#hexcomment\ APP_NAME _ FW_VER_MAJOR . FW_VER_MINOR
This can be done in addition to or instead of the custom hex filename. The directive puts a comment in the hex file that is ignored by the device programmer. The \ after hexcomment tells it to put the comment at the end of the file.
Without the \ the comment is put at the top of the file. The CCS device programmers will pop up any comments at the top of the file before programming. For example:
#hexcomment NOTICE: This file is only to be used for APP_NAME
This simple technique can be a powerful tool to properly identify your hex files.
Like us on Facebook. Follow us on Twitter.
About CCS:
CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit https://www.ccsinfo.com.
PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.
|