dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
nexpaq
Date:
Sat Sep 17 16:32:05 2016 +0000
Revision:
1:55a6170b404f
checking in for sharing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 1:55a6170b404f 1 """
nexpaq 1:55a6170b404f 2 mbed SDK
nexpaq 1:55a6170b404f 3 Copyright (c) 2011-2013 ARM Limited
nexpaq 1:55a6170b404f 4
nexpaq 1:55a6170b404f 5 Licensed under the Apache License, Version 2.0 (the "License");
nexpaq 1:55a6170b404f 6 you may not use this file except in compliance with the License.
nexpaq 1:55a6170b404f 7 You may obtain a copy of the License at
nexpaq 1:55a6170b404f 8
nexpaq 1:55a6170b404f 9 http://www.apache.org/licenses/LICENSE-2.0
nexpaq 1:55a6170b404f 10
nexpaq 1:55a6170b404f 11 Unless required by applicable law or agreed to in writing, software
nexpaq 1:55a6170b404f 12 distributed under the License is distributed on an "AS IS" BASIS,
nexpaq 1:55a6170b404f 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nexpaq 1:55a6170b404f 14 See the License for the specific language governing permissions and
nexpaq 1:55a6170b404f 15 limitations under the License.
nexpaq 1:55a6170b404f 16 """
nexpaq 1:55a6170b404f 17 import re
nexpaq 1:55a6170b404f 18 from os.path import join, dirname, splitext, basename
nexpaq 1:55a6170b404f 19 from distutils.spawn import find_executable
nexpaq 1:55a6170b404f 20
nexpaq 1:55a6170b404f 21 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
nexpaq 1:55a6170b404f 22 from tools.hooks import hook_tool
nexpaq 1:55a6170b404f 23 from tools.utils import mkdir
nexpaq 1:55a6170b404f 24
nexpaq 1:55a6170b404f 25 class ARM(mbedToolchain):
nexpaq 1:55a6170b404f 26 LINKER_EXT = '.sct'
nexpaq 1:55a6170b404f 27 LIBRARY_EXT = '.ar'
nexpaq 1:55a6170b404f 28
nexpaq 1:55a6170b404f 29 STD_LIB_NAME = "%s.ar"
nexpaq 1:55a6170b404f 30 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error): (?P<message>.+)')
nexpaq 1:55a6170b404f 31 INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
nexpaq 1:55a6170b404f 32 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
nexpaq 1:55a6170b404f 33
nexpaq 1:55a6170b404f 34
nexpaq 1:55a6170b404f 35 DEFAULT_FLAGS = {
nexpaq 1:55a6170b404f 36 'common': ["-c", "--gnu",
nexpaq 1:55a6170b404f 37 "-Otime", "--split_sections", "--apcs=interwork",
nexpaq 1:55a6170b404f 38 "--brief_diagnostics", "--restrict", "--multibyte_chars"],
nexpaq 1:55a6170b404f 39 'asm': [],
nexpaq 1:55a6170b404f 40 'c': ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"],
nexpaq 1:55a6170b404f 41 'cxx': ["--cpp", "--no_rtti", "--no_vla"],
nexpaq 1:55a6170b404f 42 'ld': [],
nexpaq 1:55a6170b404f 43 }
nexpaq 1:55a6170b404f 44
nexpaq 1:55a6170b404f 45 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
nexpaq 1:55a6170b404f 46 mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
nexpaq 1:55a6170b404f 47
nexpaq 1:55a6170b404f 48 if target.core == "Cortex-M0+":
nexpaq 1:55a6170b404f 49 cpu = "Cortex-M0"
nexpaq 1:55a6170b404f 50 elif target.core == "Cortex-M4F":
nexpaq 1:55a6170b404f 51 cpu = "Cortex-M4.fp"
nexpaq 1:55a6170b404f 52 elif target.core == "Cortex-M7FD":
nexpaq 1:55a6170b404f 53 cpu = "Cortex-M7.fp.dp"
nexpaq 1:55a6170b404f 54 elif target.core == "Cortex-M7F":
nexpaq 1:55a6170b404f 55 cpu = "Cortex-M7.fp.sp"
nexpaq 1:55a6170b404f 56 else:
nexpaq 1:55a6170b404f 57 cpu = target.core
nexpaq 1:55a6170b404f 58
nexpaq 1:55a6170b404f 59 if not TOOLCHAIN_PATHS['ARM']:
nexpaq 1:55a6170b404f 60 exe = find_executable('armcc')
nexpaq 1:55a6170b404f 61 if exe:
nexpaq 1:55a6170b404f 62 TOOLCHAIN_PATHS['ARM'] = dirname(dirname(exe))
nexpaq 1:55a6170b404f 63
nexpaq 1:55a6170b404f 64 ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
nexpaq 1:55a6170b404f 65 ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
nexpaq 1:55a6170b404f 66
nexpaq 1:55a6170b404f 67 main_cc = join(ARM_BIN, "armcc")
nexpaq 1:55a6170b404f 68
nexpaq 1:55a6170b404f 69 self.flags['common'] += ["--cpu=%s" % cpu]
nexpaq 1:55a6170b404f 70 if "save-asm" in self.options:
nexpaq 1:55a6170b404f 71 self.flags['common'].extend(["--asm", "--interleave"])
nexpaq 1:55a6170b404f 72
nexpaq 1:55a6170b404f 73 if "debug-info" in self.options:
nexpaq 1:55a6170b404f 74 self.flags['common'].append("-g")
nexpaq 1:55a6170b404f 75 self.flags['c'].append("-O0")
nexpaq 1:55a6170b404f 76 else:
nexpaq 1:55a6170b404f 77 self.flags['c'].append("-O3")
nexpaq 1:55a6170b404f 78
nexpaq 1:55a6170b404f 79 self.asm = [main_cc] + self.flags['common'] + self.flags['asm'] + ["-I \""+ARM_INC+"\""]
nexpaq 1:55a6170b404f 80 self.cc = [main_cc] + self.flags['common'] + self.flags['c'] + ["-I \""+ARM_INC+"\""]
nexpaq 1:55a6170b404f 81 self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx'] + ["-I \""+ARM_INC+"\""]
nexpaq 1:55a6170b404f 82
nexpaq 1:55a6170b404f 83 self.ld = [join(ARM_BIN, "armlink")]
nexpaq 1:55a6170b404f 84 self.sys_libs = []
nexpaq 1:55a6170b404f 85
nexpaq 1:55a6170b404f 86 self.ar = join(ARM_BIN, "armar")
nexpaq 1:55a6170b404f 87 self.elf2bin = join(ARM_BIN, "fromelf")
nexpaq 1:55a6170b404f 88
nexpaq 1:55a6170b404f 89 self.toolchain_path = TOOLCHAIN_PATHS['ARM']
nexpaq 1:55a6170b404f 90
nexpaq 1:55a6170b404f 91 def parse_dependencies(self, dep_path):
nexpaq 1:55a6170b404f 92 dependencies = []
nexpaq 1:55a6170b404f 93 for line in open(dep_path).readlines():
nexpaq 1:55a6170b404f 94 match = ARM.DEP_PATTERN.match(line)
nexpaq 1:55a6170b404f 95 if match is not None:
nexpaq 1:55a6170b404f 96 #we need to append chroot, because when the .d files are generated the compiler is chrooted
nexpaq 1:55a6170b404f 97 dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file'))
nexpaq 1:55a6170b404f 98 return dependencies
nexpaq 1:55a6170b404f 99
nexpaq 1:55a6170b404f 100 def parse_output(self, output):
nexpaq 1:55a6170b404f 101 msg = None
nexpaq 1:55a6170b404f 102 for line in output.splitlines():
nexpaq 1:55a6170b404f 103 match = ARM.DIAGNOSTIC_PATTERN.match(line)
nexpaq 1:55a6170b404f 104 if match is not None:
nexpaq 1:55a6170b404f 105 if msg is not None:
nexpaq 1:55a6170b404f 106 self.cc_info(msg)
nexpaq 1:55a6170b404f 107 msg = {
nexpaq 1:55a6170b404f 108 'severity': match.group('severity').lower(),
nexpaq 1:55a6170b404f 109 'file': match.group('file'),
nexpaq 1:55a6170b404f 110 'line': match.group('line'),
nexpaq 1:55a6170b404f 111 'col': match.group('column') if match.group('column') else 0,
nexpaq 1:55a6170b404f 112 'message': match.group('message'),
nexpaq 1:55a6170b404f 113 'text': '',
nexpaq 1:55a6170b404f 114 'target_name': self.target.name,
nexpaq 1:55a6170b404f 115 'toolchain_name': self.name
nexpaq 1:55a6170b404f 116 }
nexpaq 1:55a6170b404f 117 elif msg is not None:
nexpaq 1:55a6170b404f 118 # Determine the warning/error column by calculating the ^ position
nexpaq 1:55a6170b404f 119 match = ARM.INDEX_PATTERN.match(line)
nexpaq 1:55a6170b404f 120 if match is not None:
nexpaq 1:55a6170b404f 121 msg['col'] = len(match.group('col'))
nexpaq 1:55a6170b404f 122 self.cc_info(msg)
nexpaq 1:55a6170b404f 123 msg = None
nexpaq 1:55a6170b404f 124 else:
nexpaq 1:55a6170b404f 125 msg['text'] += line+"\n"
nexpaq 1:55a6170b404f 126
nexpaq 1:55a6170b404f 127 if msg is not None:
nexpaq 1:55a6170b404f 128 self.cc_info(msg)
nexpaq 1:55a6170b404f 129
nexpaq 1:55a6170b404f 130 def get_dep_option(self, object):
nexpaq 1:55a6170b404f 131 base, _ = splitext(object)
nexpaq 1:55a6170b404f 132 dep_path = base + '.d'
nexpaq 1:55a6170b404f 133 return ["--depend", dep_path]
nexpaq 1:55a6170b404f 134
nexpaq 1:55a6170b404f 135 def get_config_option(self, config_header):
nexpaq 1:55a6170b404f 136 return ['--preinclude=' + config_header]
nexpaq 1:55a6170b404f 137
nexpaq 1:55a6170b404f 138 def get_compile_options(self, defines, includes, for_asm=False):
nexpaq 1:55a6170b404f 139 opts = ['-D%s' % d for d in defines]
nexpaq 1:55a6170b404f 140 if self.RESPONSE_FILES:
nexpaq 1:55a6170b404f 141 opts += ['--via', self.get_inc_file(includes)]
nexpaq 1:55a6170b404f 142 else:
nexpaq 1:55a6170b404f 143 opts += ["-I%s" % i for i in includes]
nexpaq 1:55a6170b404f 144
nexpaq 1:55a6170b404f 145 if not for_asm:
nexpaq 1:55a6170b404f 146 config_header = self.get_config_header()
nexpaq 1:55a6170b404f 147 if config_header is not None:
nexpaq 1:55a6170b404f 148 opts = opts + self.get_config_option(config_header)
nexpaq 1:55a6170b404f 149 return opts
nexpaq 1:55a6170b404f 150
nexpaq 1:55a6170b404f 151 @hook_tool
nexpaq 1:55a6170b404f 152 def assemble(self, source, object, includes):
nexpaq 1:55a6170b404f 153 # Preprocess first, then assemble
nexpaq 1:55a6170b404f 154 dir = join(dirname(object), '.temp')
nexpaq 1:55a6170b404f 155 mkdir(dir)
nexpaq 1:55a6170b404f 156 tempfile = join(dir, basename(object) + '.E.s')
nexpaq 1:55a6170b404f 157
nexpaq 1:55a6170b404f 158 # Build preprocess assemble command
nexpaq 1:55a6170b404f 159 cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]
nexpaq 1:55a6170b404f 160
nexpaq 1:55a6170b404f 161 # Build main assemble command
nexpaq 1:55a6170b404f 162 cmd = self.asm + ["-o", object, tempfile]
nexpaq 1:55a6170b404f 163
nexpaq 1:55a6170b404f 164 # Call cmdline hook
nexpaq 1:55a6170b404f 165 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
nexpaq 1:55a6170b404f 166 cmd = self.hook.get_cmdline_assembler(cmd)
nexpaq 1:55a6170b404f 167
nexpaq 1:55a6170b404f 168 # Return command array, don't execute
nexpaq 1:55a6170b404f 169 return [cmd_pre, cmd]
nexpaq 1:55a6170b404f 170
nexpaq 1:55a6170b404f 171 @hook_tool
nexpaq 1:55a6170b404f 172 def compile(self, cc, source, object, includes):
nexpaq 1:55a6170b404f 173 # Build compile command
nexpaq 1:55a6170b404f 174 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
nexpaq 1:55a6170b404f 175
nexpaq 1:55a6170b404f 176 cmd.extend(self.get_dep_option(object))
nexpaq 1:55a6170b404f 177
nexpaq 1:55a6170b404f 178 cmd.extend(["-o", object, source])
nexpaq 1:55a6170b404f 179
nexpaq 1:55a6170b404f 180 # Call cmdline hook
nexpaq 1:55a6170b404f 181 cmd = self.hook.get_cmdline_compiler(cmd)
nexpaq 1:55a6170b404f 182
nexpaq 1:55a6170b404f 183 return [cmd]
nexpaq 1:55a6170b404f 184
nexpaq 1:55a6170b404f 185 def compile_c(self, source, object, includes):
nexpaq 1:55a6170b404f 186 return self.compile(self.cc, source, object, includes)
nexpaq 1:55a6170b404f 187
nexpaq 1:55a6170b404f 188 def compile_cpp(self, source, object, includes):
nexpaq 1:55a6170b404f 189 return self.compile(self.cppc, source, object, includes)
nexpaq 1:55a6170b404f 190
nexpaq 1:55a6170b404f 191 @hook_tool
nexpaq 1:55a6170b404f 192 def link(self, output, objects, libraries, lib_dirs, mem_map):
nexpaq 1:55a6170b404f 193 map_file = splitext(output)[0] + ".map"
nexpaq 1:55a6170b404f 194 if len(lib_dirs):
nexpaq 1:55a6170b404f 195 args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--map", "--list=%s" % map_file]
nexpaq 1:55a6170b404f 196 else:
nexpaq 1:55a6170b404f 197 args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
nexpaq 1:55a6170b404f 198
nexpaq 1:55a6170b404f 199 if mem_map:
nexpaq 1:55a6170b404f 200 args.extend(["--scatter", mem_map])
nexpaq 1:55a6170b404f 201
nexpaq 1:55a6170b404f 202 # Build linker command
nexpaq 1:55a6170b404f 203 cmd = self.ld + args + objects + libraries + self.sys_libs
nexpaq 1:55a6170b404f 204
nexpaq 1:55a6170b404f 205 # Call cmdline hook
nexpaq 1:55a6170b404f 206 cmd = self.hook.get_cmdline_linker(cmd)
nexpaq 1:55a6170b404f 207
nexpaq 1:55a6170b404f 208 if self.RESPONSE_FILES:
nexpaq 1:55a6170b404f 209 # Split link command to linker executable + response file
nexpaq 1:55a6170b404f 210 cmd_linker = cmd[0]
nexpaq 1:55a6170b404f 211 link_files = self.get_link_file(cmd[1:])
nexpaq 1:55a6170b404f 212 cmd = [cmd_linker, '--via', link_files]
nexpaq 1:55a6170b404f 213
nexpaq 1:55a6170b404f 214 # Exec command
nexpaq 1:55a6170b404f 215 self.cc_verbose("Link: %s" % ' '.join(cmd))
nexpaq 1:55a6170b404f 216 self.default_cmd(cmd)
nexpaq 1:55a6170b404f 217
nexpaq 1:55a6170b404f 218 @hook_tool
nexpaq 1:55a6170b404f 219 def archive(self, objects, lib_path):
nexpaq 1:55a6170b404f 220 if self.RESPONSE_FILES:
nexpaq 1:55a6170b404f 221 param = ['--via', self.get_arch_file(objects)]
nexpaq 1:55a6170b404f 222 else:
nexpaq 1:55a6170b404f 223 param = objects
nexpaq 1:55a6170b404f 224
nexpaq 1:55a6170b404f 225 # Exec command
nexpaq 1:55a6170b404f 226 self.default_cmd([self.ar, '-r', lib_path] + param)
nexpaq 1:55a6170b404f 227
nexpaq 1:55a6170b404f 228 @hook_tool
nexpaq 1:55a6170b404f 229 def binary(self, resources, elf, bin):
nexpaq 1:55a6170b404f 230 # Build binary command
nexpaq 1:55a6170b404f 231 cmd = [self.elf2bin, '--bin', '-o', bin, elf]
nexpaq 1:55a6170b404f 232
nexpaq 1:55a6170b404f 233 # Call cmdline hook
nexpaq 1:55a6170b404f 234 cmd = self.hook.get_cmdline_binary(cmd)
nexpaq 1:55a6170b404f 235
nexpaq 1:55a6170b404f 236 # Exec command
nexpaq 1:55a6170b404f 237 self.cc_verbose("FromELF: %s" % ' '.join(cmd))
nexpaq 1:55a6170b404f 238 self.default_cmd(cmd)
nexpaq 1:55a6170b404f 239
nexpaq 1:55a6170b404f 240
nexpaq 1:55a6170b404f 241 class ARM_STD(ARM):
nexpaq 1:55a6170b404f 242 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
nexpaq 1:55a6170b404f 243 ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
nexpaq 1:55a6170b404f 244
nexpaq 1:55a6170b404f 245 # Run-time values
nexpaq 1:55a6170b404f 246 self.ld.extend(["--libpath", join(TOOLCHAIN_PATHS['ARM'], "lib")])
nexpaq 1:55a6170b404f 247
nexpaq 1:55a6170b404f 248
nexpaq 1:55a6170b404f 249 class ARM_MICRO(ARM):
nexpaq 1:55a6170b404f 250 PATCHED_LIBRARY = False
nexpaq 1:55a6170b404f 251
nexpaq 1:55a6170b404f 252 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
nexpaq 1:55a6170b404f 253 ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
nexpaq 1:55a6170b404f 254
nexpaq 1:55a6170b404f 255 # Extend flags
nexpaq 1:55a6170b404f 256 self.flags['common'].extend(["-D__MICROLIB"])
nexpaq 1:55a6170b404f 257 self.flags['c'].extend(["--library_type=microlib"])
nexpaq 1:55a6170b404f 258 self.flags['ld'].extend(["--library_type=microlib"])
nexpaq 1:55a6170b404f 259
nexpaq 1:55a6170b404f 260 # Run-time values
nexpaq 1:55a6170b404f 261 self.asm += ["-D__MICROLIB"]
nexpaq 1:55a6170b404f 262 self.cc += ["-D__MICROLIB", "--library_type=microlib"]
nexpaq 1:55a6170b404f 263 self.cppc += ["-D__MICROLIB", "--library_type=microlib"]
nexpaq 1:55a6170b404f 264 self.ld += ["--library_type=microlib"]
nexpaq 1:55a6170b404f 265
nexpaq 1:55a6170b404f 266 # Only allow a single thread
nexpaq 1:55a6170b404f 267 self.cc += ["-DMBED_RTOS_SINGLE_THREAD"]
nexpaq 1:55a6170b404f 268 self.cppc += ["-DMBED_RTOS_SINGLE_THREAD"]
nexpaq 1:55a6170b404f 269
nexpaq 1:55a6170b404f 270 # We had to patch microlib to add C++ support
nexpaq 1:55a6170b404f 271 # In later releases this patch should have entered mainline
nexpaq 1:55a6170b404f 272 if ARM_MICRO.PATCHED_LIBRARY:
nexpaq 1:55a6170b404f 273 # Run-time values
nexpaq 1:55a6170b404f 274 self.flags['ld'].extend(["--noscanlib"])
nexpaq 1:55a6170b404f 275 # Run-time values
nexpaq 1:55a6170b404f 276 self.ld += ["--noscanlib"]
nexpaq 1:55a6170b404f 277
nexpaq 1:55a6170b404f 278 # System Libraries
nexpaq 1:55a6170b404f 279 self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "microlib", lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]])
nexpaq 1:55a6170b404f 280
nexpaq 1:55a6170b404f 281 if target.core == "Cortex-M3":
nexpaq 1:55a6170b404f 282 self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "cpplib", lib+".l") for lib in ["cpp_ws", "cpprt_w"]])
nexpaq 1:55a6170b404f 283
nexpaq 1:55a6170b404f 284 elif target.core in ["Cortex-M0", "Cortex-M0+"]:
nexpaq 1:55a6170b404f 285 self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "cpplib", lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
nexpaq 1:55a6170b404f 286 else:
nexpaq 1:55a6170b404f 287 # Run-time values
nexpaq 1:55a6170b404f 288 self.ld.extend(["--libpath", join(TOOLCHAIN_PATHS['ARM'], "lib")])