Files
stm32h7-libopencm3/2gpio-lib/xmake.lua
2025-12-29 19:10:44 +08:00

91 lines
2.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 工程名
set_project("stm32h7")
-- 定义工具链
toolchain("arm-none-eabi")
set_kind("standalone")
set_sdkdir("/home/time/doc/mybin/arm-none-eabi")
toolchain_end()
-- 使用自定义的 arm-none-eabi 工具链
set_toolchains("arm-none-eabi")
-- 设置平台与架构
set_plat("MCU")
set_arch("ARM Cortex-M7")
-- 编译优化与调试
set_optimize("none")
set_symbols("debug")
-- 全局架构 & FPU
add_cxflags("-mthumb", "-mcpu=cortex-m7", "-mfpu=fpv5-d16", "-mfloat-abi=hard", {force = true})
add_asflags("-mthumb", "-mcpu=cortex-m7", "-mfpu=fpv5-d16", "-mfloat-abi=hard", {force = true})
add_ldflags("-mthumb", "-mcpu=cortex-m7", "-mfpu=fpv5-d16", "-mfloat-abi=hard", {force = true})
-- 全局头文件路径 (libopencm3)
add_includedirs("../../libopencm3/include")
-- 全局链接 libopencm3
add_linkdirs("../../libopencm3/lib")
add_links("opencm3_stm32h7")
-- 全局额外链接选项
add_ldflags("-T./cortex-m-generic.ld", "--static", "-nostartfiles", "-Wl,--gc-sections", {force = true})
add_syslinks("c", "gcc", "nosys")
-- 全局宏定义
add_defines("STM32H7")
-- 全局用户头文件路径
add_includedirs("user/inc")
-- 目标程序
target("gpio-lib")
set_kind("binary")
add_files("user/src/*.c")
set_targetdir("$(projectdir)/bin")
add_deps("lib")
on_load(function (target)
target:set("filename", target:name() .. ".elf")
-- 生成 map 文件并带 cref显示 cross reference
target:add("ldflags",
"-Wl,-Map=" .. path.join(target:targetdir(), target:name() .. ".map") .. ",-cref",
{force = true}
)
end)
-- 生成额外文件
after_build(function (target)
local elf = target:targetfile()
local bindir = target:targetdir()
local name = target:name()
-- 常见格式
os.execv("arm-none-eabi-objcopy", {"-Obinary", elf, path.join(bindir, name .. ".bin")})
os.execv("arm-none-eabi-objcopy", {"-Oihex", elf, path.join(bindir, name .. ".hex")})
os.execv("arm-none-eabi-objcopy", {"-Osrec", elf, path.join(bindir, name .. ".srec")})
os.execv("arm-none-eabi-objdump", {"-S", elf}, {stdout = path.join(bindir, name .. ".list")})
-- 🔥 符号表 (对应 MDK Image Symbol Table)
os.execv("arm-none-eabi-nm", {"-n", elf}, {stdout = path.join(bindir, name .. ".sym")})
-- 🔥 段大小统计 (对应 MDK Image component sizes)
os.execv("arm-none-eabi-size", {"-B", elf}, {stdout = path.join(bindir, name .. ".size")})
end)
on_clean(function (target)
os.rm("build")
os.rm("bin")
end)
target("lib")
set_kind("phony")
add_deps("lib-ebtn")
target("lib-ebtn")
set_kind("static")
add_includedirs("lib/ebtn", {public = true})
add_files("lib/ebtn/*.c")