跳轉到主要內容

在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模組。
更新stm32f4xx_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 Drivers組和檔案

專案組中新增的MCU Instrumentation組和檔案

Note
.extsettings檔案引用的檔必須由用戶手動添加到STM32CubeMX專案的資料夾中。

對於上面的STM32H735G-DK範例,文件cortexmmcuinstrumentment.cpp應該位於其指定的位置/TouchGFX/target/ cortexmmcuinstrumentment.cpp中,

Further reading