xref: /aosp_15_r20/external/pigweed/targets/stm32f429i_disc1_stm32cube/BUILD.bazel (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker# Copyright 2021 The Pigweed Authors
2*61c4878aSAndroid Build Coastguard Worker#
3*61c4878aSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4*61c4878aSAndroid Build Coastguard Worker# use this file except in compliance with the License. You may obtain a copy of
5*61c4878aSAndroid Build Coastguard Worker# the License at
6*61c4878aSAndroid Build Coastguard Worker#
7*61c4878aSAndroid Build Coastguard Worker#     https://www.apache.org/licenses/LICENSE-2.0
8*61c4878aSAndroid Build Coastguard Worker#
9*61c4878aSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
10*61c4878aSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11*61c4878aSAndroid Build Coastguard Worker# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12*61c4878aSAndroid Build Coastguard Worker# License for the specific language governing permissions and limitations under
13*61c4878aSAndroid Build Coastguard Worker# the License.
14*61c4878aSAndroid Build Coastguard Worker
15*61c4878aSAndroid Build Coastguard Workerload("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
16*61c4878aSAndroid Build Coastguard Workerload("//pw_build:compatibility.bzl", "incompatible_with_mcu")
17*61c4878aSAndroid Build Coastguard Workerload("//pw_build:merge_flags.bzl", "flags_from_dict")
18*61c4878aSAndroid Build Coastguard Workerload("//pw_build:pw_linker_script.bzl", "pw_linker_script")
19*61c4878aSAndroid Build Coastguard Workerload("//third_party/freertos:flags.bzl", "FREERTOS_FLAGS")
20*61c4878aSAndroid Build Coastguard Worker
21*61c4878aSAndroid Build Coastguard Workerpackage(default_visibility = ["//visibility:public"])
22*61c4878aSAndroid Build Coastguard Worker
23*61c4878aSAndroid Build Coastguard Workerlicenses(["notice"])
24*61c4878aSAndroid Build Coastguard Worker
25*61c4878aSAndroid Build Coastguard Workercc_library(
26*61c4878aSAndroid Build Coastguard Worker    name = "freertos_config",
27*61c4878aSAndroid Build Coastguard Worker    hdrs = [
28*61c4878aSAndroid Build Coastguard Worker        "config/FreeRTOSConfig.h",
29*61c4878aSAndroid Build Coastguard Worker    ],
30*61c4878aSAndroid Build Coastguard Worker    includes = ["config/"],
31*61c4878aSAndroid Build Coastguard Worker    target_compatible_with = [":freertos_config_cv"],
32*61c4878aSAndroid Build Coastguard Worker    deps = ["//third_party/freertos:config_assert"],
33*61c4878aSAndroid Build Coastguard Worker)
34*61c4878aSAndroid Build Coastguard Worker
35*61c4878aSAndroid Build Coastguard Worker# Constraint value corresponding to :freertos_config.
36*61c4878aSAndroid Build Coastguard Worker#
37*61c4878aSAndroid Build Coastguard Worker# If you include this in your platform definition, you will tell Bazel to use
38*61c4878aSAndroid Build Coastguard Worker# the :freertos_config defined above when compiling FreeRTOS.  (See
39*61c4878aSAndroid Build Coastguard Worker# //third_party/freertos/BUILD.bazel.) If you include it in a target's
40*61c4878aSAndroid Build Coastguard Worker# `target_compatible_with`, you will tell Bazel the target can only be built
41*61c4878aSAndroid Build Coastguard Worker# for platforms that specify this FreeRTOS config.
42*61c4878aSAndroid Build Coastguard Workerconstraint_value(
43*61c4878aSAndroid Build Coastguard Worker    name = "freertos_config_cv",
44*61c4878aSAndroid Build Coastguard Worker    constraint_setting = "@freertos//:freertos_config_setting",
45*61c4878aSAndroid Build Coastguard Worker)
46*61c4878aSAndroid Build Coastguard Worker
47*61c4878aSAndroid Build Coastguard Workerplatform(
48*61c4878aSAndroid Build Coastguard Worker    name = "platform",
49*61c4878aSAndroid Build Coastguard Worker    constraint_values = [
50*61c4878aSAndroid Build Coastguard Worker        ":freertos_config_cv",
51*61c4878aSAndroid Build Coastguard Worker        "//pw_build/constraints/rtos:freertos",
52*61c4878aSAndroid Build Coastguard Worker        "//pw_interrupt_cortex_m:backend",
53*61c4878aSAndroid Build Coastguard Worker        "//pw_malloc:bucket_block_allocator_backend",
54*61c4878aSAndroid Build Coastguard Worker        "@freertos//:port_ARM_CM4F",
55*61c4878aSAndroid Build Coastguard Worker        "@freertos//:disable_task_statics",
56*61c4878aSAndroid Build Coastguard Worker        "@platforms//cpu:armv7e-m",
57*61c4878aSAndroid Build Coastguard Worker        "@platforms//os:none",
58*61c4878aSAndroid Build Coastguard Worker        "@pw_toolchain//constraints/arm_mcpu:cortex-m4",
59*61c4878aSAndroid Build Coastguard Worker        "@rust_crates//:no_std",
60*61c4878aSAndroid Build Coastguard Worker    ],
61*61c4878aSAndroid Build Coastguard Worker    flags = flags_from_dict(FREERTOS_FLAGS | {
62*61c4878aSAndroid Build Coastguard Worker        "@cmsis_core//:cc_defines": ":cc_defines",
63*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_assert:check_backend": "//pw_assert_basic",
64*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_assert:check_backend_impl": "//pw_assert_basic:impl",
65*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_boot:backend": "//pw_boot_cortex_m",
66*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_log:backend": "//pw_log_tokenized",
67*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_log:backend_impl": "//pw_log_tokenized:impl",
68*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_log_tokenized:handler_backend": "//pw_system:log_backend",
69*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_malloc:backend": "//pw_malloc:bucket_block_allocator",
70*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_sys_io:backend": "//pw_sys_io_stm32cube",
71*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_system:extra_platform_libs": "//targets/stm32f429i_disc1_stm32cube:extra_platform_libs",
72*61c4878aSAndroid Build Coastguard Worker        "@pigweed//pw_unit_test:main": "//targets/stm32f429i_disc1_stm32cube:unit_test_app",
73*61c4878aSAndroid Build Coastguard Worker        "@stm32f4xx_hal_driver//:hal_config": "//targets/stm32f429i_disc1_stm32cube:hal_config",
74*61c4878aSAndroid Build Coastguard Worker    }),
75*61c4878aSAndroid Build Coastguard Worker)
76*61c4878aSAndroid Build Coastguard Worker
77*61c4878aSAndroid Build Coastguard Workercc_library(
78*61c4878aSAndroid Build Coastguard Worker    name = "cc_defines",
79*61c4878aSAndroid Build Coastguard Worker    defines = [
80*61c4878aSAndroid Build Coastguard Worker        "STM32CUBE_HEADER=\\\"stm32f4xx.h\\\"",
81*61c4878aSAndroid Build Coastguard Worker        "STM32F429xx",
82*61c4878aSAndroid Build Coastguard Worker    ],
83*61c4878aSAndroid Build Coastguard Worker)
84*61c4878aSAndroid Build Coastguard Worker
85*61c4878aSAndroid Build Coastguard Workercc_library(
86*61c4878aSAndroid Build Coastguard Worker    name = "hal_config",
87*61c4878aSAndroid Build Coastguard Worker    hdrs = [
88*61c4878aSAndroid Build Coastguard Worker        "config/stm32f4xx_hal_conf.h",
89*61c4878aSAndroid Build Coastguard Worker    ],
90*61c4878aSAndroid Build Coastguard Worker    includes = ["config"],
91*61c4878aSAndroid Build Coastguard Worker)
92*61c4878aSAndroid Build Coastguard Worker
93*61c4878aSAndroid Build Coastguard Workercc_library(
94*61c4878aSAndroid Build Coastguard Worker    name = "unit_test_app",
95*61c4878aSAndroid Build Coastguard Worker    testonly = True,
96*61c4878aSAndroid Build Coastguard Worker    srcs = [
97*61c4878aSAndroid Build Coastguard Worker        "unit_test_app.cc",
98*61c4878aSAndroid Build Coastguard Worker    ],
99*61c4878aSAndroid Build Coastguard Worker    deps = [
100*61c4878aSAndroid Build Coastguard Worker        "//pw_status",
101*61c4878aSAndroid Build Coastguard Worker        "//pw_system",
102*61c4878aSAndroid Build Coastguard Worker        "//pw_unit_test:rpc_service",
103*61c4878aSAndroid Build Coastguard Worker    ],
104*61c4878aSAndroid Build Coastguard Worker    alwayslink = 1,
105*61c4878aSAndroid Build Coastguard Worker)
106*61c4878aSAndroid Build Coastguard Worker
107*61c4878aSAndroid Build Coastguard Workercc_library(
108*61c4878aSAndroid Build Coastguard Worker    name = "pre_init",
109*61c4878aSAndroid Build Coastguard Worker    srcs = [
110*61c4878aSAndroid Build Coastguard Worker        "boot.cc",
111*61c4878aSAndroid Build Coastguard Worker        "vector_table.c",
112*61c4878aSAndroid Build Coastguard Worker    ],
113*61c4878aSAndroid Build Coastguard Worker    copts = ["-Wno-return-type"],
114*61c4878aSAndroid Build Coastguard Worker    defines = ["PW_MALLOC_ACTIVE=1"],
115*61c4878aSAndroid Build Coastguard Worker    target_compatible_with = [":freertos_config_cv"],
116*61c4878aSAndroid Build Coastguard Worker    deps = [
117*61c4878aSAndroid Build Coastguard Worker        ":freertos_config",
118*61c4878aSAndroid Build Coastguard Worker        "//pw_assert",
119*61c4878aSAndroid Build Coastguard Worker        "//pw_boot",
120*61c4878aSAndroid Build Coastguard Worker        "//pw_boot_cortex_m",
121*61c4878aSAndroid Build Coastguard Worker        "//pw_malloc",
122*61c4878aSAndroid Build Coastguard Worker        "//pw_preprocessor",
123*61c4878aSAndroid Build Coastguard Worker        "//pw_string",
124*61c4878aSAndroid Build Coastguard Worker        "//pw_sys_io_stm32cube",
125*61c4878aSAndroid Build Coastguard Worker        "//pw_system:init",
126*61c4878aSAndroid Build Coastguard Worker        "//third_party/freertos:support",
127*61c4878aSAndroid Build Coastguard Worker        "//third_party/stm32cube",
128*61c4878aSAndroid Build Coastguard Worker        "@freertos",
129*61c4878aSAndroid Build Coastguard Worker    ],
130*61c4878aSAndroid Build Coastguard Worker    alwayslink = 1,
131*61c4878aSAndroid Build Coastguard Worker)
132*61c4878aSAndroid Build Coastguard Worker
133*61c4878aSAndroid Build Coastguard Workercc_library(
134*61c4878aSAndroid Build Coastguard Worker    name = "extra_platform_libs",
135*61c4878aSAndroid Build Coastguard Worker    deps = [
136*61c4878aSAndroid Build Coastguard Worker        # The linker script for pw_boot_cortex_m.
137*61c4878aSAndroid Build Coastguard Worker        ":linker_script",
138*61c4878aSAndroid Build Coastguard Worker        # The initialization code.
139*61c4878aSAndroid Build Coastguard Worker        ":pre_init",
140*61c4878aSAndroid Build Coastguard Worker        # The linker script for pw_tokenizer.
141*61c4878aSAndroid Build Coastguard Worker        "//pw_tokenizer:linker_script",
142*61c4878aSAndroid Build Coastguard Worker        # Arm GCC support libraries.
143*61c4878aSAndroid Build Coastguard Worker        "//pw_toolchain/arm_gcc:arm_none_eabi_gcc_support",
144*61c4878aSAndroid Build Coastguard Worker    ],
145*61c4878aSAndroid Build Coastguard Worker)
146*61c4878aSAndroid Build Coastguard Worker
147*61c4878aSAndroid Build Coastguard Workerpw_linker_script(
148*61c4878aSAndroid Build Coastguard Worker    name = "linker_script",
149*61c4878aSAndroid Build Coastguard Worker    defines = [
150*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_FLASH_BEGIN=0x08000200",
151*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_FLASH_SIZE=2048K",
152*61c4878aSAndroid Build Coastguard Worker
153*61c4878aSAndroid Build Coastguard Worker        # TODO(b/235348465): Currently "pw_tokenizer/detokenize_test" requires
154*61c4878aSAndroid Build Coastguard Worker        # at least 6K bytes in heap when using pw_malloc:bucket_block_allocator.
155*61c4878aSAndroid Build Coastguard Worker        # The heap size required for tests should be investigated.
156*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_HEAP_SIZE=7K",
157*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_MIN_STACK_SIZE=1K",
158*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_RAM_BEGIN=0x20000000",
159*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_RAM_SIZE=192K",
160*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_VECTOR_TABLE_BEGIN=0x08000000",
161*61c4878aSAndroid Build Coastguard Worker        "PW_BOOT_VECTOR_TABLE_SIZE=512",
162*61c4878aSAndroid Build Coastguard Worker    ],
163*61c4878aSAndroid Build Coastguard Worker    linker_script = "//pw_boot_cortex_m:basic_cortex_m.ld",
164*61c4878aSAndroid Build Coastguard Worker)
165*61c4878aSAndroid Build Coastguard Worker
166*61c4878aSAndroid Build Coastguard Workersphinx_docs_library(
167*61c4878aSAndroid Build Coastguard Worker    name = "docs",
168*61c4878aSAndroid Build Coastguard Worker    srcs = [
169*61c4878aSAndroid Build Coastguard Worker        "target_docs.rst",
170*61c4878aSAndroid Build Coastguard Worker    ],
171*61c4878aSAndroid Build Coastguard Worker    target_compatible_with = incompatible_with_mcu(),
172*61c4878aSAndroid Build Coastguard Worker)
173