Search code examples
cembeddedkeiliarstm32cubemx

how solve problem on download and debug using IAR?


whenever I generate my code with STM32cubeMX on Iar embedded workbench V8.5 this error is still present

Fatal Error [Pe035]: #error directive: "Unknown target." 

enter image description here


Solution

  • The error is unrelated to either downloading or debugging. It is a build error.

    The #error is a pre-processor directive in the code. If you double-click on one of those errors it will no doubt take you to the offending code. It is not possible from the image to direct you to the exact cause (you should post the "build Log" text in its entirety, rather then an image of the "build" tab), but will no doubt be code similar to (elided):

    #if defined(STM32F405xx)
      #include "stm32f405xx.h"
    #elif defined(STM32F415xx)
      #include "stm32f415xx.h"
    #elif 
        ...  
    #elif defined(STM32F423xx)
      #include "stm32f423xx.h"
    #else
     #error "Unknown Target"   <<<< HERE - no target macro has been defined.
    #endif
    

    The point being that the HAL code supports multiple STM32 variants and it is necessary to set a macro identifying your target so that the appropriate part specific code will be built.

    If you created your project using STM32CubeMX or from the IAR IDE, there will be some place in the configuration where you can specify your target. (in the case of CubeMX I don't think you can do much of anything until you have selected the target). Failing that there will be some place to define command-line build macros in the build configuration.