# Copyright 2022 The Pigweed Authors # # Licensed under the Apache License, Version 2.0 (the "License"); you may not # use this file except in compliance with the License. You may obtain a copy of # the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. import("//build_overrides/pi_pico.gni") import("//build_overrides/pigweed.gni") import("$dir_pw_build/copy_and_patch.gni") import("$dir_pw_build/target_types.gni") import("$dir_pw_system/system_target.gni") import("$dir_pw_toolchain/arm_gcc/toolchains.gni") import("$dir_pw_toolchain/generate_toolchain.gni") declare_args() { pw_targets_ENABLE_RP2040_TEST_RUNNER = false } if (current_toolchain != default_toolchain) { pw_source_set("pre_init") { remove_configs = [ "$dir_pw_build:strict_warnings" ] deps = [ "$PICO_ROOT/src/common/pico_base", "$PICO_ROOT/src/common/pico_stdlib", "$PICO_ROOT/src/rp2_common/hardware_exception", "$PICO_ROOT/src/rp2_common/hardware_watchdog", "$PICO_ROOT/src/rp2_common/pico_malloc", "$dir_pigweed/targets/rp2040:memmap_default_ld", "$dir_pw_cpu_exception:entry", "$dir_pw_system", "$dir_pw_system:crash_handler", "$pw_external_freertos", "$pw_external_freertos:support", ] sources = [ "boot.cc" ] } pw_source_set("device_handler") { deps = [ "$PICO_ROOT/src/rp2_common/hardware_watchdog", "$dir_pw_cpu_exception:entry", "$dir_pw_cpu_exception_cortex_m:snapshot", "$dir_pw_system:device_handler.facade", "$dir_pw_thread_freertos:snapshot", ] sources = [ "device_handler.cc" ] } config("config_includes") { include_dirs = [ "config" ] defines = [ "_PW_PICO_GN_BUILD=1" ] } config("module_config_include") { cflags = [ "-include", rebase_path("config/pigweed_module_config.h", root_build_dir), ] visibility = [ ":*" ] } pw_source_set("module_config") { public_configs = [ ":module_config_include" ] } config("rp2040_hal_config") { inputs = [ "config/rp2040_hal_config.h" ] cflags = [ "-include" + rebase_path("config/rp2040_hal_config.h", root_build_dir) ] } pw_copy_and_patch_file("memmap_default_ld") { source = "${PICO_SRC_DIR}/src/rp2_common/pico_standard_link/memmap_default.ld" out = "patched_memmap_default.ld" patch_file = "patches/pico_sdk_v1_memmap_default.ld.patch" # Check if PICO_SRC_DIR is defined, as in build configurations which don't # define PICO_SRC_DIR, GN will complain, as root can't be an empty string. if (PICO_SRC_DIR != "") { root = "${PICO_SRC_DIR}" } } config("linker_script") { _linker_scripts = get_target_outputs(":memmap_default_ld") _linker_script_path = rebase_path(_linker_scripts[0], root_build_dir) ldflags = [ "-T${_linker_script_path}" ] } pw_source_set("rp2040_freertos_config") { public_configs = [ ":config_includes" ] public_deps = [ "$pw_external_freertos:config_assert" ] public = [ "config/FreeRTOSConfig.h" ] } pw_source_set("unit_test_app") { sources = [ "unit_test_app.cc" ] deps = [ "$dir_pw_status", "$dir_pw_system", "$dir_pw_thread:thread", "$dir_pw_thread_freertos:thread", "$dir_pw_unit_test:rpc_service", ] } # We don't want this linked into the boot_stage2 binary, so make the printf # float config a source set added to pw_build_LINK_DEPS (which is dropped on # the boot_stage2 binary) rather than as a default_config. pw_source_set("float_printf_adapter") { all_dependent_configs = [ "$dir_pw_toolchain/arm_gcc:enable_float_printf" ] } } pw_system_target("rp2040") { cpu = PW_SYSTEM_CPU.CORTEX_M0PLUS scheduler = PW_SYSTEM_SCHEDULER.FREERTOS use_pw_malloc = false global_configs = [ ":rp2040_hal_config" ] build_args = { pw_build_DEFAULT_MODULE_CONFIG = get_path_info(":module_config", "abspath") pw_build_EXECUTABLE_TARGET_TYPE = "pico_executable" pw_build_EXECUTABLE_TARGET_TYPE_FILE = get_path_info("$dir_pigweed/targets/rp2040/pico_executable.gni", "abspath") pw_assert_BACKEND = dir_pw_assert_trap pw_assert_LITE_BACKEND = dir_pw_assert_trap pw_cpu_exception_ENTRY_BACKEND = "$dir_pw_cpu_exception_cortex_m:cpu_exception_armv6m" pw_cpu_exception_HANDLER_BACKEND = "$dir_pw_cpu_exception:basic_handler" pw_cpu_exception_SUPPORT_BACKEND = "$dir_pw_cpu_exception_cortex_m:support" pw_log_BACKEND = dir_pw_log_tokenized pw_log_tokenized_HANDLER_BACKEND = "$dir_pw_system:log_backend.impl" pw_third_party_freertos_CONFIG = "$dir_pigweed/targets/rp2040:rp2040_freertos_config" pw_third_party_freertos_PORT = "$pw_external_freertos:arm_cm0" pw_sys_io_BACKEND = dir_pw_sys_io_stdio pw_sync_INTERRUPT_SPIN_LOCK_BACKEND = "$dir_pw_sync_freertos:interrupt_spin_lock" pw_system_DEVICE_HANDLER = "$dir_pigweed/targets/rp2040:device_handler" PICO_LINKER_SCRIPT = "$dir_pigweed/targets/rp2040:linker_script" pw_build_LINK_DEPS += [ "$dir_pigweed/targets/rp2040:pre_init", "$dir_pw_assert:impl", "$dir_pw_atomic:atomic_cortex_m", "$dir_pw_cpu_exception:entry_impl", "$dir_pw_log:impl", get_path_info(":float_printf_adapter", "abspath"), ] # ONLY RELEVANT FOR UNIT TESTS. if (pw_targets_ENABLE_RP2040_TEST_RUNNER) { _test_runner_script = "$dir_pigweed/targets/rp2040/py/rp2040_utils/unit_test_client.py" pw_unit_test_AUTOMATIC_RUNNER = get_path_info(_test_runner_script, "abspath") } pw_unit_test_MAIN = "$dir_pigweed/targets/rp2040:unit_test_app" } } # This is target is to keep the presubmit happy. # It is not yet used. # TODO: pwbug.dev/349853258 - add a GN toolchain for pw_system_async. pw_source_set("system_async_example") { sources = [ "system_async_example.cc" ] }