blob: 234534a95aff63e002f20ae05e430f252429ffb5 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001# Copyright (c) 2021 Arm Limited. All rights reserved.
2# SPDX-License-Identifier: Apache-2.0
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Generic Makefile target for ARM Cortex M builds.
17# For more info see: tensorflow/lite/micro/cortex_m_generic/README.md
18ifeq ($(TARGET),$(filter $(TARGET), cortex_m_ethos_eval))
19 FLOAT := soft
20 GCC_TARGET_ARCH := $(TARGET_ARCH)
21
22 ifeq ($(TARGET_ARCH), cortex-m0)
23 CORE=M0
24 ARM_LDFLAGS := -Wl,--cpu=Cortex-M0
25
26 else ifeq ($(TARGET_ARCH), cortex-m3)
27 CORE=M3
28 ARM_LDFLAGS := -Wl,--cpu=Cortex-M3
29
30 else ifeq ($(TARGET_ARCH), cortex-m33)
31 CORE=M33
32 ARM_LDFLAGS := -Wl,--cpu=Cortex-M33
33 TARGET_SPECIFIC_FLAGS += -D__DSP_PRESENT=1 -D__FPU_PRESENT=1 -D__VTOR_PRESENT=1 -D__FPU_USED=1
34 FLOAT=hard
35
36 else ifeq ($(TARGET_ARCH), cortex-m33+nodsp)
37 CORE=M33
38 ARM_LDFLAGS := -Wl,--cpu=Cortex-M33.no_dsp.no_fp
39
40 else ifeq ($(TARGET_ARCH), cortex-m4)
41 CORE=M4
42 ARM_LDFLAGS := -Wl,--cpu=Cortex-M4.no_fp
43 GCC_TARGET_ARCH := cortex-m4+nofp
44
45 else ifeq ($(TARGET_ARCH), cortex-m4+fp)
46 CORE=M4
47 ARM_LDFLAGS := -Wl,--cpu=Cortex-M4
48 TARGET_SPECIFIC_FLAGS += -D__FPU_PRESENT=1
49 FLOAT=hard
50 GCC_TARGET_ARCH := cortex-m4
51
52 else ifeq ($(TARGET_ARCH), cortex-m55)
53 CORE=M55
54 ARM_LDFLAGS := -Wl,--cpu=8.1-M.Main.mve.fp
55 TARGET_SPECIFIC_FLAGS += -D__DSP_PRESENT=1 -D__FPU_PRESENT=1
56 FLOAT=hard
57
58 else ifeq ($(TARGET_ARCH), cortex-m55+nodsp+nofp)
59 CORE=M55
60 ARM_LDFLAGS := -Wl,--cpu=8.1-M.Main.mve.no_dsp.no_fp
61
62 else ifeq ($(TARGET_ARCH), cortex-m55+nofp)
63 CORE=M55
64 ARM_LDFLAGS := -Wl,--cpu=8.1-M.Main.mve.no_fp
65 TARGET_SPECIFIC_FLAGS += -D__DSP_PRESENT=1
66
67 else ifeq ($(TARGET_ARCH), cortex-m7)
68 CORE=M7
69 ARM_LDFLAGS := -Wl,--cpu=Cortex-M7.no_fp
70 GCC_TARGET_ARCH := cortex-m7+nofp
71
72 else ifeq ($(TARGET_ARCH), cortex-m7+fp)
73 CORE=M7
74 ARM_LDFLAGS := -Wl,--cpu=Cortex-M7
75 FLOAT=hard
76 GCC_TARGET_ARCH := cortex-m7
77
78 else
79 $(error "TARGET_ARCH=$(TARGET_ARCH) is not supported")
80 endif
81
82 ifneq ($(filter cortex-m55%,$(TARGET_ARCH)),)
83 # soft-abi=soft disables MVE - use softfp instead for M55.
84 ifeq ($(FLOAT),soft)
85 FLOAT=softfp
86 endif
87 endif
88
89 # Toolchain specfic flags
90 ifeq ($(TOOLCHAIN), armclang)
91 CXX_TOOL := armclang
92 CC_TOOL := armclang
93 AR_TOOL := armar
94 LD := armlink
95
96 FLAGS_ARMC = \
97 --target=arm-arm-none-eabi \
98 -mcpu=$(TARGET_ARCH)
99
100 # For debug, include specific dwarf format symbols
101 ifeq ($(BUILD_TYPE), debug)
102 ifneq ($(ARMCLANG_DEBUG_DWARF_LEVEL),)
103 FLAGS_ARMC += -gdwarf-$(ARMCLANG_DEBUG_DWARF_LEVEL)
104 endif
105 endif
106
107 CXXFLAGS += $(FLAGS_ARMC)
108 CCFLAGS += $(FLAGS_ARMC)
109 LDFLAGS += $(ARM_LDFLAGS)
110
111 # Arm Compiler will not link the Math library (see below), therefore we're filtering it out.
112 # See Fatal error: L6450U: Cannot find library m:
113 # "Arm Compiler is designed to run in a bare metal environment,
114 # and automatically includes implementations of these functions,
115 # and so no such flag is necessary."
116 # https://developer.arm.com/documentation/100891/0611/troubleshooting/general-troubleshooting-advice
117 MICROLITE_LIBS := $(filter-out -lm,$(MICROLITE_LIBS))
118
119 else ifeq ($(TOOLCHAIN), gcc)
alexander3c798932021-03-26 21:42:19 +0000120 TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
121
122 FLAGS_GCC = -mcpu=$(GCC_TARGET_ARCH) -mfpu=auto
123 CXXFLAGS += $(FLAGS_GCC)
124 CCFLAGS += $(FLAGS_GCC)
125
126 else
127 $(error "TOOLCHAIN=$(TOOLCHAIN) is not supported.")
128 endif
129
Isabella Gottardic5d8bda2021-07-21 10:35:08 +0100130
alexander3c798932021-03-26 21:42:19 +0000131 PLATFORM_FLAGS = \
132 -DTF_LITE_MCU_DEBUG_LOG \
133 -mthumb \
134 -mfloat-abi=$(FLOAT) \
135 -funsigned-char \
136 -mlittle-endian \
137 -Wno-type-limits \
138 -Wno-unused-private-field \
139 -fomit-frame-pointer \
140 -MD \
141 -DCPU_CORTEX_$(CORE)=1 \
Richard Burton527b4742021-11-26 12:17:19 +0000142 -DETHOSU_ARCH=${ETHOSU_ARCH} \
alexander3c798932021-03-26 21:42:19 +0000143 $(TARGET_SPECIFIC_FLAGS)
144
145 # Common + C/C++ flags
Cisco Cervellera414b1b92021-09-28 18:15:10 +0100146 CXXFLAGS += $(PLATFORM_FLAGS)
147 CCFLAGS += $(PLATFORM_FLAGS)
alexander3c798932021-03-26 21:42:19 +0000148
149endif