• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15load("@rules_cc//cc:cc_library.bzl", "cc_library")
16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
17load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
18load("//pw_build:merge_flags.bzl", "flags_from_dict")
19load("//pw_build:pw_cc_binary.bzl", "pw_cc_binary")
20load("//pw_build:pw_copy_and_patch_file.bzl", "pw_copy_and_patch_file")
21load("//pw_toolchain/cc/current_toolchain:conditions.bzl", "if_compiler_is_clang")
22load("//targets/rp2040:flash.bzl", "flash_rp2040", "flash_rp2350")
23load("//targets/rp2040:transition.bzl", "RP2_SYSTEM_FLAGS", "rp2040_binary", "rp2350_binary")
24
25package(
26    default_visibility = ["//visibility:public"],
27    features = ["-layering_check"],
28)
29
30licenses(["notice"])
31
32config_setting(
33    name = "pico_clang_build",
34    constraint_values = [
35        "//pw_build/constraints/chipset:rp2040",
36    ],
37    flag_values = {
38        "@bazel_tools//tools/cpp:compiler": "clang",
39    },
40)
41
42# This is an incomplete platform, do NOT try to pass this
43# as a --platforms flag value. Use :rp2040 or :rp2350.
44platform(
45    name = "rp2_common",
46    constraint_values = [
47        "@freertos//:disable_task_statics",
48        "freertos_config_cv",
49        "//pw_build/constraints/chipset:rp2040",  # TODO: https://pwbug.dev/343487589 - Use Pico SDK constraints.
50        "//pw_build/constraints/rtos:freertos",
51        "//pw_cpu_exception:enabled",
52        "//pw_interrupt_cortex_m:backend",
53        "@rust_crates//:no_std",
54        "@platforms//os:none",
55    ],
56    flags = flags_from_dict(RP2_SYSTEM_FLAGS),
57    visibility = ["//visibility:private"],
58)
59
60platform(
61    name = "rp2040",
62    constraint_values = [
63        "@freertos//:port_ARM_CM0",
64        "@pico-sdk//bazel/constraint:rp2040",
65        # For toolchain selection.
66        "@platforms//cpu:armv6-m",
67        "//pw_build/constraints/arm:cortex-m0plus",
68    ],
69    flags = flags_from_dict({
70        "@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT": package_relative_label(":rp2040_linker_script"),
71    }),
72    parents = [":rp2_common"],
73)
74
75platform(
76    name = "rp2350",
77    constraint_values = [
78        "@freertos//:port_ARM_CM33_NTZ",
79        "@pico-sdk//bazel/constraint:rp2350",
80        # For toolchain selection.
81        "@platforms//cpu:armv8-m",
82        "//pw_build/constraints/arm:cortex-m33",
83    ],
84    flags = flags_from_dict({
85        "@pico-sdk//bazel/config:PICO_DEFAULT_LINKER_SCRIPT": package_relative_label(":rp2350_linker_script"),
86    }),
87    parents = [":rp2_common"],
88)
89
90platform(
91    name = "rp2040_pw_system_demo",
92    flags = flags_from_dict({
93        "@bazel_tools//tools/cpp:link_extra_libs": package_relative_label(":pre_init"),
94    }),
95    parents = [":rp2040"],
96)
97
98platform(
99    name = "rp2350_pw_system_demo",
100    flags = flags_from_dict({
101        "@bazel_tools//tools/cpp:link_extra_libs": package_relative_label(":pre_init"),
102    }),
103    parents = [":rp2350"],
104)
105
106# These need to get linked into every `cc_binary` for the linker
107# to succeed.
108cc_library(
109    name = "extra_platform_libs",
110    deps = [
111        "//pw_build:default_link_extra_lib",
112        "//pw_tokenizer:linker_script",
113        "@pico-sdk//src/rp2_common/pico_stdlib",
114    ] + if_compiler_is_clang(
115        [
116            "//pw_libcxx",
117            "@pico-sdk//src/rp2_common/pico_clib_interface:llvm_libc_interface",
118        ],
119        otherwise = [],
120    ),
121    alwayslink = 1,
122)
123
124alias(
125    name = "pico_sdk_clib_select",
126    actual = if_compiler_is_clang(
127        "@pico-sdk//src/rp2_common/pico_clib_interface:llvm_libc_interface",
128        otherwise = "@pico-sdk//src/rp2_common/pico_clib_interface:newlib_interface",
129    ),
130)
131
132cc_library(
133    name = "freertos_config",
134    hdrs = [
135        "config/FreeRTOSConfig.h",
136    ],
137    includes = ["config/"],
138    target_compatible_with = [":freertos_config_cv"],
139    deps = [
140        "//third_party/freertos:config_assert",
141        "@pico-sdk//src/rp2_common/cmsis:cmsis_core",
142    ],
143)
144
145constraint_value(
146    name = "freertos_config_cv",
147    constraint_setting = "@freertos//:freertos_config_setting",
148)
149
150cc_library(
151    name = "unit_test_app",
152    testonly = True,
153    srcs = [
154        "unit_test_app.cc",
155    ],
156    deps = [
157        ":pre_init",
158        "//pw_status",
159        "//pw_system",
160        "//pw_unit_test:rpc_service",
161    ],
162    alwayslink = True,
163)
164
165# This is just a stub to silence warnings saying that boot.cc and *.h files are
166# missing from the bazel build. There's no plans yet to do a Bazel build for
167# the Pi Pico.
168filegroup(
169    name = "rp2040_files",
170    srcs = [
171        "config/rp2040_hal_config.h",
172    ],
173)
174
175# This is a duplication of the contents of pigweed_module_config.h since we
176# can't do a -include because copts do not propagate to dependencies.
177cc_library(
178    name = "pigweed_module_config",
179    hdrs = ["config/pigweed_module_config.h"],
180    defines = [
181        # LINT.IfChange
182        "PW_THREAD_FREERTOS_CONFIG_JOINING_ENABLED=1",
183        "PW_ASSERT_BASIC_ACTION=PW_ASSERT_BASIC_ACTION_EXIT",
184        # LINT.ThenChange(//targets/rp2040/config/pigweed_module_config.h)
185    ],
186)
187
188cc_library(
189    name = "pre_init",
190    srcs = [
191        "boot.cc",
192    ],
193    target_compatible_with = [":freertos_config_cv"],
194    deps = [
195        ":extra_platform_libs",
196        ":freertos_config",
197        "//pw_cpu_exception:entry_backend_impl",
198        "//pw_system:init",
199        "//third_party/freertos:support",
200        "@freertos",
201        "@pico-sdk//src/rp2_common/hardware_exception:hardware_exception",
202    ],
203    alwayslink = 1,
204)
205
206cc_library(
207    name = "device_handler",
208    srcs = [
209        "device_handler.cc",
210    ],
211    strip_include_prefix = "public",
212    deps = [
213        "//pw_cpu_exception_cortex_m:snapshot",
214        "//pw_system:device_handler.facade",
215        "//pw_thread_freertos:snapshot",
216        "@pico-sdk//src/rp2_common/hardware_watchdog:hardware_watchdog",
217    ],
218)
219
220pw_cc_binary(
221    name = "system_async_example",
222    testonly = True,
223    srcs = ["system_async_example.cc"],
224    # TODO(b/365184562): This target does not build with asan and fuzztest.
225    target_compatible_with = select({
226        "//pw_fuzzer:use_fuzztest": ["@platforms//:incompatible"],
227        "//conditions:default": [],
228    }),
229    deps = [
230        "//pw_channel:rp2_stdio_channel",
231        "//pw_libcxx",
232        "//pw_multibuf:testing",
233        "//pw_system:async",
234        "//third_party/freertos:support",
235        "@freertos",
236        "@pico-sdk//src/rp2_common/pico_stdlib",
237    ],
238)
239
240rp2040_binary(
241    name = "rp2040_system_async_example",
242    testonly = True,
243    binary = ":system_async_example",
244)
245
246flash_rp2040(
247    name = "flash_rp2040_system_async_example",
248    testonly = True,
249    rp2040_binary = ":rp2040_system_async_example",
250)
251
252pw_copy_and_patch_file(
253    name = "rp2040_memmap_default",
254    src = "@pico-sdk//src/rp2_common/pico_crt0/rp2040:memmap_default.ld",
255    out = "patched_rp2040_memmap_default.ld",
256    patch_file = "patches/rp2040_memmap_default.ld.patch",
257)
258
259cc_library(
260    name = "rp2040_linker_script",
261    additional_linker_inputs = [":rp2040_memmap_default"],
262    linkopts = ["-T$(execpath :rp2040_memmap_default)"],
263    deps = [
264        "@pico-sdk//src/rp2_common/pico_standard_link:default_flash_region",
265    ],
266)
267
268rp2350_binary(
269    name = "rp2350_system_async_example",
270    testonly = True,
271    binary = ":system_async_example",
272)
273
274flash_rp2350(
275    name = "flash_rp2350_system_async_example",
276    testonly = True,
277    rp2350_binary = ":rp2350_system_async_example",
278)
279
280pw_copy_and_patch_file(
281    name = "rp2350_memmap_default",
282    src = "@pico-sdk//src/rp2_common/pico_crt0/rp2350:memmap_default.ld",
283    out = "patched_rp2350_memmap_default.ld",
284    patch_file = "patches/rp2350_memmap_default.ld.patch",
285)
286
287cc_library(
288    name = "rp2350_linker_script",
289    additional_linker_inputs = [":rp2350_memmap_default"],
290    linkopts = ["-T$(execpath :rp2350_memmap_default)"],
291    deps = [
292        "@pico-sdk//src/rp2_common/pico_standard_link:default_flash_region",
293    ],
294)
295
296sphinx_docs_library(
297    name = "docs",
298    srcs = [
299        "49-pico.rules",
300        "target_docs.rst",
301        "upstream.rst",
302    ],
303    target_compatible_with = incompatible_with_mcu(),
304)
305
306filegroup(
307    name = "bloaty_config",
308    srcs = ["bloaty_config.bloaty"],
309)
310