跳转到主要内容

向STM32CubeMX工程中添加文件

生成工程的其它配置

STM32CubeMX允许通过.extSettings文件指定其它工程设置。 这些设置将在CubeMX代码生成之后应用于指定的项目。 .extSettings文件必须放在对应工程目录,并与.ioc文件在相同的层级中。

条目和语法

  • ProjectFiles 使用ProjectFiles部分中的字段来指定额外的Include目录。 语法:

    HeaderPath = <include directory 1 path>;< include directory 2 path >
  • Groups使用Groups部分中的字段创建新的文件组和/或向组中添加文件。 语法:

    <Group name> = <file pathname1>;< file pathname2>
  • Others使用Others部分中的字段启用HAL模块和/或指定预处理器定义语句。 语法:

    Define = <define1_name>;<define2_name>

示例

下面的示例为STM32H735G-DK工程指定了额外设置:

.extSettings file for STM32H735G-DK
[ProjectFiles]
HeaderPath=../Drivers/BSP/Components/Common;../Drivers/BSP/STM32H735G-DK
[Groups]
Drivers/BSP/STM32H735G-DK=../Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ospi.c;../Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ts.c;../Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_bus.c
Drivers/BSP/Components=../Drivers/BSP/Components/s70kl1281/s70kl1281.c;../Drivers/BSP/Components/mx25lm51245g/mx25lm51245g.c;../Drivers/BSP/Components/ft5336/ft5336.c;../Drivers/BSP/Components/ft5336/ft5336_reg.c
Application/User/TouchGFX/target=../TouchGFX/target/CortexMMCUInstrumentation.cpp
[Others]
Define=USE_STM32H735G_DK
HALModule=I2C

下面的示例为STM32H747I-DK工程指定了额外设置:

Tip
如果是多核心配置,用户必须指定应该为哪个核心添加文件或设置。
.extSettings file for STM32H747I-DISCO
[CortexM7:ProjectFiles]
HeaderPath=../Drivers/BSP/Components/Common;../Drivers/BSP/STM32H747I-Discovery
[CortexM7:Groups]
Application/User/CM7/TouchGFX/target=../CM7/TouchGFX/target/STM32H7Instrumentation.cpp
Drivers/BSP/Components=../Drivers/BSP/Components/otm8009a/otm8009a.c;../Drivers/BSP/Components/otm8009a/otm8009a_reg.c;../Drivers/BSP/Components/ft6x06/ft6x06.c;../Drivers/BSP/Components/ft6x06/ft6x06_reg.c;../Drivers/BSP/Components/mt25tl01g/mt25tl01g.c;../Drivers/BSP/Components/is42s32800j/is42s32800j.c
Drivers/BSP/STM32H747I-Discovery=../Drivers/BSP/STM32H747I-Discovery/stm32h747i_discovery_bus.c;../Drivers/BSP/STM32H747I-Discovery/stm32h747i_discovery_qspi.c;../Drivers/BSP/STM32H747I-Discovery/stm32h747i_discovery_sdram.c;../Drivers/BSP/STM32H747I-Discovery/stm32h747i_discovery_ts.c;
[CortexM7:Others]
Define=USE_STM32H747I_DISCO
HALModule=I2C

对生成项目的影响

在从CubeMX生成项目时,此.extSettings文件的存在会触发以下更新:

  • STM32CubeIDE文件夹中的IDE project.project文件
更新 `.project` 文件 (STM32CubeIDE IDE)
        <link>
<name>Drivers/BSP/Components/ft5336.c</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/Drivers/BSP/Components/ft5336/ft5336.c</locationURI>
</link>
<link>
<name>Drivers/BSP/Components/ft5336_reg.c</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/Drivers/BSP/Components/ft5336/ft5336_reg.c</locationURI>
</link>
<link>
<name>Drivers/BSP/Components/mx25lm51245g.c</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/Drivers/BSP/Components/mx25lm51245g/mx25lm51245g.c</locationURI>
</link>
<link>
<name>Drivers/BSP/Components/s70kl1281.c</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/Drivers/BSP/Components/s70kl1281/s70kl1281.c</locationURI>
</link>
<link>
<name>Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_bus.c</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_bus.c</locationURI>
</link>
<link>
<name>Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ospi.c</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ospi.c</locationURI>
</link>
<link>
<name>Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ts.c</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/Drivers/BSP/STM32H735G-DK/stm32h735g_discovery_ts.c</locationURI>
</link>
...
<link>
<name>Application/User/TouchGFX/target/CortexMMCUInstrumentation.cpp</name>
<type>1</type>
<locationURI>$%7BPARENT-1-PROJECT_LOC%7D/TouchGFX/target/CortexMMCUInstrumentation.cpp</locationURI>
</link>
  • 项目Inc(include)文件夹中的stm32h7xx_hal_conf.h文件,因为.extsettings文件中存在I2C模块。
更新 stm32h7xx_hal_conf.h 文件,使能 HAL 模块 (I2C)
/* #define HAL_PSSI_MODULE_ENABLED */
/* #define HAL_DTS_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_MDMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
/* #define HAL_HSEM_MODULE_ENABLED */
  • STM32CubeIDE用户界面中的项目视图,如下图中所示。

    加入到工程中的新增的BSP驱动组和文件

项目组中新增的MCU Instrumentation组和文件

Note
.extsettings文件引用的文件必须由用户手动添加到STM32CubeMX项目的文件夹中。

对于上面的STM32H735G-DK示例,文件cortexmmcuinstrumentment.cpp应该位于其指定的位置/TouchGFX/target/ cortexmmcuinstrumentment.cpp,

Further reading