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/copy_and_patch.gni") 19import("$dir_pw_build/target_types.gni") 20import("$dir_pw_docgen/docs.gni") 21import("$dir_pw_system/system_target.gni") 22import("$dir_pw_toolchain/arm_gcc/toolchains.gni") 23import("$dir_pw_toolchain/generate_toolchain.gni") 24 25declare_args() { 26 pw_targets_ENABLE_RP2040_TEST_RUNNER = false 27} 28 29if (current_toolchain != default_toolchain) { 30 pw_source_set("pre_init") { 31 remove_configs = [ "$dir_pw_build:strict_warnings" ] 32 33 deps = [ 34 "$PICO_ROOT/src/common/pico_base", 35 "$PICO_ROOT/src/common/pico_stdlib", 36 "$PICO_ROOT/src/rp2_common/hardware_exception", 37 "$PICO_ROOT/src/rp2_common/hardware_watchdog", 38 "$PICO_ROOT/src/rp2_common/pico_malloc", 39 "$dir_pigweed/targets/rp2040:memmap_default_ld", 40 "$dir_pw_cpu_exception:entry", 41 "$dir_pw_string", 42 "$dir_pw_system", 43 "$dir_pw_system:crash_handler", 44 "$dir_pw_third_party/freertos", 45 "$dir_pw_third_party/freertos:support", 46 ] 47 sources = [ "boot.cc" ] 48 } 49 50 pw_source_set("device_handler") { 51 deps = [ 52 "$PICO_ROOT/src/rp2_common/hardware_watchdog", 53 "$dir_pw_cpu_exception:entry", 54 "$dir_pw_cpu_exception_cortex_m:snapshot", 55 "$dir_pw_system:device_handler.facade", 56 "$dir_pw_thread_freertos:snapshot", 57 ] 58 sources = [ "device_handler.cc" ] 59 } 60 61 config("config_includes") { 62 include_dirs = [ "config" ] 63 defines = [ "_PW_PICO_GN_BUILD=1" ] 64 } 65 66 config("module_config_include") { 67 cflags = [ 68 "-include", 69 rebase_path("config/pigweed_module_config.h", root_build_dir), 70 ] 71 visibility = [ ":*" ] 72 } 73 74 pw_source_set("module_config") { 75 public_configs = [ ":module_config_include" ] 76 } 77 78 config("rp2040_hal_config") { 79 inputs = [ "config/rp2040_hal_config.h" ] 80 cflags = [ "-include" + 81 rebase_path("config/rp2040_hal_config.h", root_build_dir) ] 82 } 83 84 pw_copy_and_patch_file("memmap_default_ld") { 85 source = 86 "${PICO_SRC_DIR}/src/rp2_common/pico_standard_link/memmap_default.ld" 87 out = "patched_memmap_default.ld" 88 patch_file = "patches/pico_sdk_v1_memmap_default.ld.patch" 89 90 # Check if PICO_SRC_DIR is defined, as in build configurations which don't 91 # define PICO_SRC_DIR, GN will complain, as root can't be an empty string. 92 if (PICO_SRC_DIR != "") { 93 root = "${PICO_SRC_DIR}" 94 } 95 } 96 97 config("linker_script") { 98 _linker_scripts = get_target_outputs(":memmap_default_ld") 99 _linker_script_path = rebase_path(_linker_scripts[0], root_build_dir) 100 ldflags = [ "-T${_linker_script_path}" ] 101 } 102 103 pw_source_set("rp2040_freertos_config") { 104 public_configs = [ ":config_includes" ] 105 public_deps = [ "$dir_pw_third_party/freertos:config_assert" ] 106 public = [ "config/FreeRTOSConfig.h" ] 107 } 108 109 pw_source_set("unit_test_app") { 110 sources = [ "unit_test_app.cc" ] 111 deps = [ 112 "$dir_pw_status", 113 "$dir_pw_system", 114 "$dir_pw_unit_test:rpc_service", 115 ] 116 } 117 118 # We don't want this linked into the boot_stage2 binary, so make the printf 119 # float config a source set added to pw_build_LINK_DEPS (which is dropped on 120 # the boot_stage2 binary) rather than as a default_config. 121 pw_source_set("float_printf_adapter") { 122 all_dependent_configs = [ "$dir_pw_toolchain/arm_gcc:enable_float_printf" ] 123 } 124} 125 126pw_system_target("rp2040") { 127 cpu = PW_SYSTEM_CPU.CORTEX_M0PLUS 128 scheduler = PW_SYSTEM_SCHEDULER.FREERTOS 129 use_pw_malloc = false 130 global_configs = [ ":rp2040_hal_config" ] 131 132 build_args = { 133 pw_build_DEFAULT_MODULE_CONFIG = get_path_info(":module_config", "abspath") 134 pw_build_EXECUTABLE_TARGET_TYPE = "pico_executable" 135 pw_build_EXECUTABLE_TARGET_TYPE_FILE = 136 get_path_info("$dir_pigweed/targets/rp2040/pico_executable.gni", 137 "abspath") 138 139 pw_assert_BACKEND = dir_pw_assert_trap 140 pw_assert_LITE_BACKEND = dir_pw_assert_trap 141 142 pw_cpu_exception_ENTRY_BACKEND = 143 "$dir_pw_cpu_exception_cortex_m:cpu_exception_armv6m" 144 pw_cpu_exception_HANDLER_BACKEND = "$dir_pw_cpu_exception:basic_handler" 145 pw_cpu_exception_SUPPORT_BACKEND = "$dir_pw_cpu_exception_cortex_m:support" 146 147 pw_log_BACKEND = dir_pw_log_tokenized 148 pw_log_tokenized_HANDLER_BACKEND = "$dir_pw_system:log_backend.impl" 149 150 pw_third_party_freertos_CONFIG = 151 "$dir_pigweed/targets/rp2040:rp2040_freertos_config" 152 pw_third_party_freertos_PORT = "$dir_pw_third_party/freertos:arm_cm0" 153 154 pw_sys_io_BACKEND = dir_pw_sys_io_stdio 155 156 pw_sync_INTERRUPT_SPIN_LOCK_BACKEND = 157 "$dir_pw_sync_freertos:interrupt_spin_lock" 158 159 pw_system_DEVICE_HANDLER = "$dir_pigweed/targets/rp2040:device_handler" 160 161 PICO_LINKER_SCRIPT = "$dir_pigweed/targets/rp2040:linker_script" 162 163 pw_build_LINK_DEPS += [ 164 "$dir_pigweed/targets/rp2040:pre_init", 165 "$dir_pw_assert:impl", 166 "$dir_pw_cpu_exception:entry_impl", 167 "$dir_pw_log:impl", 168 get_path_info(":float_printf_adapter", "abspath"), 169 ] 170 171 # ONLY RELEVANT FOR UNIT TESTS. 172 if (pw_targets_ENABLE_RP2040_TEST_RUNNER) { 173 _test_runner_script = 174 "//targets/rp2040/py/rp2040_utils/unit_test_client.py" 175 pw_unit_test_AUTOMATIC_RUNNER = 176 get_path_info(_test_runner_script, "abspath") 177 } 178 pw_unit_test_MAIN = "$dir_pigweed/targets/rp2040:unit_test_app" 179 } 180} 181 182# This is target is to keep the presubmit happy. 183# It is not yet used. 184# TODO: pwbug.dev/349853258 - add a GN toolchain for pw_system_async. 185pw_source_set("system_async_example") { 186 sources = [ "system_async_example.cc" ] 187} 188 189pw_doc_group("target_docs") { 190 sources = [ 191 "target_docs.rst", 192 "upstream.rst", 193 ] 194 inputs = [ "49-pico.rules" ] 195} 196