Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
tools/toolchains/iar.py@3:1198227e6421, 2016-12-16 (annotated)
- Committer:
- switches
- Date:
- Fri Dec 16 16:27:57 2016 +0000
- Revision:
- 3:1198227e6421
- Parent:
- 0:5c4d7b2438d3
Changed ADC scale for MAX32625 platforms to 1.2V full scale to match MAX32630 platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:5c4d7b2438d3 | 1 | """ |
switches | 0:5c4d7b2438d3 | 2 | mbed SDK |
switches | 0:5c4d7b2438d3 | 3 | Copyright (c) 2011-2013 ARM Limited |
switches | 0:5c4d7b2438d3 | 4 | |
switches | 0:5c4d7b2438d3 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
switches | 0:5c4d7b2438d3 | 6 | you may not use this file except in compliance with the License. |
switches | 0:5c4d7b2438d3 | 7 | You may obtain a copy of the License at |
switches | 0:5c4d7b2438d3 | 8 | |
switches | 0:5c4d7b2438d3 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
switches | 0:5c4d7b2438d3 | 10 | |
switches | 0:5c4d7b2438d3 | 11 | Unless required by applicable law or agreed to in writing, software |
switches | 0:5c4d7b2438d3 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
switches | 0:5c4d7b2438d3 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
switches | 0:5c4d7b2438d3 | 14 | See the License for the specific language governing permissions and |
switches | 0:5c4d7b2438d3 | 15 | limitations under the License. |
switches | 0:5c4d7b2438d3 | 16 | """ |
switches | 0:5c4d7b2438d3 | 17 | import re |
switches | 0:5c4d7b2438d3 | 18 | from os import remove |
switches | 0:5c4d7b2438d3 | 19 | from os.path import join, splitext, exists |
switches | 0:5c4d7b2438d3 | 20 | |
switches | 0:5c4d7b2438d3 | 21 | from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS |
switches | 0:5c4d7b2438d3 | 22 | from tools.hooks import hook_tool |
switches | 0:5c4d7b2438d3 | 23 | |
switches | 0:5c4d7b2438d3 | 24 | class IAR(mbedToolchain): |
switches | 0:5c4d7b2438d3 | 25 | LIBRARY_EXT = '.a' |
switches | 0:5c4d7b2438d3 | 26 | LINKER_EXT = '.icf' |
switches | 0:5c4d7b2438d3 | 27 | STD_LIB_NAME = "%s.a" |
switches | 0:5c4d7b2438d3 | 28 | |
switches | 0:5c4d7b2438d3 | 29 | DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)') |
switches | 0:5c4d7b2438d3 | 30 | INDEX_PATTERN = re.compile('(?P<col>\s*)\^') |
switches | 0:5c4d7b2438d3 | 31 | |
switches | 0:5c4d7b2438d3 | 32 | @staticmethod |
switches | 0:5c4d7b2438d3 | 33 | def check_executable(): |
switches | 0:5c4d7b2438d3 | 34 | """Returns True if the executable (arm-none-eabi-gcc) location |
switches | 0:5c4d7b2438d3 | 35 | specified by the user exists OR the executable can be found on the PATH. |
switches | 0:5c4d7b2438d3 | 36 | Returns False otherwise.""" |
switches | 0:5c4d7b2438d3 | 37 | return mbedToolchain.generic_check_executable("IAR", 'iccarm', 2, "bin") |
switches | 0:5c4d7b2438d3 | 38 | |
switches | 0:5c4d7b2438d3 | 39 | def __init__(self, target, notify=None, macros=None, |
switches | 0:5c4d7b2438d3 | 40 | silent=False, extra_verbose=False, build_profile=None): |
switches | 0:5c4d7b2438d3 | 41 | mbedToolchain.__init__(self, target, notify, macros, silent, |
switches | 0:5c4d7b2438d3 | 42 | extra_verbose=extra_verbose, |
switches | 0:5c4d7b2438d3 | 43 | build_profile=build_profile) |
switches | 0:5c4d7b2438d3 | 44 | if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD": |
switches | 0:5c4d7b2438d3 | 45 | cpuchoice = "Cortex-M7" |
switches | 0:5c4d7b2438d3 | 46 | else: |
switches | 0:5c4d7b2438d3 | 47 | cpuchoice = target.core |
switches | 0:5c4d7b2438d3 | 48 | |
switches | 0:5c4d7b2438d3 | 49 | # flags_cmd are used only by our scripts, the project files have them already defined, |
switches | 0:5c4d7b2438d3 | 50 | # using this flags results in the errors (duplication) |
switches | 0:5c4d7b2438d3 | 51 | # asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core |
switches | 0:5c4d7b2438d3 | 52 | if target.core == "Cortex-M4F": |
switches | 0:5c4d7b2438d3 | 53 | asm_flags_cmd = [ |
switches | 0:5c4d7b2438d3 | 54 | "--cpu", "Cortex-M4F" |
switches | 0:5c4d7b2438d3 | 55 | ] |
switches | 0:5c4d7b2438d3 | 56 | else: |
switches | 0:5c4d7b2438d3 | 57 | asm_flags_cmd = [ |
switches | 0:5c4d7b2438d3 | 58 | "--cpu", cpuchoice |
switches | 0:5c4d7b2438d3 | 59 | ] |
switches | 0:5c4d7b2438d3 | 60 | # custom c flags |
switches | 0:5c4d7b2438d3 | 61 | if target.core == "Cortex-M4F": |
switches | 0:5c4d7b2438d3 | 62 | c_flags_cmd = [ |
switches | 0:5c4d7b2438d3 | 63 | "--cpu", "Cortex-M4F", |
switches | 0:5c4d7b2438d3 | 64 | "--thumb", "--dlib_config", join(TOOLCHAIN_PATHS['IAR'], "inc", "c", "DLib_Config_Full.h") |
switches | 0:5c4d7b2438d3 | 65 | ] |
switches | 0:5c4d7b2438d3 | 66 | else: |
switches | 0:5c4d7b2438d3 | 67 | c_flags_cmd = [ |
switches | 0:5c4d7b2438d3 | 68 | "--cpu", cpuchoice, |
switches | 0:5c4d7b2438d3 | 69 | "--thumb", "--dlib_config", join(TOOLCHAIN_PATHS['IAR'], "inc", "c", "DLib_Config_Full.h") |
switches | 0:5c4d7b2438d3 | 70 | ] |
switches | 0:5c4d7b2438d3 | 71 | # custom c++ cmd flags |
switches | 0:5c4d7b2438d3 | 72 | cxx_flags_cmd = [ |
switches | 0:5c4d7b2438d3 | 73 | "--c++", "--no_rtti", "--no_exceptions" |
switches | 0:5c4d7b2438d3 | 74 | ] |
switches | 0:5c4d7b2438d3 | 75 | if target.core == "Cortex-M7FD": |
switches | 0:5c4d7b2438d3 | 76 | asm_flags_cmd += ["--fpu", "VFPv5"] |
switches | 0:5c4d7b2438d3 | 77 | c_flags_cmd.append("--fpu=VFPv5") |
switches | 0:5c4d7b2438d3 | 78 | elif target.core == "Cortex-M7F": |
switches | 0:5c4d7b2438d3 | 79 | asm_flags_cmd += ["--fpu", "VFPv5_sp"] |
switches | 0:5c4d7b2438d3 | 80 | c_flags_cmd.append("--fpu=VFPv5_sp") |
switches | 0:5c4d7b2438d3 | 81 | |
switches | 0:5c4d7b2438d3 | 82 | IAR_BIN = join(TOOLCHAIN_PATHS['IAR'], "bin") |
switches | 0:5c4d7b2438d3 | 83 | main_cc = join(IAR_BIN, "iccarm") |
switches | 0:5c4d7b2438d3 | 84 | |
switches | 0:5c4d7b2438d3 | 85 | self.asm = [join(IAR_BIN, "iasmarm")] + asm_flags_cmd + self.flags["asm"] |
switches | 0:5c4d7b2438d3 | 86 | self.cc = [main_cc] |
switches | 0:5c4d7b2438d3 | 87 | self.cppc = [main_cc] |
switches | 0:5c4d7b2438d3 | 88 | self.cc += self.flags["common"] + c_flags_cmd + self.flags["c"] |
switches | 0:5c4d7b2438d3 | 89 | self.cppc += self.flags["common"] + c_flags_cmd + cxx_flags_cmd + self.flags["cxx"] |
switches | 0:5c4d7b2438d3 | 90 | self.ld = [join(IAR_BIN, "ilinkarm")] |
switches | 0:5c4d7b2438d3 | 91 | self.ar = join(IAR_BIN, "iarchive") |
switches | 0:5c4d7b2438d3 | 92 | self.elf2bin = join(IAR_BIN, "ielftool") |
switches | 0:5c4d7b2438d3 | 93 | |
switches | 0:5c4d7b2438d3 | 94 | def parse_dependencies(self, dep_path): |
switches | 0:5c4d7b2438d3 | 95 | return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines() |
switches | 0:5c4d7b2438d3 | 96 | if (path and not path.isspace())] |
switches | 0:5c4d7b2438d3 | 97 | |
switches | 0:5c4d7b2438d3 | 98 | def parse_output(self, output): |
switches | 0:5c4d7b2438d3 | 99 | msg = None |
switches | 0:5c4d7b2438d3 | 100 | for line in output.splitlines(): |
switches | 0:5c4d7b2438d3 | 101 | match = IAR.DIAGNOSTIC_PATTERN.match(line) |
switches | 0:5c4d7b2438d3 | 102 | if match is not None: |
switches | 0:5c4d7b2438d3 | 103 | if msg is not None: |
switches | 0:5c4d7b2438d3 | 104 | self.cc_info(msg) |
switches | 0:5c4d7b2438d3 | 105 | msg = None |
switches | 0:5c4d7b2438d3 | 106 | msg = { |
switches | 0:5c4d7b2438d3 | 107 | 'severity': match.group('severity').lower(), |
switches | 0:5c4d7b2438d3 | 108 | 'file': match.group('file'), |
switches | 0:5c4d7b2438d3 | 109 | 'line': match.group('line'), |
switches | 0:5c4d7b2438d3 | 110 | 'col': 0, |
switches | 0:5c4d7b2438d3 | 111 | 'message': match.group('message'), |
switches | 0:5c4d7b2438d3 | 112 | 'text': '', |
switches | 0:5c4d7b2438d3 | 113 | 'target_name': self.target.name, |
switches | 0:5c4d7b2438d3 | 114 | 'toolchain_name': self.name |
switches | 0:5c4d7b2438d3 | 115 | } |
switches | 0:5c4d7b2438d3 | 116 | elif msg is not None: |
switches | 0:5c4d7b2438d3 | 117 | # Determine the warning/error column by calculating the ^ position |
switches | 0:5c4d7b2438d3 | 118 | match = IAR.INDEX_PATTERN.match(line) |
switches | 0:5c4d7b2438d3 | 119 | if match is not None: |
switches | 0:5c4d7b2438d3 | 120 | msg['col'] = len(match.group('col')) |
switches | 0:5c4d7b2438d3 | 121 | self.cc_info(msg) |
switches | 0:5c4d7b2438d3 | 122 | msg = None |
switches | 0:5c4d7b2438d3 | 123 | else: |
switches | 0:5c4d7b2438d3 | 124 | msg['text'] += line+"\n" |
switches | 0:5c4d7b2438d3 | 125 | |
switches | 0:5c4d7b2438d3 | 126 | if msg is not None: |
switches | 0:5c4d7b2438d3 | 127 | self.cc_info(msg) |
switches | 0:5c4d7b2438d3 | 128 | |
switches | 0:5c4d7b2438d3 | 129 | def get_dep_option(self, object): |
switches | 0:5c4d7b2438d3 | 130 | base, _ = splitext(object) |
switches | 0:5c4d7b2438d3 | 131 | dep_path = base + '.d' |
switches | 0:5c4d7b2438d3 | 132 | return ["--dependencies", dep_path] |
switches | 0:5c4d7b2438d3 | 133 | |
switches | 0:5c4d7b2438d3 | 134 | def cc_extra(self, object): |
switches | 0:5c4d7b2438d3 | 135 | base, _ = splitext(object) |
switches | 0:5c4d7b2438d3 | 136 | return ["-l", base + '.s.txt'] |
switches | 0:5c4d7b2438d3 | 137 | |
switches | 0:5c4d7b2438d3 | 138 | def get_config_option(self, config_header): |
switches | 0:5c4d7b2438d3 | 139 | return ['--preinclude=' + config_header] |
switches | 0:5c4d7b2438d3 | 140 | |
switches | 0:5c4d7b2438d3 | 141 | def get_compile_options(self, defines, includes, for_asm=False): |
switches | 0:5c4d7b2438d3 | 142 | opts = ['-D%s' % d for d in defines] |
switches | 0:5c4d7b2438d3 | 143 | if self.RESPONSE_FILES: |
switches | 0:5c4d7b2438d3 | 144 | opts += ['-f', self.get_inc_file(includes)] |
switches | 0:5c4d7b2438d3 | 145 | else: |
switches | 0:5c4d7b2438d3 | 146 | opts += ["-I%s" % i for i in includes] |
switches | 0:5c4d7b2438d3 | 147 | |
switches | 0:5c4d7b2438d3 | 148 | if not for_asm: |
switches | 0:5c4d7b2438d3 | 149 | config_header = self.get_config_header() |
switches | 0:5c4d7b2438d3 | 150 | if config_header is not None: |
switches | 0:5c4d7b2438d3 | 151 | opts = opts + self.get_config_option(config_header) |
switches | 0:5c4d7b2438d3 | 152 | return opts |
switches | 0:5c4d7b2438d3 | 153 | |
switches | 0:5c4d7b2438d3 | 154 | @hook_tool |
switches | 0:5c4d7b2438d3 | 155 | def assemble(self, source, object, includes): |
switches | 0:5c4d7b2438d3 | 156 | # Build assemble command |
switches | 0:5c4d7b2438d3 | 157 | cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes, True) + ["-o", object, source] |
switches | 0:5c4d7b2438d3 | 158 | |
switches | 0:5c4d7b2438d3 | 159 | # Call cmdline hook |
switches | 0:5c4d7b2438d3 | 160 | cmd = self.hook.get_cmdline_assembler(cmd) |
switches | 0:5c4d7b2438d3 | 161 | |
switches | 0:5c4d7b2438d3 | 162 | # Return command array, don't execute |
switches | 0:5c4d7b2438d3 | 163 | return [cmd] |
switches | 0:5c4d7b2438d3 | 164 | |
switches | 0:5c4d7b2438d3 | 165 | @hook_tool |
switches | 0:5c4d7b2438d3 | 166 | def compile(self, cc, source, object, includes): |
switches | 0:5c4d7b2438d3 | 167 | # Build compile command |
switches | 0:5c4d7b2438d3 | 168 | cmd = cc + self.get_compile_options(self.get_symbols(), includes) |
switches | 0:5c4d7b2438d3 | 169 | |
switches | 0:5c4d7b2438d3 | 170 | cmd.extend(self.get_dep_option(object)) |
switches | 0:5c4d7b2438d3 | 171 | |
switches | 0:5c4d7b2438d3 | 172 | cmd.extend(self.cc_extra(object)) |
switches | 0:5c4d7b2438d3 | 173 | |
switches | 0:5c4d7b2438d3 | 174 | cmd.extend(["-o", object, source]) |
switches | 0:5c4d7b2438d3 | 175 | |
switches | 0:5c4d7b2438d3 | 176 | # Call cmdline hook |
switches | 0:5c4d7b2438d3 | 177 | cmd = self.hook.get_cmdline_compiler(cmd) |
switches | 0:5c4d7b2438d3 | 178 | |
switches | 0:5c4d7b2438d3 | 179 | return [cmd] |
switches | 0:5c4d7b2438d3 | 180 | |
switches | 0:5c4d7b2438d3 | 181 | def compile_c(self, source, object, includes): |
switches | 0:5c4d7b2438d3 | 182 | return self.compile(self.cc, source, object, includes) |
switches | 0:5c4d7b2438d3 | 183 | |
switches | 0:5c4d7b2438d3 | 184 | def compile_cpp(self, source, object, includes): |
switches | 0:5c4d7b2438d3 | 185 | return self.compile(self.cppc, source, object, includes) |
switches | 0:5c4d7b2438d3 | 186 | |
switches | 0:5c4d7b2438d3 | 187 | @hook_tool |
switches | 0:5c4d7b2438d3 | 188 | def link(self, output, objects, libraries, lib_dirs, mem_map): |
switches | 0:5c4d7b2438d3 | 189 | # Build linker command |
switches | 0:5c4d7b2438d3 | 190 | map_file = splitext(output)[0] + ".map" |
switches | 0:5c4d7b2438d3 | 191 | cmd = self.ld + [ "-o", output, "--map=%s" % map_file] + objects + libraries + self.flags['ld'] |
switches | 0:5c4d7b2438d3 | 192 | |
switches | 0:5c4d7b2438d3 | 193 | if mem_map: |
switches | 0:5c4d7b2438d3 | 194 | cmd.extend(["--config", mem_map]) |
switches | 0:5c4d7b2438d3 | 195 | |
switches | 0:5c4d7b2438d3 | 196 | # Call cmdline hook |
switches | 0:5c4d7b2438d3 | 197 | cmd = self.hook.get_cmdline_linker(cmd) |
switches | 0:5c4d7b2438d3 | 198 | |
switches | 0:5c4d7b2438d3 | 199 | if self.RESPONSE_FILES: |
switches | 0:5c4d7b2438d3 | 200 | # Split link command to linker executable + response file |
switches | 0:5c4d7b2438d3 | 201 | cmd_linker = cmd[0] |
switches | 0:5c4d7b2438d3 | 202 | link_files = self.get_link_file(cmd[1:]) |
switches | 0:5c4d7b2438d3 | 203 | cmd = [cmd_linker, '-f', link_files] |
switches | 0:5c4d7b2438d3 | 204 | |
switches | 0:5c4d7b2438d3 | 205 | # Exec command |
switches | 0:5c4d7b2438d3 | 206 | self.cc_verbose("Link: %s" % ' '.join(cmd)) |
switches | 0:5c4d7b2438d3 | 207 | self.default_cmd(cmd) |
switches | 0:5c4d7b2438d3 | 208 | |
switches | 0:5c4d7b2438d3 | 209 | @hook_tool |
switches | 0:5c4d7b2438d3 | 210 | def archive(self, objects, lib_path): |
switches | 0:5c4d7b2438d3 | 211 | if self.RESPONSE_FILES: |
switches | 0:5c4d7b2438d3 | 212 | param = ['-f', self.get_arch_file(objects)] |
switches | 0:5c4d7b2438d3 | 213 | else: |
switches | 0:5c4d7b2438d3 | 214 | param = objects |
switches | 0:5c4d7b2438d3 | 215 | |
switches | 0:5c4d7b2438d3 | 216 | if exists(lib_path): |
switches | 0:5c4d7b2438d3 | 217 | remove(lib_path) |
switches | 0:5c4d7b2438d3 | 218 | |
switches | 0:5c4d7b2438d3 | 219 | self.default_cmd([self.ar, lib_path] + param) |
switches | 0:5c4d7b2438d3 | 220 | |
switches | 0:5c4d7b2438d3 | 221 | @hook_tool |
switches | 0:5c4d7b2438d3 | 222 | def binary(self, resources, elf, bin): |
switches | 0:5c4d7b2438d3 | 223 | # Build binary command |
switches | 0:5c4d7b2438d3 | 224 | cmd = [self.elf2bin, "--bin", elf, bin] |
switches | 0:5c4d7b2438d3 | 225 | |
switches | 0:5c4d7b2438d3 | 226 | # Call cmdline hook |
switches | 0:5c4d7b2438d3 | 227 | cmd = self.hook.get_cmdline_binary(cmd) |
switches | 0:5c4d7b2438d3 | 228 | |
switches | 0:5c4d7b2438d3 | 229 | # Exec command |
switches | 0:5c4d7b2438d3 | 230 | self.cc_verbose("FromELF: %s" % ' '.join(cmd)) |
switches | 0:5c4d7b2438d3 | 231 | self.default_cmd(cmd) |