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
iar.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 import remove 00019 from os.path import join, exists, dirname, splitext, exists 00020 from distutils.spawn import find_executable 00021 00022 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS 00023 from tools.hooks import hook_tool 00024 00025 class IAR(mbedToolchain): 00026 LIBRARY_EXT = '.a' 00027 LINKER_EXT = '.icf' 00028 STD_LIB_NAME = "%s.a" 00029 00030 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)') 00031 INDEX_PATTERN = re.compile('(?P<col>\s*)\^') 00032 00033 DEFAULT_FLAGS = { 00034 'common': [ 00035 "--no_wrap_diagnostics", 00036 # Pa050: No need to be notified about "non-native end of line sequence" 00037 # Pa084: Pointless integer comparison -> checks for the values of an enum, but we use values outside of the enum to notify errors (ie: NC). 00038 # Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85)) 00039 # Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0)) 00040 "-e", # Enable IAR language extension 00041 "--diag_suppress=Pa050,Pa084,Pa093,Pa082"], 00042 'asm': [], 00043 'c': ["--vla"], 00044 'cxx': ["--guard_calls"], 00045 'ld': ["--skip_dynamic_initialization", "--threaded_lib"], 00046 } 00047 00048 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False): 00049 mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose) 00050 if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD": 00051 cpuchoice = "Cortex-M7" 00052 else: 00053 cpuchoice = target.core 00054 00055 if not TOOLCHAIN_PATHS['IAR']: 00056 exe = find_executable('iccarm') 00057 if exe: 00058 TOOLCHAIN_PATHS['IAR'] = dirname(dirname(exe)) 00059 00060 # flags_cmd are used only by our scripts, the project files have them already defined, 00061 # using this flags results in the errors (duplication) 00062 # asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core 00063 if target.core == "Cortex-M4F": 00064 asm_flags_cmd = [ 00065 "--cpu", "Cortex-M4F" 00066 ] 00067 else: 00068 asm_flags_cmd = [ 00069 "--cpu", cpuchoice 00070 ] 00071 # custom c flags 00072 if target.core == "Cortex-M4F": 00073 c_flags_cmd = [ 00074 "--cpu", "Cortex-M4F", 00075 "--thumb", "--dlib_config", join(TOOLCHAIN_PATHS['IAR'], "inc", "c", "DLib_Config_Full.h") 00076 ] 00077 else: 00078 c_flags_cmd = [ 00079 "--cpu", cpuchoice, 00080 "--thumb", "--dlib_config", join(TOOLCHAIN_PATHS['IAR'], "inc", "c", "DLib_Config_Full.h") 00081 ] 00082 # custom c++ cmd flags 00083 cxx_flags_cmd = [ 00084 "--c++", "--no_rtti", "--no_exceptions" 00085 ] 00086 if target.core == "Cortex-M7FD": 00087 asm_flags_cmd += ["--fpu", "VFPv5"] 00088 c_flags_cmd.append("--fpu=VFPv5") 00089 elif target.core == "Cortex-M7F": 00090 asm_flags_cmd += ["--fpu", "VFPv5_sp"] 00091 c_flags_cmd.append("--fpu=VFPv5_sp") 00092 00093 if "debug-info" in self.options: 00094 c_flags_cmd.append("-r") 00095 c_flags_cmd.append("-On") 00096 else: 00097 c_flags_cmd.append("-Oh") 00098 00099 IAR_BIN = join(TOOLCHAIN_PATHS['IAR'], "bin") 00100 main_cc = join(IAR_BIN, "iccarm") 00101 00102 self.asm = [join(IAR_BIN, "iasmarm")] + asm_flags_cmd + self.flags["asm"] 00103 self.cc = [main_cc] 00104 self.cppc = [main_cc] 00105 self.cc += self.flags["common"] + c_flags_cmd + self.flags["c"] 00106 self.cppc += self.flags["common"] + c_flags_cmd + cxx_flags_cmd + self.flags["cxx"] 00107 self.ld = join(IAR_BIN, "ilinkarm") 00108 self.ar = join(IAR_BIN, "iarchive") 00109 self.elf2bin = join(IAR_BIN, "ielftool") 00110 00111 self.toolchain_path = TOOLCHAIN_PATHS['IAR'] 00112 00113 def parse_dependencies(self, dep_path): 00114 return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines() 00115 if (path and not path.isspace())] 00116 00117 def parse_output(self, output): 00118 msg = None 00119 for line in output.splitlines(): 00120 match = IAR.DIAGNOSTIC_PATTERN.match(line) 00121 if match is not None: 00122 if msg is not None: 00123 self.cc_info(msg) 00124 msg = { 00125 'severity': match.group('severity').lower(), 00126 'file': match.group('file'), 00127 'line': match.group('line'), 00128 'col': 0, 00129 'message': match.group('message'), 00130 'text': '', 00131 'target_name': self.target.name, 00132 'toolchain_name': self.name 00133 } 00134 elif msg is not None: 00135 # Determine the warning/error column by calculating the ^ position 00136 match = IAR.INDEX_PATTERN.match(line) 00137 if match is not None: 00138 msg['col'] = len(match.group('col')) 00139 self.cc_info(msg) 00140 msg = None 00141 else: 00142 msg['text'] += line+"\n" 00143 00144 def get_dep_option(self, object): 00145 base, _ = splitext(object) 00146 dep_path = base + '.d' 00147 return ["--dependencies", dep_path] 00148 00149 def cc_extra(self, object): 00150 base, _ = splitext(object) 00151 return ["-l", base + '.s.txt'] 00152 00153 def get_config_option(self, config_header): 00154 return ['--preinclude=' + config_header] 00155 00156 def get_compile_options(self, defines, includes, for_asm=False): 00157 opts = ['-D%s' % d for d in defines] 00158 if self.RESPONSE_FILES: 00159 opts += ['-f', self.get_inc_file(includes)] 00160 else: 00161 opts += ["-I%s" % i for i in includes] 00162 00163 if not for_asm: 00164 config_header = self.get_config_header() 00165 if config_header is not None: 00166 opts = opts + self.get_config_option(config_header) 00167 return opts 00168 00169 @hook_tool 00170 def assemble(self, source, object, includes): 00171 # Build assemble command 00172 cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes, True) + ["-o", object, source] 00173 00174 # Call cmdline hook 00175 cmd = self.hook.get_cmdline_assembler(cmd) 00176 00177 # Return command array, don't execute 00178 return [cmd] 00179 00180 @hook_tool 00181 def compile(self, cc, source, object, includes): 00182 # Build compile command 00183 cmd = cc + self.get_compile_options(self.get_symbols(), includes) 00184 00185 cmd.extend(self.get_dep_option(object)) 00186 00187 cmd.extend(self.cc_extra(object)) 00188 00189 cmd.extend(["-o", object, source]) 00190 00191 # Call cmdline hook 00192 cmd = self.hook.get_cmdline_compiler(cmd) 00193 00194 return [cmd] 00195 00196 def compile_c(self, source, object, includes): 00197 return self.compile(self.cc, source, object, includes) 00198 00199 def compile_cpp(self, source, object, includes): 00200 return self.compile(self.cppc, source, object, includes) 00201 00202 @hook_tool 00203 def link(self, output, objects, libraries, lib_dirs, mem_map): 00204 # Build linker command 00205 map_file = splitext(output)[0] + ".map" 00206 cmd = [self.ld, "-o", output, "--map=%s" % map_file] + objects + libraries + self.flags['ld'] 00207 00208 if mem_map: 00209 cmd.extend(["--config", mem_map]) 00210 00211 # Call cmdline hook 00212 cmd = self.hook.get_cmdline_linker(cmd) 00213 00214 if self.RESPONSE_FILES: 00215 # Split link command to linker executable + response file 00216 cmd_linker = cmd[0] 00217 link_files = self.get_link_file(cmd[1:]) 00218 cmd = [cmd_linker, '-f', link_files] 00219 00220 # Exec command 00221 self.cc_verbose("Link: %s" % ' '.join(cmd)) 00222 self.default_cmd(cmd) 00223 00224 @hook_tool 00225 def archive(self, objects, lib_path): 00226 if self.RESPONSE_FILES: 00227 param = ['-f', self.get_arch_file(objects)] 00228 else: 00229 param = objects 00230 00231 if exists(lib_path): 00232 remove(lib_path) 00233 00234 self.default_cmd([self.ar, lib_path] + param) 00235 00236 @hook_tool 00237 def binary(self, resources, elf, bin): 00238 # Build binary command 00239 cmd = [self.elf2bin, "--bin", elf, bin] 00240 00241 # Call cmdline hook 00242 cmd = self.hook.get_cmdline_binary(cmd) 00243 00244 # Exec command 00245 self.cc_verbose("FromELF: %s" % ' '.join(cmd)) 00246 self.default_cmd(cmd)
Generated on Tue Jul 12 2022 12:28:32 by
1.7.2
