Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

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?

UserRevisionLine numberNew 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.path import join, dirname, splitext, basename
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
switches 0:5c4d7b2438d3 21 from tools.hooks import hook_tool
switches 0:5c4d7b2438d3 22 from tools.utils import mkdir
switches 0:5c4d7b2438d3 23
switches 0:5c4d7b2438d3 24 class ARM(mbedToolchain):
switches 0:5c4d7b2438d3 25 LINKER_EXT = '.sct'
switches 0:5c4d7b2438d3 26 LIBRARY_EXT = '.ar'
switches 0:5c4d7b2438d3 27
switches 0:5c4d7b2438d3 28 STD_LIB_NAME = "%s.ar"
switches 0:5c4d7b2438d3 29 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error): (?P<message>.+)')
switches 0:5c4d7b2438d3 30 INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
switches 0:5c4d7b2438d3 31 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
switches 0:5c4d7b2438d3 32
switches 0:5c4d7b2438d3 33 @staticmethod
switches 0:5c4d7b2438d3 34 def check_executable():
switches 0:5c4d7b2438d3 35 """Returns True if the executable (armcc) location specified by the
switches 0:5c4d7b2438d3 36 user exists OR the executable can be found on the PATH.
switches 0:5c4d7b2438d3 37 Returns False otherwise."""
switches 0:5c4d7b2438d3 38 return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
switches 0:5c4d7b2438d3 39
switches 0:5c4d7b2438d3 40 def __init__(self, target, notify=None, macros=None,
switches 0:5c4d7b2438d3 41 silent=False, extra_verbose=False, build_profile=None):
switches 0:5c4d7b2438d3 42 mbedToolchain.__init__(self, target, notify, macros, silent,
switches 0:5c4d7b2438d3 43 extra_verbose=extra_verbose,
switches 0:5c4d7b2438d3 44 build_profile=build_profile)
switches 0:5c4d7b2438d3 45
switches 0:5c4d7b2438d3 46 if target.core == "Cortex-M0+":
switches 0:5c4d7b2438d3 47 cpu = "Cortex-M0"
switches 0:5c4d7b2438d3 48 elif target.core == "Cortex-M4F":
switches 0:5c4d7b2438d3 49 cpu = "Cortex-M4.fp"
switches 0:5c4d7b2438d3 50 elif target.core == "Cortex-M7FD":
switches 0:5c4d7b2438d3 51 cpu = "Cortex-M7.fp.dp"
switches 0:5c4d7b2438d3 52 elif target.core == "Cortex-M7F":
switches 0:5c4d7b2438d3 53 cpu = "Cortex-M7.fp.sp"
switches 0:5c4d7b2438d3 54 else:
switches 0:5c4d7b2438d3 55 cpu = target.core
switches 0:5c4d7b2438d3 56
switches 0:5c4d7b2438d3 57 ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
switches 0:5c4d7b2438d3 58 ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
switches 0:5c4d7b2438d3 59
switches 0:5c4d7b2438d3 60 main_cc = join(ARM_BIN, "armcc")
switches 0:5c4d7b2438d3 61
switches 0:5c4d7b2438d3 62 self.flags['common'] += ["--cpu=%s" % cpu]
switches 0:5c4d7b2438d3 63
switches 0:5c4d7b2438d3 64 self.asm = [main_cc] + self.flags['common'] + self.flags['asm'] + ["-I \""+ARM_INC+"\""]
switches 0:5c4d7b2438d3 65 self.cc = [main_cc] + self.flags['common'] + self.flags['c'] + ["-I \""+ARM_INC+"\""]
switches 0:5c4d7b2438d3 66 self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx'] + ["-I \""+ARM_INC+"\""]
switches 0:5c4d7b2438d3 67
switches 0:5c4d7b2438d3 68 self.ld = [join(ARM_BIN, "armlink")]
switches 0:5c4d7b2438d3 69 self.sys_libs = []
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 self.ar = join(ARM_BIN, "armar")
switches 0:5c4d7b2438d3 72 self.elf2bin = join(ARM_BIN, "fromelf")
switches 0:5c4d7b2438d3 73
switches 0:5c4d7b2438d3 74 def parse_dependencies(self, dep_path):
switches 0:5c4d7b2438d3 75 dependencies = []
switches 0:5c4d7b2438d3 76 for line in open(dep_path).readlines():
switches 0:5c4d7b2438d3 77 match = ARM.DEP_PATTERN.match(line)
switches 0:5c4d7b2438d3 78 if match is not None:
switches 0:5c4d7b2438d3 79 #we need to append chroot, because when the .d files are generated the compiler is chrooted
switches 0:5c4d7b2438d3 80 dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file'))
switches 0:5c4d7b2438d3 81 return dependencies
switches 0:5c4d7b2438d3 82
switches 0:5c4d7b2438d3 83 def parse_output(self, output):
switches 0:5c4d7b2438d3 84 msg = None
switches 0:5c4d7b2438d3 85 for line in output.splitlines():
switches 0:5c4d7b2438d3 86 match = ARM.DIAGNOSTIC_PATTERN.match(line)
switches 0:5c4d7b2438d3 87 if match is not None:
switches 0:5c4d7b2438d3 88 if msg is not None:
switches 0:5c4d7b2438d3 89 self.cc_info(msg)
switches 0:5c4d7b2438d3 90 msg = None
switches 0:5c4d7b2438d3 91 msg = {
switches 0:5c4d7b2438d3 92 'severity': match.group('severity').lower(),
switches 0:5c4d7b2438d3 93 'file': match.group('file'),
switches 0:5c4d7b2438d3 94 'line': match.group('line'),
switches 0:5c4d7b2438d3 95 'col': match.group('column') if match.group('column') else 0,
switches 0:5c4d7b2438d3 96 'message': match.group('message'),
switches 0:5c4d7b2438d3 97 'text': '',
switches 0:5c4d7b2438d3 98 'target_name': self.target.name,
switches 0:5c4d7b2438d3 99 'toolchain_name': self.name
switches 0:5c4d7b2438d3 100 }
switches 0:5c4d7b2438d3 101 elif msg is not None:
switches 0:5c4d7b2438d3 102 # Determine the warning/error column by calculating the ^ position
switches 0:5c4d7b2438d3 103 match = ARM.INDEX_PATTERN.match(line)
switches 0:5c4d7b2438d3 104 if match is not None:
switches 0:5c4d7b2438d3 105 msg['col'] = len(match.group('col'))
switches 0:5c4d7b2438d3 106 self.cc_info(msg)
switches 0:5c4d7b2438d3 107 msg = None
switches 0:5c4d7b2438d3 108 else:
switches 0:5c4d7b2438d3 109 msg['text'] += line+"\n"
switches 0:5c4d7b2438d3 110
switches 0:5c4d7b2438d3 111 if msg is not None:
switches 0:5c4d7b2438d3 112 self.cc_info(msg)
switches 0:5c4d7b2438d3 113
switches 0:5c4d7b2438d3 114 def get_dep_option(self, object):
switches 0:5c4d7b2438d3 115 base, _ = splitext(object)
switches 0:5c4d7b2438d3 116 dep_path = base + '.d'
switches 0:5c4d7b2438d3 117 return ["--depend", dep_path]
switches 0:5c4d7b2438d3 118
switches 0:5c4d7b2438d3 119 def get_config_option(self, config_header):
switches 0:5c4d7b2438d3 120 return ['--preinclude=' + config_header]
switches 0:5c4d7b2438d3 121
switches 0:5c4d7b2438d3 122 def get_compile_options(self, defines, includes, for_asm=False):
switches 0:5c4d7b2438d3 123 opts = ['-D%s' % d for d in defines]
switches 0:5c4d7b2438d3 124 if self.RESPONSE_FILES:
switches 0:5c4d7b2438d3 125 opts += ['--via', self.get_inc_file(includes)]
switches 0:5c4d7b2438d3 126 else:
switches 0:5c4d7b2438d3 127 opts += ["-I%s" % i for i in includes]
switches 0:5c4d7b2438d3 128
switches 0:5c4d7b2438d3 129 if not for_asm:
switches 0:5c4d7b2438d3 130 config_header = self.get_config_header()
switches 0:5c4d7b2438d3 131 if config_header is not None:
switches 0:5c4d7b2438d3 132 opts = opts + self.get_config_option(config_header)
switches 0:5c4d7b2438d3 133 return opts
switches 0:5c4d7b2438d3 134
switches 0:5c4d7b2438d3 135 @hook_tool
switches 0:5c4d7b2438d3 136 def assemble(self, source, object, includes):
switches 0:5c4d7b2438d3 137 # Preprocess first, then assemble
switches 0:5c4d7b2438d3 138 dir = join(dirname(object), '.temp')
switches 0:5c4d7b2438d3 139 mkdir(dir)
switches 0:5c4d7b2438d3 140 tempfile = join(dir, basename(object) + '.E.s')
switches 0:5c4d7b2438d3 141
switches 0:5c4d7b2438d3 142 # Build preprocess assemble command
switches 0:5c4d7b2438d3 143 cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]
switches 0:5c4d7b2438d3 144
switches 0:5c4d7b2438d3 145 # Build main assemble command
switches 0:5c4d7b2438d3 146 cmd = self.asm + ["-o", object, tempfile]
switches 0:5c4d7b2438d3 147
switches 0:5c4d7b2438d3 148 # Call cmdline hook
switches 0:5c4d7b2438d3 149 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
switches 0:5c4d7b2438d3 150 cmd = self.hook.get_cmdline_assembler(cmd)
switches 0:5c4d7b2438d3 151
switches 0:5c4d7b2438d3 152 # Return command array, don't execute
switches 0:5c4d7b2438d3 153 return [cmd_pre, cmd]
switches 0:5c4d7b2438d3 154
switches 0:5c4d7b2438d3 155 @hook_tool
switches 0:5c4d7b2438d3 156 def compile(self, cc, source, object, includes):
switches 0:5c4d7b2438d3 157 # Build compile command
switches 0:5c4d7b2438d3 158 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
switches 0:5c4d7b2438d3 159
switches 0:5c4d7b2438d3 160 cmd.extend(self.get_dep_option(object))
switches 0:5c4d7b2438d3 161
switches 0:5c4d7b2438d3 162 cmd.extend(["-o", object, source])
switches 0:5c4d7b2438d3 163
switches 0:5c4d7b2438d3 164 # Call cmdline hook
switches 0:5c4d7b2438d3 165 cmd = self.hook.get_cmdline_compiler(cmd)
switches 0:5c4d7b2438d3 166
switches 0:5c4d7b2438d3 167 return [cmd]
switches 0:5c4d7b2438d3 168
switches 0:5c4d7b2438d3 169 def compile_c(self, source, object, includes):
switches 0:5c4d7b2438d3 170 return self.compile(self.cc, source, object, includes)
switches 0:5c4d7b2438d3 171
switches 0:5c4d7b2438d3 172 def compile_cpp(self, source, object, includes):
switches 0:5c4d7b2438d3 173 return self.compile(self.cppc, source, object, includes)
switches 0:5c4d7b2438d3 174
switches 0:5c4d7b2438d3 175 @hook_tool
switches 0:5c4d7b2438d3 176 def link(self, output, objects, libraries, lib_dirs, mem_map):
switches 0:5c4d7b2438d3 177 map_file = splitext(output)[0] + ".map"
switches 0:5c4d7b2438d3 178 if len(lib_dirs):
switches 0:5c4d7b2438d3 179 args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--map", "--list=%s" % map_file]
switches 0:5c4d7b2438d3 180 else:
switches 0:5c4d7b2438d3 181 args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
switches 0:5c4d7b2438d3 182
switches 0:5c4d7b2438d3 183 if mem_map:
switches 0:5c4d7b2438d3 184 args.extend(["--scatter", mem_map])
switches 0:5c4d7b2438d3 185
switches 0:5c4d7b2438d3 186 # Build linker command
switches 0:5c4d7b2438d3 187 cmd = self.ld + args + objects + libraries + self.sys_libs
switches 0:5c4d7b2438d3 188
switches 0:5c4d7b2438d3 189 # Call cmdline hook
switches 0:5c4d7b2438d3 190 cmd = self.hook.get_cmdline_linker(cmd)
switches 0:5c4d7b2438d3 191
switches 0:5c4d7b2438d3 192 if self.RESPONSE_FILES:
switches 0:5c4d7b2438d3 193 # Split link command to linker executable + response file
switches 0:5c4d7b2438d3 194 cmd_linker = cmd[0]
switches 0:5c4d7b2438d3 195 link_files = self.get_link_file(cmd[1:])
switches 0:5c4d7b2438d3 196 cmd = [cmd_linker, '--via', link_files]
switches 0:5c4d7b2438d3 197
switches 0:5c4d7b2438d3 198 # Exec command
switches 0:5c4d7b2438d3 199 self.cc_verbose("Link: %s" % ' '.join(cmd))
switches 0:5c4d7b2438d3 200 self.default_cmd(cmd)
switches 0:5c4d7b2438d3 201
switches 0:5c4d7b2438d3 202 @hook_tool
switches 0:5c4d7b2438d3 203 def archive(self, objects, lib_path):
switches 0:5c4d7b2438d3 204 if self.RESPONSE_FILES:
switches 0:5c4d7b2438d3 205 param = ['--via', self.get_arch_file(objects)]
switches 0:5c4d7b2438d3 206 else:
switches 0:5c4d7b2438d3 207 param = objects
switches 0:5c4d7b2438d3 208
switches 0:5c4d7b2438d3 209 # Exec command
switches 0:5c4d7b2438d3 210 self.default_cmd([self.ar, '-r', lib_path] + param)
switches 0:5c4d7b2438d3 211
switches 0:5c4d7b2438d3 212 @hook_tool
switches 0:5c4d7b2438d3 213 def binary(self, resources, elf, bin):
switches 0:5c4d7b2438d3 214 # Build binary command
switches 0:5c4d7b2438d3 215 cmd = [self.elf2bin, '--bin', '-o', bin, elf]
switches 0:5c4d7b2438d3 216
switches 0:5c4d7b2438d3 217 # Call cmdline hook
switches 0:5c4d7b2438d3 218 cmd = self.hook.get_cmdline_binary(cmd)
switches 0:5c4d7b2438d3 219
switches 0:5c4d7b2438d3 220 # Exec command
switches 0:5c4d7b2438d3 221 self.cc_verbose("FromELF: %s" % ' '.join(cmd))
switches 0:5c4d7b2438d3 222 self.default_cmd(cmd)
switches 0:5c4d7b2438d3 223
switches 0:5c4d7b2438d3 224
switches 0:5c4d7b2438d3 225 class ARM_STD(ARM):
switches 0:5c4d7b2438d3 226 def __init__(self, target, notify=None, macros=None,
switches 0:5c4d7b2438d3 227 silent=False, extra_verbose=False, build_profile=None):
switches 0:5c4d7b2438d3 228 ARM.__init__(self, target, notify, macros, silent,
switches 0:5c4d7b2438d3 229 extra_verbose=extra_verbose, build_profile=build_profile)
switches 0:5c4d7b2438d3 230
switches 0:5c4d7b2438d3 231 # Run-time values
switches 0:5c4d7b2438d3 232 self.ld.extend(["--libpath", join(TOOLCHAIN_PATHS['ARM'], "lib")])
switches 0:5c4d7b2438d3 233
switches 0:5c4d7b2438d3 234
switches 0:5c4d7b2438d3 235 class ARM_MICRO(ARM):
switches 0:5c4d7b2438d3 236 PATCHED_LIBRARY = False
switches 0:5c4d7b2438d3 237
switches 0:5c4d7b2438d3 238 def __init__(self, target, notify=None, macros=None,
switches 0:5c4d7b2438d3 239 silent=False, extra_verbose=False, build_profile=None):
switches 0:5c4d7b2438d3 240 ARM.__init__(self, target, notify, macros, silent,
switches 0:5c4d7b2438d3 241 extra_verbose=extra_verbose, build_profile=build_profile)
switches 0:5c4d7b2438d3 242
switches 0:5c4d7b2438d3 243 # Run-time values
switches 0:5c4d7b2438d3 244 self.ld.extend(["--libpath", join(TOOLCHAIN_PATHS['ARM'], "lib")])