Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,9 @@ jobs:
lfs: true

- name: Install ARM GCC Toolchain
shell: pwsh
run: |
# 下载并解压ARM GCC工具链(使用13.2版本以支持最新的ld脚本语法)
$url = "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-eabi.zip"
$output = "gcc-arm-none-eabi.zip"
Invoke-WebRequest -Uri $url -OutFile $output
Expand-Archive -Path $output -DestinationPath "C:\gcc-arm"

# 添加到PATH
$env:Path = "C:\gcc-arm\arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi\bin;" + $env:Path
echo "C:\gcc-arm\arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
uses: carlosperate/arm-none-eabi-gcc-action@v1
with:
release: '13.2.Rel1'

- name: Verify toolchain installation
shell: pwsh
Expand Down
80 changes: 18 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,108 +1,64 @@
cmake_minimum_required(VERSION 3.20)

# ==============================================================================
# 项目基本配置
# ==============================================================================
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# 设置工程名
set(CMAKE_PROJECT_NAME EK_DEMO)

project(${CMAKE_PROJECT_NAME})

# 允许使用的语言
enable_language(C CXX ASM)

# 默认生成 compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export compile commands" FORCE)

# Ninja 彩色输出支持
if("${CMAKE_GENERATOR}" MATCHES "Ninja")
message(STATUS "Build Generator is Ninja, forcing colored diagnostics.")
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-fdiagnostics-color=always>)
endif()

# ==============================================================================
# 全局宏定义 (Global Macros)
# ==============================================================================
# 使用 INTERFACE 库来管理全局宏,方便所有子层级继承
# 全局配置库
add_library(global_macros INTERFACE)

# 添加根目录作为 include 路径,使所有层级都能访问 ek_conf.h
target_include_directories(global_macros INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_include_directories(global_macros INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(global_macros INTERFACE
$<$<CONFIG:Debug>:DEBUG> # 仅在 Debug 模式下定义 DEBUG
$<$<CONFIG:Debug>:DEBUG>
$<$<CONFIG:Release>:NDEBUG>
# 在这里添加你的全局宏
)

# ==============================================================================
# 全局编译选项 (Global Compile Options)
# ==============================================================================
# 统一管理警告等级、优化等级、MCU架构参数
add_library(global_options INTERFACE)
target_compile_options(global_options INTERFACE
# 通用警告
-Wall
-Wextra

# C 标准与特性 (如果编译器支持)
-Wall -Wextra
$<$<COMPILE_LANGUAGE:C>:-std=c11>
$<$<COMPILE_LANGUAGE:CXX>:-std=c++17>

# 可以在这里添加 MCU 架构参数,或者在 Toolchain 文件中定义
# -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16

# 调试与优化
$<$<CONFIG:Debug>:-O0 -g3>
$<$<CONFIG:Release>:-O3>
)

# 统一输出目录配置
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# ==============================================================================
# 生成最终固件 (Executable)
# ==============================================================================
# 可执行文件
set(EMPTY_OBJ ${CMAKE_CURRENT_SOURCE_DIR}/ek_empty_obj.c)

add_executable(${CMAKE_PROJECT_NAME} ${EMPTY_OBJ})

# 设置输出文件名
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})

# ==============================================================================
# 添加子目录 (构建静态库)
# ==============================================================================
# 注意:在各层级的 CMakeLists.txt 中,记得链接 global_macros 和 global_options
add_subdirectory(L1_MCU) # 原 L0_MCU
add_subdirectory(L2_Core) # 包含 utils/ 和 hal/
add_subdirectory(L3_Middlewares) # FreeRTOS 等第三方中间件
# add_subdirectory(L4_Components)
add_subdirectory(L0_Assets)
add_subdirectory(L1_MCU)
add_subdirectory(L2_Core)
add_subdirectory(L3_Middlewares)
add_subdirectory(L4_Components)
add_subdirectory(L5_App)

# 链接所有层级生成的库
# 注意顺序:通常 顶层 依赖 底层,但链接器有时需要注意符号解析顺序。
# 如果使用 .a 静态库,建议将依赖方放在前面 (L5 依赖 L4...)
# 强制链接器解析 ek_main 符号(跨层调用 L1->L5)

Copilot AI Jan 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining why the --undefined flag is necessary for ek_main, as this is a non-standard linking requirement that forces symbol resolution across layers.

Suggested change
# 强制链接器解析 ek_main 符号(跨层调用 L1->L5)
# NOTE: Non-standard linking requirement.
# ek_main is implemented in a higher layer (e.g. L5) but is entered from lower layers (L1->L5),
# so the top-level executable does not directly reference ek_main. Without this flag the linker
# may discard the object file containing ek_main during garbage collection. We therefore force
# the linker to treat ek_main as an undefined symbol at link time so that it is resolved across
# layers and the correct entry point is retained.

Copilot uses AI. Check for mistakes.
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE "-Wl,--undefined=ek_main")

target_link_libraries(${CMAKE_PROJECT_NAME}
l5_app
# l4_components
l4_components
l3_middlewares
l2_core
l1_mcu
"-Wl,--whole-archive" l1_mcu "-Wl,--no-whole-archive" # 包含 syscalls
l0_assets

global_macros # 确保最终 ELF 也继承宏
global_options # 确保最终 ELF 也继承选项
global_macros
global_options
)

# ==============================================================================
# Post-Build: 生成 Hex/Bin/Size
# ==============================================================================
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}> ${CMAKE_PROJECT_NAME}.bin
Expand Down
11 changes: 11 additions & 0 deletions L0_Assets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
file(GLOB_RECURSE L0_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.c")

add_library(l0_assets STATIC ${L0_SRCS})

target_link_libraries(l0_assets PUBLIC
global_macros
global_options
)

target_include_directories(l0_assets PUBLIC inc)

94 changes: 94 additions & 0 deletions L0_Assets/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# L0_Assets (资源文件层)

## 1. 简介
L0_Assets 是本项目的资源文件层,用于存放与固件一起打包的资源数据。

向上:为各层提供资源数据访问接口。

本层主要用于存储不需要编译的静态资源,如:
- 图标、图片数据
- 字体文件
- 配置数据
- 其他二进制资源

## 2. 目录结构
```text
L0_Assets
├── CMakeLists.txt # 构建脚本
├── inc/ # 头文件目录(资源声明)
│ └── assets.h
└── src/ # 源文件目录(资源定义)
└── assets.c
```

## 3. 核心开发原则

**静态资源管理**:

本层主要存放编译到固件中的静态资源数据。

资源以 C 数组或 const 数据的形式提供,直接链接到最终固件。

**无依赖设计**:

本层不依赖任何其他层级(L1~L5),仅依赖 `global_macros` 和 `global_options`。

保持最底层的独立性,确保资源数据可被任何层访问。

## 4. 使用示例

### 添加图片资源

```c
// inc/logo.h
#ifndef LOGO_H
#define LOGO_H

#include <stdint.h>

// Logo 图片数据 (RGB565 格式)
extern const uint16_t logo_data[];
extern const uint32_t logo_width;
extern const uint32_t logo_height;

#endif
```

```c
// src/logo.c
#include "logo.h"

const uint16_t logo_data[] = {
0xFFFF, 0xFFFF, 0x0000, // ...
};

const uint32_t logo_width = 64;
const uint32_t logo_height = 64;
```

### 在上层使用资源

```c
// L5_App 或 L4 组件中使用
#include "assets.h"

void display_logo(void)
{
// 使用资源数据
lcd_draw_bitmap(0, 0, logo_width, logo_height, logo_data);
}
```

## 5. 常见问题

**Q: 为什么需要单独的资源层?**

A: 将资源数据集中管理,便于维护和复用。同时,资源数据可以作为独立模块被任何层访问,符合分层架构的设计理念。

**Q: 资源文件如何影响固件大小?**

A: 所有资源数据都会被链接到最终固件中,增加 FLASH 占用。建议使用压缩格式或优化资源大小。

**Q: 能否支持外部资源文件?**

A: 本层仅支持编译时嵌入的静态资源。如需运行时加载外部文件(如 SD 卡),应在 L4_Components 中实现文件系统驱动。
1 change: 1 addition & 0 deletions L0_Assets/src/assets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// 这个文件夹放置一些资源文件
15 changes: 2 additions & 13 deletions L1_MCU/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
add_library(l1_mcu STATIC)

target_link_libraries(l1_mcu PUBLIC
global_macros
global_options
)

target_link_libraries(l1_mcu PUBLIC l0_assets global_macros global_options)
target_include_directories(l1_mcu PUBLIC inc)

# 设置默认 MCU 型号,允许命令行 -DMCU_MODEL=xxx 覆盖
# 选择 MCU 型号
set(MCU_MODEL "STM32F429ZIT6_GCC" CACHE STRING "Select MCU Model")

message(STATUS "L1 Configuration: Integrating ${MCU_MODEL} into l1_mcu")

if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${MCU_MODEL}")
message(FATAL_ERROR "MCU directory not found: ${CMAKE_CURRENT_SOURCE_DIR}/${MCU_MODEL}")
endif()

# 添加 stub 源文件(提供 ek_main 的弱定义)
target_sources(l1_mcu PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/stub/ek_app_stub.c
)

# 进入子目录。注意:此时 l1_mcu 目标已经存在,子目录可以向其添加文件
add_subdirectory(${MCU_MODEL})
37 changes: 37 additions & 0 deletions L1_MCU/STM32F407VGT6_GCC/.mxproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[PreviousLibFiles]
LibFiles=Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dmamux.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.h;Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Drivers/CMSIS/Include/core_cm35p.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/pmu_armv8.h;Drivers/CMSIS/Include/cachel1_armv7.h;Drivers/CMSIS/Include/cmsis_armclang_ltm.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_cm55.h;Drivers/CMSIS/Include/tz_context.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/core_starmc1.h;Drivers/CMSIS/Include/core_cm85.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/pac_armv81.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/core_armv81mml.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/core_cm0plus.h;

[PreviousUsedCMakes]
SourceFiles=Core/Src/main.c;Core/Src/gpio.c;Core/Src/usart.c;Core/Src/stm32f4xx_it.c;Core/Src/stm32f4xx_hal_msp.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c;Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c;Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c;Core/Src/system_stm32f4xx.c;;;
HeaderPath=Drivers/STM32F4xx_HAL_Driver/Inc;Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;Drivers/CMSIS/Device/ST/STM32F4xx/Include;Drivers/CMSIS/Include;Middlewares/ST/ARM/DSP/Inc;Core/Inc;
CDefines=USE_HAL_DRIVER;STM32F407xx;USE_HAL_DRIVER;USE_HAL_DRIVER;

[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=5
HeaderFiles#0=../Core/Inc/gpio.h
HeaderFiles#1=../Core/Inc/usart.h
HeaderFiles#2=../Core/Inc/stm32f4xx_it.h
HeaderFiles#3=../Core/Inc/stm32f4xx_hal_conf.h
HeaderFiles#4=../Core/Inc/main.h
HeaderFolderListSize=1
HeaderPath#0=../Core/Inc
HeaderFiles=;
SourceFileListSize=5
SourceFiles#0=../Core/Src/gpio.c
SourceFiles#1=../Core/Src/usart.c
SourceFiles#2=../Core/Src/stm32f4xx_it.c
SourceFiles#3=../Core/Src/stm32f4xx_hal_msp.c
SourceFiles#4=../Core/Src/main.c
SourceFolderListSize=1
SourcePath#0=../Core/Src
SourceFiles=;

[ThirdPartyIp]
ThirdPartyIpNumber=1
ThirdPartyIpName#0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0

[ThirdPartyIp#STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0]
library=../Middlewares/ST/ARM/DSP/Lib/libarm_cortexM4lf_math.a;
header=../Middlewares/ST/ARM/DSP/Inc/arm_math.h;

55 changes: 55 additions & 0 deletions L1_MCU/STM32F407VGT6_GCC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# STM32 头文件路径
set(MX_Include_Dirs
${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc
${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32F4xx_HAL_Driver/Inc
${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Device/ST/STM32F4xx/Include
${CMAKE_CURRENT_SOURCE_DIR}/Drivers/CMSIS/Include
${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/ST/ARM/DSP/Inc
)

# 收集源文件
file(GLOB MX_Start_S ${CMAKE_CURRENT_SOURCE_DIR}/*.s)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Core/Src MX_Core_Src)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/Drivers/STM32F4xx_HAL_Driver/Src MX_Driver_Src)

# 创建 cubemx_hal OBJECT 库(不生成独立静态库,对象将被添加到 l1_mcu)
add_library(cubemx_hal OBJECT ${MX_Start_S} ${MX_Core_Src} ${MX_Driver_Src})

# ARM DSP 数学库 - 作为源文件添加
target_sources(cubemx_hal PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Middlewares/ST/ARM/DSP/Lib/libarm_cortexM4lf_math.a
)

# 头文件路径 - PUBLIC(传递给使用者)
target_include_directories(cubemx_hal PUBLIC
${MX_Include_Dirs}
)

# STM32 宏定义 - PUBLIC(传递给使用者)
target_compile_definitions(cubemx_hal PUBLIC
USE_HAL_DRIVER
STM32F407xx
$<$<CONFIG:Debug>:DEBUG>
)

# 链接全局配置
target_link_libraries(cubemx_hal PUBLIC
global_macros
global_options
)

# 将 cubemx_hal 的对象文件添加到 l1_mcu(整合到 l1_mcu 静态库中)
# 这样上层只需要链接 l1_mcu,不需要知道 cubemx_hal 的存在
target_sources(l1_mcu PRIVATE
$<TARGET_OBJECTS:cubemx_hal>
)

# 将 cubemx_hal 的头文件和宏定义传递给 l1_mcu 的使用者
target_include_directories(l1_mcu PUBLIC
$<TARGET_PROPERTY:cubemx_hal,INTERFACE_INCLUDE_DIRECTORIES>
)

target_compile_definitions(l1_mcu PUBLIC
$<TARGET_PROPERTY:cubemx_hal,INTERFACE_COMPILE_DEFINITIONS>
)
Loading