1+ load ("@rules_cc//cc:defs.bzl" , "cc_binary" )
2+
3+ filegroup (
4+ name = "linker_script" ,
5+ srcs = ["stm32g474vetx_flash.ld" ],
6+ )
7+
8+ filegroup (
9+ name = "startup_file" ,
10+ srcs = ["startup_stm32g474xx.s" ],
11+ )
12+
13+ cc_binary (
14+ name = "vcu_firmware_2026" ,
15+ srcs = glob (
16+ [
17+ "Core/Src/**/*.c" ,
18+ "Drivers/*HAL_Driver/**/*.c" ,
19+ "Middlewares/**/*.c" ,
20+ "USB_DEVICE/**/*.c" ,
21+ "Core/Inc/**/*.h" ,
22+ "Drivers/**/*.h" ,
23+ "Middlewares/**/*.h" ,
24+ "USB_DEVICE/**/*.h" ,
25+ ],
26+
27+ allow_empty = True # allows empty globs, so the codebase can grow without refactoring
28+ ),
29+
30+ includes = [
31+ "Core/Inc" ,
32+ "Drivers/STM32G4xx_HAL_Driver/Inc" ,
33+ "Drivers/STM32G4xx_HAL_Driver/Inc/Legacy" ,
34+ "Drivers/CMSIS/Device/ST/STM32G4xx/Include" ,
35+ "Drivers/CMSIS/Include" ,
36+ "USB_DEVICE/App" ,
37+ "USB_DEVICE/Target" ,
38+ "Middlewares/ST/STM32_USB_Device_Library/Core/Inc" ,
39+ "Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc" ,
40+ "//longhorn-lib:longhorn_lib"
41+ ],
42+
43+ # Compiler options
44+ copts = [
45+ "-mcpu=cortex-m4" ,
46+ "-mthumb" ,
47+ "-mthumb-interwork" ,
48+ "-ffunction-sections" ,
49+ "-fdata-sections" ,
50+ ],
51+
52+ # Linker options
53+ linkopts = [
54+ "-T $(location :linker_script)" ,
55+ "$(location :startup_file)" ,
56+ "-Wl,-Map=output.map" ,
57+ "-Wl,--gc-sections" ,
58+ "-Wl,--no-warn-rwx-segments" ,
59+ ],
60+
61+ # Defines for the C preprocessor
62+ defines = [
63+ "DEBUG" ,
64+ "USE_HAL_DRIVER" ,
65+ "STM32G474xx" ,
66+ ],
67+
68+ additional_linker_inputs = [
69+ ":linker_script" ,
70+ ":startup_file" ,
71+ ],
72+
73+ # Target platform constraints
74+ target_compatible_with = [
75+ "@platforms//cpu:arm" ,
76+ "@platforms//os:none" ,
77+ ],
78+
79+ visibility = ["//visibility:public" ],
80+ )
81+
82+ genrule (
83+ name = "bin" ,
84+ srcs = [":vcu_firmware_2026" ],
85+ outs = ["vcu_firmware_2026.bin" ],
86+ cmd = "$(execpath @arm_none_eabi//:objcopy) -O binary $< $@" ,
87+ cmd_bat = "copy \" $(location @arm_none_eabi//:objcopy)\" objcopy.exe && objcopy.exe -O binary $< $@" ,
88+ tools = ["@arm_none_eabi//:objcopy" ],
89+ )
90+
91+ genrule (
92+ name = "hex" ,
93+ srcs = [":vcu_firmware_2026" ],
94+ outs = ["vcu_firmware_2026.hex" ],
95+ cmd = "$(execpath @arm_none_eabi//:objcopy) -O ihex $< $@" ,
96+ cmd_bat = "copy \" $(location @arm_none_eabi//:objcopy)\" objcopy.exe && objcopy.exe -O ihex $< $@" ,
97+ tools = ["@arm_none_eabi//:objcopy" ],
98+ )
0 commit comments