Skip to content

Commit 739a630

Browse files
authored
Merge pull request #11 from LonghornRacingElectric/toolchain-fixes
Super cool fixes to toolchain should work on windows
2 parents 5d85a53 + 978456e commit 739a630

4 files changed

Lines changed: 68 additions & 41 deletions

File tree

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ arm_toolchain = use_extension("@toolchains_arm_gnu//:extensions.bzl", "arm_toolc
1212

1313
arm_toolchain.arm_none_eabi(version = "13.2.1")
1414
use_repo(arm_toolchain, "arm_none_eabi")
15-
# register_toolchains("@arm_none_eabi//toolchain:all")
16-
register_toolchains("//toolchain:all")
15+
register_toolchains("@arm_none_eabi//toolchain:all")
16+
# register_toolchains("//toolchain:all")
1717

1818
bazel_dep(name = "rules_python", version = "1.5.3")
1919

VCU/BUILD

Whitespace-only changes.

VCU/firmware/BUILD.bazel

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,14 @@
1-
load("@rules_cc//cc:defs.bzl", "cc_binary")
2-
load("//:tools/outputs/build_outputs.bzl", "binary_out", "hex_out")
1+
load("//:tools/outputs/build_outputs.bzl", "binary_out", "hex_out", "firmware_project")
32

4-
cc_binary(
3+
firmware_project(
54
name = "vcu_firmware_2026",
6-
srcs = glob([
7-
"Core/Src/**/*.c",
8-
"Core/Inc/**/*.h",
9-
], allow_empty = True)
10-
+ [
11-
# Include the HAL for compilation
12-
"//drivers/stm32g4:hal_srcs",
13-
],
14-
15-
includes = [
16-
"Core/Inc",
17-
],
18-
19-
deps = [
20-
"//drivers/stm32g4:stm32_headers",
21-
],
22-
23-
# Linker options, also includes the reset handler startup file
24-
linkopts = [
25-
"-T $(location //toolchain:stm32g474vetx_flash_script)",
26-
"$(location //toolchain:stm32g474_startup)",
27-
],
28-
5+
linker_script = "//toolchain:stm32g474vetx_flash_script",
6+
startup_script = "//toolchain:stm32g474_startup",
297
defines = [
308
"DEBUG",
319
"USE_HAL_DRIVER",
3210
"STM32G474xx",
3311
],
34-
35-
additional_linker_inputs = [
36-
"//toolchain:stm32g474vetx_flash_script",
37-
"//toolchain:stm32g474_startup",
38-
],
39-
40-
target_compatible_with = [
41-
"@platforms//cpu:arm",
42-
"@platforms//os:none",
43-
],
44-
45-
visibility = ["//visibility:public"],
4612
)
4713

4814
binary_out(

tools/outputs/build_outputs.bzl

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Macro for creating binary and hex files using objcopy."""
22

3+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
4+
35
def binary_out(name, src, visibility = None, **kwargs):
46
"""
57
Runs objcopy to convert a source file (e.g., an ELF) into a raw binary.
@@ -40,4 +42,63 @@ def hex_out(name, src, visibility = None, **kwargs):
4042
tools = ["@arm_none_eabi//:objcopy"],
4143
visibility = visibility,
4244
**kwargs
43-
)
45+
)
46+
47+
MCU_FLAGS = [
48+
"-mcpu=cortex-m4",
49+
"-mthumb",
50+
"-mfpu=fpv4-sp-d16",
51+
"-mfloat-abi=hard",
52+
]
53+
54+
def firmware_project(name, linker_script, startup_script, defines = [], extra_srcs = [], **kwargs):
55+
cc_binary(
56+
name = name,
57+
srcs = native.glob([
58+
"Core/Src/**/*.c",
59+
"Core/Inc/**/*.h",
60+
], allow_empty = True)
61+
+ [
62+
# Include the HAL for compilation
63+
"//drivers/stm32g4:hal_srcs",
64+
] + extra_srcs,
65+
66+
includes = [
67+
"Core/Inc",
68+
],
69+
70+
deps = [
71+
"//drivers/stm32g4:stm32_headers",
72+
],
73+
74+
# Linker options, also includes the reset handler startup file
75+
linkopts = MCU_FLAGS + [
76+
"-Wl,-Map=output.map",
77+
"-Wl,--gc-sections",
78+
"-Wl,--no-warn-rwx-segments",
79+
"-T $(location " + linker_script +")",
80+
"$(location " + startup_script +")",
81+
],
82+
83+
defines = defines,
84+
85+
additional_linker_inputs = [
86+
linker_script,
87+
startup_script,
88+
],
89+
90+
target_compatible_with = [
91+
"@platforms//cpu:arm",
92+
"@platforms//os:none",
93+
],
94+
95+
copts = MCU_FLAGS + [
96+
"-mthumb-interwork",
97+
"-ffunction-sections",
98+
"-fdata-sections",
99+
],
100+
101+
visibility = ["//visibility:public"],
102+
103+
**kwargs
104+
)

0 commit comments

Comments
 (0)