How can I compile two version of my code in IAR Embbedded Workbench

╄→гoц情女王★ 提交于 2019-12-25 11:57:10

问题


I have two version of code and I need to switch them as work need to compile each one while keeping two version on an IAR project. I find something like "compile switch" but I don't know how is it doing. Is there anyone tell me a keyword or an advice that can I search?


回答1:


You can use C preprocessor #define feature to toggle between code versions and use IAR EWARM project's Defined Symbols feature to enable a list of #defines in a specific header file (for example: defines.h) that will be included in all C files.

defines.h

#if defined(PROD_VERSION)

    #define SOFTWARE_VERSION_PRODUCT ("1.0-release")
    //...whetever specific #defines meant for the release version, for example...
    //#define ENABLE_RF_STUB
    #define USE_SERIAL_CTS_RTS

#elif defined(TEST_VERSION)

    #define SOFTWARE_VERSION_PRODUCT ("1.0-test")
    //...whetever specific #defines meant for the test version, for example...
    #define ENABLE_RF_STUB
    #define USE_SERIAL_CTS_RTS

#elif defined(DEBUG_VERSION)

    #define SOFTWARE_VERSION_PRODUCT ("1.0-debug")
    //...whetever specific #defines meant for the debug version, for example...
    #define ENABLE_RF_STUB
    //#define USE_SERIAL_CTS_RTS

#endif

in rf.c

#include "defines.h"

void rfInit(void)
{
#ifndef ENABLE_RF_STUB
    //init RF here
#endif
}

In serial.c

#include "defines.h"

CPU_BOOLEAN isCtsRts()
{
#ifdef USE_SERIAL_CTS_RTS
    return HAL_SERIAL.isCtsRts();
#else
    return DEF_TRUE; //bypass CtsRts check
#endif
}

In your project option > C/C++ Compiler > Preprocessor > Defined symbols: add PROD_VERSION if you want the release version, or add TEST_VERSION if you want the test version or add DEBUG_VERSION if you want the debug version.

You can only choose one of the three configurations above only as IAR will only compile one version via the project compilation. Unless you can create a batch build script to allow building all the three versions under different output files created with three different project setups.




回答2:


IAR has a configuration in toolbar Project > Edit_Configuration It makes you set version "switches" via set these tool and it is possible to set preprocessor command for each setup.



来源:https://stackoverflow.com/questions/46426871/how-can-i-compile-two-version-of-my-code-in-iar-embbedded-workbench

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!