Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
arm.py
00001 """ 00002 mbed SDK 00003 Copyright (c) 2011-2013 ARM Limited 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 """ 00017 import re 00018 from os.path import join, dirname, splitext, basename 00019 from distutils.spawn import find_executable 00020 00021 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS 00022 from tools.hooks import hook_tool 00023 from tools.utils import mkdir 00024 00025 class ARM(mbedToolchain): 00026 LINKER_EXT = '.sct' 00027 LIBRARY_EXT = '.ar' 00028 00029 STD_LIB_NAME = "%s.ar" 00030 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error): (?P<message>.+)') 00031 INDEX_PATTERN = re.compile('(?P<col>\s*)\^') 00032 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n') 00033 00034 00035 DEFAULT_FLAGS = { 00036 'common': ["-c", "--gnu", 00037 "-Otime", "--split_sections", "--apcs=interwork", 00038 "--brief_diagnostics", "--restrict", "--multibyte_chars"], 00039 'asm': [], 00040 'c': ["--md", "--no_depend_system_headers", "--c99", "-D__ASSERT_MSG"], 00041 'cxx': ["--cpp", "--no_rtti", "--no_vla"], 00042 'ld': [], 00043 } 00044 00045 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False): 00046 mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose) 00047 00048 if target.core == "Cortex-M0+": 00049 cpu = "Cortex-M0" 00050 elif target.core == "Cortex-M4F": 00051 cpu = "Cortex-M4.fp" 00052 elif target.core == "Cortex-M7FD": 00053 cpu = "Cortex-M7.fp.dp" 00054 elif target.core == "Cortex-M7F": 00055 cpu = "Cortex-M7.fp.sp" 00056 else: 00057 cpu = target.core 00058 00059 if not TOOLCHAIN_PATHS['ARM']: 00060 exe = find_executable('armcc') 00061 if exe: 00062 TOOLCHAIN_PATHS['ARM'] = dirname(dirname(exe)) 00063 00064 ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin") 00065 ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include") 00066 00067 main_cc = join(ARM_BIN, "armcc") 00068 00069 self.flags['common'] += ["--cpu=%s" % cpu] 00070 if "save-asm" in self.options: 00071 self.flags['common'].extend(["--asm", "--interleave"]) 00072 00073 if "debug-info" in self.options: 00074 self.flags['common'].append("-g") 00075 self.flags['c'].append("-O0") 00076 else: 00077 self.flags['c'].append("-O3") 00078 00079 self.asm = [main_cc] + self.flags['common'] + self.flags['asm'] + ["-I \""+ARM_INC+"\""] 00080 self.cc = [main_cc] + self.flags['common'] + self.flags['c'] + ["-I \""+ARM_INC+"\""] 00081 self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx'] + ["-I \""+ARM_INC+"\""] 00082 00083 self.ld = [join(ARM_BIN, "armlink")] 00084 self.sys_libs = [] 00085 00086 self.ar = join(ARM_BIN, "armar") 00087 self.elf2bin = join(ARM_BIN, "fromelf") 00088 00089 self.toolchain_path = TOOLCHAIN_PATHS['ARM'] 00090 00091 def parse_dependencies(self, dep_path): 00092 dependencies = [] 00093 for line in open(dep_path).readlines(): 00094 match = ARM.DEP_PATTERN.match(line) 00095 if match is not None: 00096 #we need to append chroot, because when the .d files are generated the compiler is chrooted 00097 dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file')) 00098 return dependencies 00099 00100 def parse_output(self, output): 00101 msg = None 00102 for line in output.splitlines(): 00103 match = ARM.DIAGNOSTIC_PATTERN.match(line) 00104 if match is not None: 00105 if msg is not None: 00106 self.cc_info(msg) 00107 msg = { 00108 'severity': match.group('severity').lower(), 00109 'file': match.group('file'), 00110 'line': match.group('line'), 00111 'col': match.group('column') if match.group('column') else 0, 00112 'message': match.group('message'), 00113 'text': '', 00114 'target_name': self.target.name, 00115 'toolchain_name': self.name 00116 } 00117 elif msg is not None: 00118 # Determine the warning/error column by calculating the ^ position 00119 match = ARM.INDEX_PATTERN.match(line) 00120 if match is not None: 00121 msg['col'] = len(match.group('col')) 00122 self.cc_info(msg) 00123 msg = None 00124 else: 00125 msg['text'] += line+"\n" 00126 00127 if msg is not None: 00128 self.cc_info(msg) 00129 00130 def get_dep_option(self, object): 00131 base, _ = splitext(object) 00132 dep_path = base + '.d' 00133 return ["--depend", dep_path] 00134 00135 def get_config_option(self, config_header): 00136 return ['--preinclude=' + config_header] 00137 00138 def get_compile_options(self, defines, includes, for_asm=False): 00139 opts = ['-D%s' % d for d in defines] 00140 if self.RESPONSE_FILES: 00141 opts += ['--via', self.get_inc_file(includes)] 00142 else: 00143 opts += ["-I%s" % i for i in includes] 00144 00145 if not for_asm: 00146 config_header = self.get_config_header() 00147 if config_header is not None: 00148 opts = opts + self.get_config_option(config_header) 00149 return opts 00150 00151 @hook_tool 00152 def assemble(self, source, object, includes): 00153 # Preprocess first, then assemble 00154 dir = join(dirname(object), '.temp') 00155 mkdir(dir) 00156 tempfile = join(dir, basename(object) + '.E.s') 00157 00158 # Build preprocess assemble command 00159 cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source] 00160 00161 # Build main assemble command 00162 cmd = self.asm + ["-o", object, tempfile] 00163 00164 # Call cmdline hook 00165 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre) 00166 cmd = self.hook.get_cmdline_assembler(cmd) 00167 00168 # Return command array, don't execute 00169 return [cmd_pre, cmd] 00170 00171 @hook_tool 00172 def compile(self, cc, source, object, includes): 00173 # Build compile command 00174 cmd = cc + self.get_compile_options(self.get_symbols(), includes) 00175 00176 cmd.extend(self.get_dep_option(object)) 00177 00178 cmd.extend(["-o", object, source]) 00179 00180 # Call cmdline hook 00181 cmd = self.hook.get_cmdline_compiler(cmd) 00182 00183 return [cmd] 00184 00185 def compile_c(self, source, object, includes): 00186 return self.compile(self.cc, source, object, includes) 00187 00188 def compile_cpp(self, source, object, includes): 00189 return self.compile(self.cppc, source, object, includes) 00190 00191 @hook_tool 00192 def link(self, output, objects, libraries, lib_dirs, mem_map): 00193 map_file = splitext(output)[0] + ".map" 00194 if len(lib_dirs): 00195 args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--map", "--list=%s" % map_file] 00196 else: 00197 args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file] 00198 00199 if mem_map: 00200 args.extend(["--scatter", mem_map]) 00201 00202 # Build linker command 00203 cmd = self.ld + args + objects + libraries + self.sys_libs 00204 00205 # Call cmdline hook 00206 cmd = self.hook.get_cmdline_linker(cmd) 00207 00208 if self.RESPONSE_FILES: 00209 # Split link command to linker executable + response file 00210 cmd_linker = cmd[0] 00211 link_files = self.get_link_file(cmd[1:]) 00212 cmd = [cmd_linker, '--via', link_files] 00213 00214 # Exec command 00215 self.cc_verbose("Link: %s" % ' '.join(cmd)) 00216 self.default_cmd(cmd) 00217 00218 @hook_tool 00219 def archive(self, objects, lib_path): 00220 if self.RESPONSE_FILES: 00221 param = ['--via', self.get_arch_file(objects)] 00222 else: 00223 param = objects 00224 00225 # Exec command 00226 self.default_cmd([self.ar, '-r', lib_path] + param) 00227 00228 @hook_tool 00229 def binary(self, resources, elf, bin): 00230 # Build binary command 00231 cmd = [self.elf2bin, '--bin', '-o', bin, elf] 00232 00233 # Call cmdline hook 00234 cmd = self.hook.get_cmdline_binary(cmd) 00235 00236 # Exec command 00237 self.cc_verbose("FromELF: %s" % ' '.join(cmd)) 00238 self.default_cmd(cmd) 00239 00240 00241 class ARM_STD(ARM): 00242 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False): 00243 ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose) 00244 00245 # Run-time values 00246 self.ld.extend(["--libpath", join(TOOLCHAIN_PATHS['ARM'], "lib")]) 00247 00248 00249 class ARM_MICRO(ARM): 00250 PATCHED_LIBRARY = False 00251 00252 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False): 00253 ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose) 00254 00255 # Extend flags 00256 self.flags['common'].extend(["-D__MICROLIB"]) 00257 self.flags['c'].extend(["--library_type=microlib"]) 00258 self.flags['ld'].extend(["--library_type=microlib"]) 00259 00260 # Run-time values 00261 self.asm += ["-D__MICROLIB"] 00262 self.cc += ["-D__MICROLIB", "--library_type=microlib"] 00263 self.cppc += ["-D__MICROLIB", "--library_type=microlib"] 00264 self.ld += ["--library_type=microlib"] 00265 00266 # Only allow a single thread 00267 self.cc += ["-DMBED_RTOS_SINGLE_THREAD"] 00268 self.cppc += ["-DMBED_RTOS_SINGLE_THREAD"] 00269 00270 # We had to patch microlib to add C++ support 00271 # In later releases this patch should have entered mainline 00272 if ARM_MICRO.PATCHED_LIBRARY: 00273 # Run-time values 00274 self.flags['ld'].extend(["--noscanlib"]) 00275 # Run-time values 00276 self.ld += ["--noscanlib"] 00277 00278 # System Libraries 00279 self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "microlib", lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]]) 00280 00281 if target.core == "Cortex-M3": 00282 self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "cpplib", lib+".l") for lib in ["cpp_ws", "cpprt_w"]]) 00283 00284 elif target.core in ["Cortex-M0", "Cortex-M0+"]: 00285 self.sys_libs.extend([join(TOOLCHAIN_PATHS['ARM'], "lib", "cpplib", lib+".l") for lib in ["cpp_ps", "cpprt_p"]]) 00286 else: 00287 # Run-time values 00288 self.ld.extend(["--libpath", join(TOOLCHAIN_PATHS['ARM'], "lib")])
Generated on Tue Jul 12 2022 12:28:22 by
