• 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
15import("//build_overrides/pi_pico.gni")
16import("//build_overrides/pigweed.gni")
17
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_system/system_target.gni")
21import("$dir_pw_toolchain/arm_gcc/toolchains.gni")
22import("$dir_pw_toolchain/generate_toolchain.gni")
23
24declare_args() {
25  pw_targets_ENABLE_RP2040_TEST_RUNNER = false
26}
27
28if (current_toolchain != default_toolchain) {
29  pw_source_set("pre_init") {
30    remove_configs = [ "$dir_pw_build:strict_warnings" ]
31
32    deps = [
33      "$PICO_ROOT/src/common/pico_base",
34      "$PICO_ROOT/src/common/pico_stdlib",
35      "$PICO_ROOT/src/rp2_common/pico_malloc",
36      "$dir_pw_string",
37      "$dir_pw_system",
38      "$dir_pw_third_party/freertos",
39      "$dir_pw_third_party/freertos:support",
40    ]
41    sources = [ "boot.cc" ]
42  }
43
44  config("config_includes") {
45    include_dirs = [ "config" ]
46  }
47
48  config("module_config_include") {
49    cflags = [
50      "-include",
51      rebase_path("config/pigweed_module_config.h", root_build_dir),
52    ]
53    visibility = [ ":*" ]
54  }
55
56  pw_source_set("module_config") {
57    public_configs = [ ":module_config_include" ]
58  }
59
60  config("rp2040_hal_config") {
61    inputs = [ "config/rp2040_hal_config.h" ]
62    cflags = [ "-include" +
63               rebase_path("config/rp2040_hal_config.h", root_build_dir) ]
64  }
65
66  pw_source_set("rp2040_freertos_config") {
67    public_configs = [ ":config_includes" ]
68    public_deps = [ "$dir_pw_third_party/freertos:config_assert" ]
69    public = [ "config/FreeRTOSConfig.h" ]
70  }
71
72  pw_source_set("unit_test_app") {
73    sources = [ "unit_test_app.cc" ]
74    deps = [
75      "$dir_pw_status",
76      "$dir_pw_system",
77      "$dir_pw_unit_test:rpc_service",
78    ]
79  }
80
81  # We don't want this linked into the boot_stage2 binary, so make the printf
82  # float config a source set added to pw_build_LINK_DEPS (which is dropped on
83  # the boot_stage2 binary) rather than as a default_config.
84  pw_source_set("float_printf_adapter") {
85    all_dependent_configs = [ "$dir_pw_toolchain/arm_gcc:enable_float_printf" ]
86  }
87}
88
89pw_system_target("rp2040") {
90  cpu = PW_SYSTEM_CPU.CORTEX_M0PLUS
91  scheduler = PW_SYSTEM_SCHEDULER.FREERTOS
92  use_pw_malloc = false
93  global_configs = [ ":rp2040_hal_config" ]
94
95  build_args = {
96    pw_build_DEFAULT_MODULE_CONFIG = get_path_info(":module_config", "abspath")
97    pw_build_EXECUTABLE_TARGET_TYPE = "pico_executable"
98    pw_build_EXECUTABLE_TARGET_TYPE_FILE =
99        get_path_info("$dir_pigweed/targets/rp2040/pico_executable.gni",
100                      "abspath")
101
102    pw_log_BACKEND = dir_pw_log_tokenized
103    pw_log_tokenized_HANDLER_BACKEND = "$dir_pw_system:log_backend.impl"
104
105    pw_third_party_freertos_CONFIG =
106        "$dir_pigweed/targets/rp2040:rp2040_freertos_config"
107    pw_third_party_freertos_PORT = "$dir_pw_third_party/freertos:arm_cm0"
108
109    pw_sys_io_BACKEND = dir_pw_sys_io_stdio
110    pw_build_LINK_DEPS += [
111      "$dir_pigweed/targets/rp2040:pre_init",
112      "$dir_pw_assert:impl",
113      "$dir_pw_log:impl",
114      get_path_info(":float_printf_adapter", "abspath"),
115    ]
116
117    # ONLY RELEVANT FOR UNIT TESTS.
118    if (pw_targets_ENABLE_RP2040_TEST_RUNNER) {
119      _test_runner_script =
120          "//targets/rp2040/py/rp2040_utils/unit_test_client.py"
121      pw_unit_test_AUTOMATIC_RUNNER =
122          get_path_info(_test_runner_script, "abspath")
123    }
124    pw_unit_test_MAIN = "$dir_pigweed/targets/rp2040:unit_test_app"
125  }
126}
127
128pw_doc_group("target_docs") {
129  sources = [ "target_docs.rst" ]
130}
131