1# Copyright 2021 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_linker_script.bzl", "pw_linker_script") 20load("//third_party/freertos:flags.bzl", "FREERTOS_FLAGS") 21 22package( 23 default_visibility = ["//visibility:public"], 24 features = ["-layering_check"], 25) 26 27licenses(["notice"]) 28 29cc_library( 30 name = "freertos_config", 31 hdrs = [ 32 "config/FreeRTOSConfig.h", 33 ], 34 includes = ["config/"], 35 target_compatible_with = [":freertos_config_cv"], 36 deps = ["//third_party/freertos:config_assert"], 37) 38 39# Constraint value corresponding to :freertos_config. 40# 41# If you include this in your platform definition, you will tell Bazel to use 42# the :freertos_config defined above when compiling FreeRTOS. (See 43# //third_party/freertos/BUILD.bazel.) If you include it in a target's 44# `target_compatible_with`, you will tell Bazel the target can only be built 45# for platforms that specify this FreeRTOS config. 46constraint_value( 47 name = "freertos_config_cv", 48 constraint_setting = "@freertos//:freertos_config_setting", 49) 50 51platform( 52 name = "platform", 53 constraint_values = [ 54 ":freertos_config_cv", 55 "//pw_build/constraints/rtos:freertos", 56 "//pw_interrupt_cortex_m:backend", 57 "//pw_malloc:bucket_block_allocator_backend", 58 "@freertos//:port_ARM_CM4F", 59 "@freertos//:disable_task_statics", 60 "@platforms//cpu:armv7e-m", 61 "@platforms//os:none", 62 "//pw_build/constraints/arm:cortex-m4", 63 "@rust_crates//:no_std", 64 ], 65 flags = flags_from_dict(FREERTOS_FLAGS | { 66 "@cmsis_core//:cc_defines": ":cc_defines", 67 "@pigweed//pw_assert:check_backend": "//pw_assert_basic", 68 "@pigweed//pw_assert:check_backend_impl": "//pw_assert_basic:impl", 69 "@pigweed//pw_boot:backend": "//pw_boot_cortex_m", 70 "@pigweed//pw_log:backend": "//pw_log_tokenized", 71 "@pigweed//pw_log:backend_impl": "//pw_log_tokenized:impl", 72 "@pigweed//pw_log_tokenized:handler_backend": "//pw_system:log_backend", 73 "@pigweed//pw_malloc:backend": "//pw_malloc:bucket_block_allocator", 74 "@pigweed//pw_sys_io:backend": "//pw_sys_io_stm32cube", 75 "@pigweed//pw_system:extra_platform_libs": "//targets/stm32f429i_disc1_stm32cube:extra_platform_libs", 76 "@pigweed//pw_unit_test:main": "//targets/stm32f429i_disc1_stm32cube:unit_test_app", 77 "@stm32f4xx_hal_driver//:hal_config": "//targets/stm32f429i_disc1_stm32cube:hal_config", 78 }), 79) 80 81cc_library( 82 name = "cc_defines", 83 defines = [ 84 "STM32CUBE_HEADER=\\\"stm32f4xx.h\\\"", 85 "STM32F429xx", 86 ], 87) 88 89cc_library( 90 name = "hal_config", 91 hdrs = [ 92 "config/stm32f4xx_hal_conf.h", 93 ], 94 includes = ["config"], 95 tags = ["noclangtidy"], 96) 97 98cc_library( 99 name = "unit_test_app", 100 testonly = True, 101 srcs = [ 102 "unit_test_app.cc", 103 ], 104 deps = [ 105 "//pw_status", 106 "//pw_system", 107 "//pw_unit_test:rpc_service", 108 ], 109 alwayslink = 1, 110) 111 112cc_library( 113 name = "pre_init", 114 srcs = [ 115 "boot.cc", 116 "vector_table.c", 117 ], 118 copts = ["-Wno-return-type"], 119 defines = ["PW_MALLOC_ACTIVE=1"], 120 implementation_deps = ["//pw_assert:check"], 121 target_compatible_with = [":freertos_config_cv"], 122 deps = [ 123 ":freertos_config", 124 "//pw_boot", 125 "//pw_boot_cortex_m", 126 "//pw_malloc", 127 "//pw_preprocessor", 128 "//pw_string", 129 "//pw_sys_io_stm32cube", 130 "//pw_system:init", 131 "//pw_toolchain:infinite_loop", 132 "//third_party/freertos:support", 133 "//third_party/stm32cube", 134 "@freertos", 135 ], 136 alwayslink = 1, 137) 138 139cc_library( 140 name = "extra_platform_libs", 141 deps = [ 142 # The linker script for pw_boot_cortex_m. 143 ":linker_script", 144 # The initialization code. 145 ":pre_init", 146 # The linker script for pw_tokenizer. 147 "//pw_tokenizer:linker_script", 148 # Arm GCC support libraries. 149 "//pw_toolchain/arm_gcc:arm_none_eabi_gcc_support", 150 ], 151) 152 153pw_linker_script( 154 name = "linker_script", 155 defines = [ 156 "PW_BOOT_FLASH_BEGIN=0x08000200", 157 "PW_BOOT_FLASH_SIZE=2048K", 158 159 # TODO(b/235348465): Currently "pw_tokenizer/detokenize_test" requires 160 # at least 6K bytes in heap when using pw_malloc:bucket_block_allocator. 161 # The heap size required for tests should be investigated. 162 "PW_BOOT_HEAP_SIZE=7K", 163 "PW_BOOT_MIN_STACK_SIZE=1K", 164 "PW_BOOT_RAM_BEGIN=0x20000000", 165 "PW_BOOT_RAM_SIZE=192K", 166 "PW_BOOT_VECTOR_TABLE_BEGIN=0x08000000", 167 "PW_BOOT_VECTOR_TABLE_SIZE=512", 168 ], 169 linker_script = "//pw_boot_cortex_m:basic_cortex_m.ld", 170) 171 172sphinx_docs_library( 173 name = "docs", 174 srcs = [ 175 "target_docs.rst", 176 ], 177 target_compatible_with = incompatible_with_mcu(), 178) 179