Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 """
marcozecchini 0:9fca2b23d0ba 2 mbed SDK
marcozecchini 0:9fca2b23d0ba 3 Copyright (c) 2011-2013 ARM Limited
marcozecchini 0:9fca2b23d0ba 4
marcozecchini 0:9fca2b23d0ba 5 Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 6 you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 7 You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 8
marcozecchini 0:9fca2b23d0ba 9 http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 10
marcozecchini 0:9fca2b23d0ba 11 Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 12 distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 14 See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 15 limitations under the License.
marcozecchini 0:9fca2b23d0ba 16 """
marcozecchini 0:9fca2b23d0ba 17 import re
marcozecchini 0:9fca2b23d0ba 18 from copy import copy
marcozecchini 0:9fca2b23d0ba 19 from os.path import join, dirname, splitext, basename, exists
marcozecchini 0:9fca2b23d0ba 20 from os import makedirs, write
marcozecchini 0:9fca2b23d0ba 21 from tempfile import mkstemp
marcozecchini 0:9fca2b23d0ba 22
marcozecchini 0:9fca2b23d0ba 23 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
marcozecchini 0:9fca2b23d0ba 24 from tools.hooks import hook_tool
marcozecchini 0:9fca2b23d0ba 25 from tools.utils import mkdir, NotSupportedException
marcozecchini 0:9fca2b23d0ba 26
marcozecchini 0:9fca2b23d0ba 27 class ARM(mbedToolchain):
marcozecchini 0:9fca2b23d0ba 28 LINKER_EXT = '.sct'
marcozecchini 0:9fca2b23d0ba 29 LIBRARY_EXT = '.ar'
marcozecchini 0:9fca2b23d0ba 30
marcozecchini 0:9fca2b23d0ba 31 STD_LIB_NAME = "%s.ar"
marcozecchini 0:9fca2b23d0ba 32 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)')
marcozecchini 0:9fca2b23d0ba 33 INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
marcozecchini 0:9fca2b23d0ba 34 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
marcozecchini 0:9fca2b23d0ba 35 SHEBANG = "#! armcc -E"
marcozecchini 0:9fca2b23d0ba 36 SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
marcozecchini 0:9fca2b23d0ba 37 "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD"]
marcozecchini 0:9fca2b23d0ba 38
marcozecchini 0:9fca2b23d0ba 39 @staticmethod
marcozecchini 0:9fca2b23d0ba 40 def check_executable():
marcozecchini 0:9fca2b23d0ba 41 """Returns True if the executable (armcc) location specified by the
marcozecchini 0:9fca2b23d0ba 42 user exists OR the executable can be found on the PATH.
marcozecchini 0:9fca2b23d0ba 43 Returns False otherwise."""
marcozecchini 0:9fca2b23d0ba 44 return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
marcozecchini 0:9fca2b23d0ba 45
marcozecchini 0:9fca2b23d0ba 46 def __init__(self, target, notify=None, macros=None,
marcozecchini 0:9fca2b23d0ba 47 silent=False, extra_verbose=False, build_profile=None,
marcozecchini 0:9fca2b23d0ba 48 build_dir=None):
marcozecchini 0:9fca2b23d0ba 49 mbedToolchain.__init__(self, target, notify, macros, silent,
marcozecchini 0:9fca2b23d0ba 50 build_dir=build_dir,
marcozecchini 0:9fca2b23d0ba 51 extra_verbose=extra_verbose,
marcozecchini 0:9fca2b23d0ba 52 build_profile=build_profile)
marcozecchini 0:9fca2b23d0ba 53 if target.core not in self.SUPPORTED_CORES:
marcozecchini 0:9fca2b23d0ba 54 raise NotSupportedException(
marcozecchini 0:9fca2b23d0ba 55 "this compiler does not support the core %s" % target.core)
marcozecchini 0:9fca2b23d0ba 56
marcozecchini 0:9fca2b23d0ba 57 if target.core == "Cortex-M0+":
marcozecchini 0:9fca2b23d0ba 58 cpu = "Cortex-M0"
marcozecchini 0:9fca2b23d0ba 59 elif target.core == "Cortex-M4F":
marcozecchini 0:9fca2b23d0ba 60 cpu = "Cortex-M4.fp"
marcozecchini 0:9fca2b23d0ba 61 elif target.core == "Cortex-M7FD":
marcozecchini 0:9fca2b23d0ba 62 cpu = "Cortex-M7.fp.dp"
marcozecchini 0:9fca2b23d0ba 63 elif target.core == "Cortex-M7F":
marcozecchini 0:9fca2b23d0ba 64 cpu = "Cortex-M7.fp.sp"
marcozecchini 0:9fca2b23d0ba 65 else:
marcozecchini 0:9fca2b23d0ba 66 cpu = target.core
marcozecchini 0:9fca2b23d0ba 67
marcozecchini 0:9fca2b23d0ba 68 ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
marcozecchini 0:9fca2b23d0ba 69 ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
marcozecchini 0:9fca2b23d0ba 70
marcozecchini 0:9fca2b23d0ba 71 main_cc = join(ARM_BIN, "armcc")
marcozecchini 0:9fca2b23d0ba 72
marcozecchini 0:9fca2b23d0ba 73 self.flags['common'] += ["--cpu=%s" % cpu]
marcozecchini 0:9fca2b23d0ba 74
marcozecchini 0:9fca2b23d0ba 75 self.asm = [main_cc] + self.flags['common'] + self.flags['asm']
marcozecchini 0:9fca2b23d0ba 76 self.cc = [main_cc] + self.flags['common'] + self.flags['c']
marcozecchini 0:9fca2b23d0ba 77 self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx']
marcozecchini 0:9fca2b23d0ba 78
marcozecchini 0:9fca2b23d0ba 79 self.ld = [join(ARM_BIN, "armlink")] + self.flags['ld']
marcozecchini 0:9fca2b23d0ba 80
marcozecchini 0:9fca2b23d0ba 81 self.ar = join(ARM_BIN, "armar")
marcozecchini 0:9fca2b23d0ba 82 self.elf2bin = join(ARM_BIN, "fromelf")
marcozecchini 0:9fca2b23d0ba 83
marcozecchini 0:9fca2b23d0ba 84 def parse_dependencies(self, dep_path):
marcozecchini 0:9fca2b23d0ba 85 dependencies = []
marcozecchini 0:9fca2b23d0ba 86 for line in open(dep_path).readlines():
marcozecchini 0:9fca2b23d0ba 87 match = ARM.DEP_PATTERN.match(line)
marcozecchini 0:9fca2b23d0ba 88 if match is not None:
marcozecchini 0:9fca2b23d0ba 89 #we need to append chroot, because when the .d files are generated the compiler is chrooted
marcozecchini 0:9fca2b23d0ba 90 dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file'))
marcozecchini 0:9fca2b23d0ba 91 return dependencies
marcozecchini 0:9fca2b23d0ba 92
marcozecchini 0:9fca2b23d0ba 93 def parse_output(self, output):
marcozecchini 0:9fca2b23d0ba 94 msg = None
marcozecchini 0:9fca2b23d0ba 95 for line in output.splitlines():
marcozecchini 0:9fca2b23d0ba 96 match = ARM.DIAGNOSTIC_PATTERN.match(line)
marcozecchini 0:9fca2b23d0ba 97 if match is not None:
marcozecchini 0:9fca2b23d0ba 98 if msg is not None:
marcozecchini 0:9fca2b23d0ba 99 self.cc_info(msg)
marcozecchini 0:9fca2b23d0ba 100 msg = None
marcozecchini 0:9fca2b23d0ba 101 msg = {
marcozecchini 0:9fca2b23d0ba 102 'severity': match.group('severity').lower(),
marcozecchini 0:9fca2b23d0ba 103 'file': match.group('file'),
marcozecchini 0:9fca2b23d0ba 104 'line': match.group('line'),
marcozecchini 0:9fca2b23d0ba 105 'col': match.group('column') if match.group('column') else 0,
marcozecchini 0:9fca2b23d0ba 106 'message': match.group('message'),
marcozecchini 0:9fca2b23d0ba 107 'text': '',
marcozecchini 0:9fca2b23d0ba 108 'target_name': self.target.name,
marcozecchini 0:9fca2b23d0ba 109 'toolchain_name': self.name
marcozecchini 0:9fca2b23d0ba 110 }
marcozecchini 0:9fca2b23d0ba 111 elif msg is not None:
marcozecchini 0:9fca2b23d0ba 112 # Determine the warning/error column by calculating the ^ position
marcozecchini 0:9fca2b23d0ba 113 match = ARM.INDEX_PATTERN.match(line)
marcozecchini 0:9fca2b23d0ba 114 if match is not None:
marcozecchini 0:9fca2b23d0ba 115 msg['col'] = len(match.group('col'))
marcozecchini 0:9fca2b23d0ba 116 self.cc_info(msg)
marcozecchini 0:9fca2b23d0ba 117 msg = None
marcozecchini 0:9fca2b23d0ba 118 else:
marcozecchini 0:9fca2b23d0ba 119 msg['text'] += line+"\n"
marcozecchini 0:9fca2b23d0ba 120
marcozecchini 0:9fca2b23d0ba 121 if msg is not None:
marcozecchini 0:9fca2b23d0ba 122 self.cc_info(msg)
marcozecchini 0:9fca2b23d0ba 123
marcozecchini 0:9fca2b23d0ba 124 def get_dep_option(self, object):
marcozecchini 0:9fca2b23d0ba 125 base, _ = splitext(object)
marcozecchini 0:9fca2b23d0ba 126 dep_path = base + '.d'
marcozecchini 0:9fca2b23d0ba 127 return ["--depend", dep_path]
marcozecchini 0:9fca2b23d0ba 128
marcozecchini 0:9fca2b23d0ba 129 def get_config_option(self, config_header):
marcozecchini 0:9fca2b23d0ba 130 return ['--preinclude=' + config_header]
marcozecchini 0:9fca2b23d0ba 131
marcozecchini 0:9fca2b23d0ba 132 def get_compile_options(self, defines, includes, for_asm=False):
marcozecchini 0:9fca2b23d0ba 133 opts = ['-D%s' % d for d in defines]
marcozecchini 0:9fca2b23d0ba 134 if self.RESPONSE_FILES:
marcozecchini 0:9fca2b23d0ba 135 opts += ['--via', self.get_inc_file(includes)]
marcozecchini 0:9fca2b23d0ba 136 else:
marcozecchini 0:9fca2b23d0ba 137 opts += ["-I%s" % i for i in includes]
marcozecchini 0:9fca2b23d0ba 138
marcozecchini 0:9fca2b23d0ba 139 if not for_asm:
marcozecchini 0:9fca2b23d0ba 140 config_header = self.get_config_header()
marcozecchini 0:9fca2b23d0ba 141 if config_header is not None:
marcozecchini 0:9fca2b23d0ba 142 opts = opts + self.get_config_option(config_header)
marcozecchini 0:9fca2b23d0ba 143 return opts
marcozecchini 0:9fca2b23d0ba 144
marcozecchini 0:9fca2b23d0ba 145 @hook_tool
marcozecchini 0:9fca2b23d0ba 146 def assemble(self, source, object, includes):
marcozecchini 0:9fca2b23d0ba 147 # Preprocess first, then assemble
marcozecchini 0:9fca2b23d0ba 148 dir = join(dirname(object), '.temp')
marcozecchini 0:9fca2b23d0ba 149 mkdir(dir)
marcozecchini 0:9fca2b23d0ba 150 tempfile = join(dir, basename(object) + '.E.s')
marcozecchini 0:9fca2b23d0ba 151
marcozecchini 0:9fca2b23d0ba 152 # Build preprocess assemble command
marcozecchini 0:9fca2b23d0ba 153 cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]
marcozecchini 0:9fca2b23d0ba 154
marcozecchini 0:9fca2b23d0ba 155 # Build main assemble command
marcozecchini 0:9fca2b23d0ba 156 cmd = self.asm + ["-o", object, tempfile]
marcozecchini 0:9fca2b23d0ba 157
marcozecchini 0:9fca2b23d0ba 158 # Call cmdline hook
marcozecchini 0:9fca2b23d0ba 159 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
marcozecchini 0:9fca2b23d0ba 160 cmd = self.hook.get_cmdline_assembler(cmd)
marcozecchini 0:9fca2b23d0ba 161
marcozecchini 0:9fca2b23d0ba 162 # Return command array, don't execute
marcozecchini 0:9fca2b23d0ba 163 return [cmd_pre, cmd]
marcozecchini 0:9fca2b23d0ba 164
marcozecchini 0:9fca2b23d0ba 165 @hook_tool
marcozecchini 0:9fca2b23d0ba 166 def compile(self, cc, source, object, includes):
marcozecchini 0:9fca2b23d0ba 167 # Build compile command
marcozecchini 0:9fca2b23d0ba 168 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
marcozecchini 0:9fca2b23d0ba 169
marcozecchini 0:9fca2b23d0ba 170 cmd.extend(self.get_dep_option(object))
marcozecchini 0:9fca2b23d0ba 171
marcozecchini 0:9fca2b23d0ba 172 cmd.extend(["-o", object, source])
marcozecchini 0:9fca2b23d0ba 173
marcozecchini 0:9fca2b23d0ba 174 # Call cmdline hook
marcozecchini 0:9fca2b23d0ba 175 cmd = self.hook.get_cmdline_compiler(cmd)
marcozecchini 0:9fca2b23d0ba 176
marcozecchini 0:9fca2b23d0ba 177 return [cmd]
marcozecchini 0:9fca2b23d0ba 178
marcozecchini 0:9fca2b23d0ba 179 def compile_c(self, source, object, includes):
marcozecchini 0:9fca2b23d0ba 180 return self.compile(self.cc, source, object, includes)
marcozecchini 0:9fca2b23d0ba 181
marcozecchini 0:9fca2b23d0ba 182 def compile_cpp(self, source, object, includes):
marcozecchini 0:9fca2b23d0ba 183 return self.compile(self.cppc, source, object, includes)
marcozecchini 0:9fca2b23d0ba 184
marcozecchini 0:9fca2b23d0ba 185 def correct_scatter_shebang(self, scatter_file):
marcozecchini 0:9fca2b23d0ba 186 """Correct the shebang at the top of a scatter file.
marcozecchini 0:9fca2b23d0ba 187
marcozecchini 0:9fca2b23d0ba 188 Positional arguments:
marcozecchini 0:9fca2b23d0ba 189 scatter_file -- the scatter file to correct
marcozecchini 0:9fca2b23d0ba 190
marcozecchini 0:9fca2b23d0ba 191 Return:
marcozecchini 0:9fca2b23d0ba 192 The location of the correct scatter file
marcozecchini 0:9fca2b23d0ba 193
marcozecchini 0:9fca2b23d0ba 194 Side Effects:
marcozecchini 0:9fca2b23d0ba 195 This method MAY write a new scatter file to disk
marcozecchini 0:9fca2b23d0ba 196 """
marcozecchini 0:9fca2b23d0ba 197 with open(scatter_file, "rb") as input:
marcozecchini 0:9fca2b23d0ba 198 lines = input.readlines()
marcozecchini 0:9fca2b23d0ba 199 if (lines[0].startswith(self.SHEBANG) or
marcozecchini 0:9fca2b23d0ba 200 not lines[0].startswith("#!")):
marcozecchini 0:9fca2b23d0ba 201 return scatter_file
marcozecchini 0:9fca2b23d0ba 202 else:
marcozecchini 0:9fca2b23d0ba 203 new_scatter = join(self.build_dir, ".link_script.sct")
marcozecchini 0:9fca2b23d0ba 204 if self.need_update(new_scatter, [scatter_file]):
marcozecchini 0:9fca2b23d0ba 205 with open(new_scatter, "wb") as out:
marcozecchini 0:9fca2b23d0ba 206 out.write(self.SHEBANG)
marcozecchini 0:9fca2b23d0ba 207 out.write("\n")
marcozecchini 0:9fca2b23d0ba 208 out.write("".join(lines[1:]))
marcozecchini 0:9fca2b23d0ba 209 return new_scatter
marcozecchini 0:9fca2b23d0ba 210
marcozecchini 0:9fca2b23d0ba 211 @hook_tool
marcozecchini 0:9fca2b23d0ba 212 def link(self, output, objects, libraries, lib_dirs, scatter_file):
marcozecchini 0:9fca2b23d0ba 213 base, _ = splitext(output)
marcozecchini 0:9fca2b23d0ba 214 map_file = base + ".map"
marcozecchini 0:9fca2b23d0ba 215 args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
marcozecchini 0:9fca2b23d0ba 216 args.extend(objects)
marcozecchini 0:9fca2b23d0ba 217 args.extend(libraries)
marcozecchini 0:9fca2b23d0ba 218 if lib_dirs:
marcozecchini 0:9fca2b23d0ba 219 args.extend(["--userlibpath", ",".join(lib_dirs)])
marcozecchini 0:9fca2b23d0ba 220 if scatter_file:
marcozecchini 0:9fca2b23d0ba 221 new_scatter = self.correct_scatter_shebang(scatter_file)
marcozecchini 0:9fca2b23d0ba 222 args.extend(["--scatter", new_scatter])
marcozecchini 0:9fca2b23d0ba 223
marcozecchini 0:9fca2b23d0ba 224 cmd_pre = self.ld + args
marcozecchini 0:9fca2b23d0ba 225 cmd = self.hook.get_cmdline_linker(cmd_pre)
marcozecchini 0:9fca2b23d0ba 226
marcozecchini 0:9fca2b23d0ba 227 if self.RESPONSE_FILES:
marcozecchini 0:9fca2b23d0ba 228 cmd_linker = cmd[0]
marcozecchini 0:9fca2b23d0ba 229 link_files = self.get_link_file(cmd[1:])
marcozecchini 0:9fca2b23d0ba 230 cmd = [cmd_linker, '--via', link_files]
marcozecchini 0:9fca2b23d0ba 231
marcozecchini 0:9fca2b23d0ba 232 self.cc_verbose("Link: %s" % ' '.join(cmd))
marcozecchini 0:9fca2b23d0ba 233 self.default_cmd(cmd)
marcozecchini 0:9fca2b23d0ba 234
marcozecchini 0:9fca2b23d0ba 235 @hook_tool
marcozecchini 0:9fca2b23d0ba 236 def archive(self, objects, lib_path):
marcozecchini 0:9fca2b23d0ba 237 if self.RESPONSE_FILES:
marcozecchini 0:9fca2b23d0ba 238 param = ['--via', self.get_arch_file(objects)]
marcozecchini 0:9fca2b23d0ba 239 else:
marcozecchini 0:9fca2b23d0ba 240 param = objects
marcozecchini 0:9fca2b23d0ba 241 self.default_cmd([self.ar, '-r', lib_path] + param)
marcozecchini 0:9fca2b23d0ba 242
marcozecchini 0:9fca2b23d0ba 243 @hook_tool
marcozecchini 0:9fca2b23d0ba 244 def binary(self, resources, elf, bin):
marcozecchini 0:9fca2b23d0ba 245 _, fmt = splitext(bin)
marcozecchini 0:9fca2b23d0ba 246 bin_arg = {".bin": "--bin", ".hex": "--i32"}[fmt]
marcozecchini 0:9fca2b23d0ba 247 cmd = [self.elf2bin, bin_arg, '-o', bin, elf]
marcozecchini 0:9fca2b23d0ba 248 cmd = self.hook.get_cmdline_binary(cmd)
marcozecchini 0:9fca2b23d0ba 249 self.cc_verbose("FromELF: %s" % ' '.join(cmd))
marcozecchini 0:9fca2b23d0ba 250 self.default_cmd(cmd)
marcozecchini 0:9fca2b23d0ba 251
marcozecchini 0:9fca2b23d0ba 252 @staticmethod
marcozecchini 0:9fca2b23d0ba 253 def name_mangle(name):
marcozecchini 0:9fca2b23d0ba 254 return "_Z%i%sv" % (len(name), name)
marcozecchini 0:9fca2b23d0ba 255
marcozecchini 0:9fca2b23d0ba 256 @staticmethod
marcozecchini 0:9fca2b23d0ba 257 def make_ld_define(name, value):
marcozecchini 0:9fca2b23d0ba 258 return "--predefine=\"-D%s=0x%x\"" % (name, value)
marcozecchini 0:9fca2b23d0ba 259
marcozecchini 0:9fca2b23d0ba 260 @staticmethod
marcozecchini 0:9fca2b23d0ba 261 def redirect_symbol(source, sync, build_dir):
marcozecchini 0:9fca2b23d0ba 262 if not exists(build_dir):
marcozecchini 0:9fca2b23d0ba 263 makedirs(build_dir)
marcozecchini 0:9fca2b23d0ba 264 handle, filename = mkstemp(prefix=".redirect-symbol.", dir=build_dir)
marcozecchini 0:9fca2b23d0ba 265 write(handle, "RESOLVE %s AS %s\n" % (source, sync))
marcozecchini 0:9fca2b23d0ba 266 return "--edit=%s" % filename
marcozecchini 0:9fca2b23d0ba 267
marcozecchini 0:9fca2b23d0ba 268
marcozecchini 0:9fca2b23d0ba 269 class ARM_STD(ARM):
marcozecchini 0:9fca2b23d0ba 270 def __init__(self, target, notify=None, macros=None,
marcozecchini 0:9fca2b23d0ba 271 silent=False, extra_verbose=False, build_profile=None,
marcozecchini 0:9fca2b23d0ba 272 build_dir=None):
marcozecchini 0:9fca2b23d0ba 273 ARM.__init__(self, target, notify, macros, silent,
marcozecchini 0:9fca2b23d0ba 274 build_dir=build_dir, extra_verbose=extra_verbose,
marcozecchini 0:9fca2b23d0ba 275 build_profile=build_profile)
marcozecchini 0:9fca2b23d0ba 276 if "ARM" not in target.supported_toolchains:
marcozecchini 0:9fca2b23d0ba 277 raise NotSupportedException("ARM compiler support is required for ARM build")
marcozecchini 0:9fca2b23d0ba 278
marcozecchini 0:9fca2b23d0ba 279
marcozecchini 0:9fca2b23d0ba 280 class ARM_MICRO(ARM):
marcozecchini 0:9fca2b23d0ba 281 PATCHED_LIBRARY = False
marcozecchini 0:9fca2b23d0ba 282 def __init__(self, target, notify=None, macros=None,
marcozecchini 0:9fca2b23d0ba 283 silent=False, extra_verbose=False, build_profile=None,
marcozecchini 0:9fca2b23d0ba 284 build_dir=None):
marcozecchini 0:9fca2b23d0ba 285 ARM.__init__(self, target, notify, macros, silent,
marcozecchini 0:9fca2b23d0ba 286 build_dir=build_dir, extra_verbose=extra_verbose,
marcozecchini 0:9fca2b23d0ba 287 build_profile=build_profile)
marcozecchini 0:9fca2b23d0ba 288 if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
marcozecchini 0:9fca2b23d0ba 289 raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
marcozecchini 0:9fca2b23d0ba 290
marcozecchini 0:9fca2b23d0ba 291 class ARMC6(ARM_STD):
marcozecchini 0:9fca2b23d0ba 292 SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c"
marcozecchini 0:9fca2b23d0ba 293 SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
marcozecchini 0:9fca2b23d0ba 294 "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
marcozecchini 0:9fca2b23d0ba 295 "Cortex-M23", "Cortex-M23-NS", "Cortex-M33",
marcozecchini 0:9fca2b23d0ba 296 "CortexM33-NS"]
marcozecchini 0:9fca2b23d0ba 297 @staticmethod
marcozecchini 0:9fca2b23d0ba 298 def check_executable():
marcozecchini 0:9fca2b23d0ba 299 return mbedToolchain.generic_check_executable("ARMC6", "armclang", 1)
marcozecchini 0:9fca2b23d0ba 300
marcozecchini 0:9fca2b23d0ba 301 def __init__(self, target, *args, **kwargs):
marcozecchini 0:9fca2b23d0ba 302 mbedToolchain.__init__(self, target, *args, **kwargs)
marcozecchini 0:9fca2b23d0ba 303 if target.core not in self.SUPPORTED_CORES:
marcozecchini 0:9fca2b23d0ba 304 raise NotSupportedException(
marcozecchini 0:9fca2b23d0ba 305 "this compiler does not support the core %s" % target.core)
marcozecchini 0:9fca2b23d0ba 306
marcozecchini 0:9fca2b23d0ba 307 if not set(("ARM", "ARMC6")).intersection(set(target.supported_toolchains)):
marcozecchini 0:9fca2b23d0ba 308 raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build")
marcozecchini 0:9fca2b23d0ba 309
marcozecchini 0:9fca2b23d0ba 310 if target.core.lower().endswith("fd"):
marcozecchini 0:9fca2b23d0ba 311 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-2])
marcozecchini 0:9fca2b23d0ba 312 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-2])
marcozecchini 0:9fca2b23d0ba 313 elif target.core.lower().endswith("f"):
marcozecchini 0:9fca2b23d0ba 314 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-1])
marcozecchini 0:9fca2b23d0ba 315 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-1])
marcozecchini 0:9fca2b23d0ba 316 elif target.core.lower().endswith("ns"):
marcozecchini 0:9fca2b23d0ba 317 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-3])
marcozecchini 0:9fca2b23d0ba 318 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-3])
marcozecchini 0:9fca2b23d0ba 319 else:
marcozecchini 0:9fca2b23d0ba 320 self.flags['common'].append("-mcpu=%s" % target.core.lower())
marcozecchini 0:9fca2b23d0ba 321 self.flags['ld'].append("--cpu=%s" % target.core.lower())
marcozecchini 0:9fca2b23d0ba 322
marcozecchini 0:9fca2b23d0ba 323 if target.core == "Cortex-M4F":
marcozecchini 0:9fca2b23d0ba 324 self.flags['common'].append("-mfpu=fpv4-sp-d16")
marcozecchini 0:9fca2b23d0ba 325 self.flags['common'].append("-mfloat-abi=hard")
marcozecchini 0:9fca2b23d0ba 326 elif target.core == "Cortex-M7F":
marcozecchini 0:9fca2b23d0ba 327 self.flags['common'].append("-mfpu=fpv5-sp-d16")
marcozecchini 0:9fca2b23d0ba 328 self.flags['common'].append("-mfloat-abi=softfp")
marcozecchini 0:9fca2b23d0ba 329 elif target.core == "Cortex-M7FD":
marcozecchini 0:9fca2b23d0ba 330 self.flags['common'].append("-mfpu=fpv5-d16")
marcozecchini 0:9fca2b23d0ba 331 self.flags['common'].append("-mfloat-abi=softfp")
marcozecchini 0:9fca2b23d0ba 332 elif target.core.startswith("Cortex-M23"):
marcozecchini 0:9fca2b23d0ba 333 self.flags['common'].append("-march=armv8-m.base")
marcozecchini 0:9fca2b23d0ba 334 elif target.core.startswith("Cortex-M33"):
marcozecchini 0:9fca2b23d0ba 335 self.flags['common'].append("-march=armv8-m.main")
marcozecchini 0:9fca2b23d0ba 336
marcozecchini 0:9fca2b23d0ba 337 if target.core == "Cortex-M23" or target.core == "Cortex-M33":
marcozecchini 0:9fca2b23d0ba 338 self.flags['common'].append("-mcmse")
marcozecchini 0:9fca2b23d0ba 339
marcozecchini 0:9fca2b23d0ba 340 asm_cpu = {
marcozecchini 0:9fca2b23d0ba 341 "Cortex-M0+": "Cortex-M0",
marcozecchini 0:9fca2b23d0ba 342 "Cortex-M4F": "Cortex-M4.fp",
marcozecchini 0:9fca2b23d0ba 343 "Cortex-M7F": "Cortex-M7.fp.sp",
marcozecchini 0:9fca2b23d0ba 344 "Cortex-M7FD": "Cortex-M7.fp.dp",
marcozecchini 0:9fca2b23d0ba 345 "Cortex-M23-NS": "Cortex-M23",
marcozecchini 0:9fca2b23d0ba 346 "Cortex-M33-NS": "Cortex-M33" }.get(target.core, target.core)
marcozecchini 0:9fca2b23d0ba 347
marcozecchini 0:9fca2b23d0ba 348 self.flags['asm'].append("--cpu=%s" % asm_cpu)
marcozecchini 0:9fca2b23d0ba 349
marcozecchini 0:9fca2b23d0ba 350 self.cc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] +
marcozecchini 0:9fca2b23d0ba 351 self.flags['common'] + self.flags['c'])
marcozecchini 0:9fca2b23d0ba 352 self.cppc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] +
marcozecchini 0:9fca2b23d0ba 353 self.flags['common'] + self.flags['cxx'])
marcozecchini 0:9fca2b23d0ba 354 self.asm = [join(TOOLCHAIN_PATHS["ARMC6"], "armasm")] + self.flags['asm']
marcozecchini 0:9fca2b23d0ba 355 self.ld = [join(TOOLCHAIN_PATHS["ARMC6"], "armlink")] + self.flags['ld']
marcozecchini 0:9fca2b23d0ba 356 self.ar = [join(TOOLCHAIN_PATHS["ARMC6"], "armar")]
marcozecchini 0:9fca2b23d0ba 357 self.elf2bin = join(TOOLCHAIN_PATHS["ARMC6"], "fromelf")
marcozecchini 0:9fca2b23d0ba 358
marcozecchini 0:9fca2b23d0ba 359
marcozecchini 0:9fca2b23d0ba 360 def parse_dependencies(self, dep_path):
marcozecchini 0:9fca2b23d0ba 361 return mbedToolchain.parse_dependencies(self, dep_path)
marcozecchini 0:9fca2b23d0ba 362
marcozecchini 0:9fca2b23d0ba 363 def is_not_supported_error(self, output):
marcozecchini 0:9fca2b23d0ba 364 return "#error [NOT_SUPPORTED]" in output
marcozecchini 0:9fca2b23d0ba 365
marcozecchini 0:9fca2b23d0ba 366 def parse_output(self, output):
marcozecchini 0:9fca2b23d0ba 367 pass
marcozecchini 0:9fca2b23d0ba 368
marcozecchini 0:9fca2b23d0ba 369 def get_config_option(self, config_header):
marcozecchini 0:9fca2b23d0ba 370 return ["-include", config_header]
marcozecchini 0:9fca2b23d0ba 371
marcozecchini 0:9fca2b23d0ba 372 def get_compile_options(self, defines, includes, for_asm=False):
marcozecchini 0:9fca2b23d0ba 373 opts = ['-D%s' % d for d in defines]
marcozecchini 0:9fca2b23d0ba 374 opts.extend(["-I%s" % i for i in includes])
marcozecchini 0:9fca2b23d0ba 375 if for_asm:
marcozecchini 0:9fca2b23d0ba 376 return ["--cpreproc",
marcozecchini 0:9fca2b23d0ba 377 "--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)]
marcozecchini 0:9fca2b23d0ba 378 else:
marcozecchini 0:9fca2b23d0ba 379 config_header = self.get_config_header()
marcozecchini 0:9fca2b23d0ba 380 if config_header:
marcozecchini 0:9fca2b23d0ba 381 opts.extend(self.get_config_option(config_header))
marcozecchini 0:9fca2b23d0ba 382 return opts
marcozecchini 0:9fca2b23d0ba 383
marcozecchini 0:9fca2b23d0ba 384 @hook_tool
marcozecchini 0:9fca2b23d0ba 385 def assemble(self, source, object, includes):
marcozecchini 0:9fca2b23d0ba 386 cmd_pre = copy(self.asm)
marcozecchini 0:9fca2b23d0ba 387 cmd_pre.extend(self.get_compile_options(
marcozecchini 0:9fca2b23d0ba 388 self.get_symbols(True), includes, for_asm=True))
marcozecchini 0:9fca2b23d0ba 389 cmd_pre.extend(["-o", object, source])
marcozecchini 0:9fca2b23d0ba 390 return [self.hook.get_cmdline_assembler(cmd_pre)]
marcozecchini 0:9fca2b23d0ba 391
marcozecchini 0:9fca2b23d0ba 392 @hook_tool
marcozecchini 0:9fca2b23d0ba 393 def compile(self, cc, source, object, includes):
marcozecchini 0:9fca2b23d0ba 394 cmd = copy(cc)
marcozecchini 0:9fca2b23d0ba 395 cmd.extend(self.get_compile_options(self.get_symbols(), includes))
marcozecchini 0:9fca2b23d0ba 396 cmd.extend(["-o", object, source])
marcozecchini 0:9fca2b23d0ba 397 cmd = self.hook.get_cmdline_compiler(cmd)
marcozecchini 0:9fca2b23d0ba 398 return [cmd]