Search code examples
stm32iarstm32cubemx

Customize Project path and name in STM32CubeMX


Consider a CubeMX project where you have configured the STM32F103 microcontroller and have chosen EWARM as the main IDE/Toolchain. When generating code, if you select the Application Structure to advance, you may encounter the following directory structure:

YourPrjName:
|--Core
|--Driver
|--EWARM
|CubePrj.ioc
|.mxproject

Now, let's say you want to place both the Core and Driver folders inside another folder named BSW, and generate the Cube project related files in a different location. The updated directory structure would look like this:

YourPrjName:
|--BSW
|  |__Core
|  |--Driver
|--EWARM
|--CubePrj
|  |--CubePrj.ioc
|  |--.mxproject

In this revised structure, the Core and Driver folders are located within the BSW folder, and the Cube project files placed under the CubePrj directory.

How this is possible?


Solution

  • STM32CubeMX might not give you the flexibility you need for you to customize your project tree layout. The only option offered for the Code Generator is "Generate peripheral initialization as a pair of '.c/.h' files per peripheral" and that is it.

    IAR provides a small utility named EWPtool which can not only (re)populate an existing project based on a folder selection with its sources but also can update references in the preprocessor paths to the header files accordingly.

    It is possible to use the utility from the command line with this parameter syntax:

    The GUI Error shows the parameter right order

    But for that you need to make sure you have the file EWARM\settings\YourPrjName.cfg with the following:

    <?xml version="1.0"?>
    <EWPtool>
      <selectedPath>$PROJ_DIR$\..\..</selectedPath>
    </EWPtool>
    

    And then, after moving folders around, you run EWPtool from the project's EWARM folder:

    EWPtool . YourPrjName YourPrjName
    

    Their official repository contains extra use case examples which might be useful.