Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

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) 2014-2016 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 from exporters import Exporter
switches 0:5c4d7b2438d3 18 from os.path import split,splitext, basename
switches 0:5c4d7b2438d3 19
switches 0:5c4d7b2438d3 20 class Folder:
switches 0:5c4d7b2438d3 21 def __init__(self, name):
switches 0:5c4d7b2438d3 22 self.name = name
switches 0:5c4d7b2438d3 23 self.children = []
switches 0:5c4d7b2438d3 24
switches 0:5c4d7b2438d3 25 def contains(self, folderName):
switches 0:5c4d7b2438d3 26 for child in self.children:
switches 0:5c4d7b2438d3 27 if child.name == folderName:
switches 0:5c4d7b2438d3 28 return True
switches 0:5c4d7b2438d3 29 return False
switches 0:5c4d7b2438d3 30
switches 0:5c4d7b2438d3 31 def __str__(self):
switches 0:5c4d7b2438d3 32 retval = self.name + " "
switches 0:5c4d7b2438d3 33 if len(self.children) > 0:
switches 0:5c4d7b2438d3 34 retval += "[ "
switches 0:5c4d7b2438d3 35 for child in self.children:
switches 0:5c4d7b2438d3 36 retval += child.__str__()
switches 0:5c4d7b2438d3 37 retval += " ]"
switches 0:5c4d7b2438d3 38
switches 0:5c4d7b2438d3 39 return retval
switches 0:5c4d7b2438d3 40
switches 0:5c4d7b2438d3 41 def findChild(self, folderName):
switches 0:5c4d7b2438d3 42 for child in self.children:
switches 0:5c4d7b2438d3 43 if child.name == folderName:
switches 0:5c4d7b2438d3 44 return child
switches 0:5c4d7b2438d3 45 return None
switches 0:5c4d7b2438d3 46
switches 0:5c4d7b2438d3 47 def addChild(self, folderName):
switches 0:5c4d7b2438d3 48 if folderName == '':
switches 0:5c4d7b2438d3 49 return None
switches 0:5c4d7b2438d3 50
switches 0:5c4d7b2438d3 51 if not self.contains(folderName):
switches 0:5c4d7b2438d3 52 self.children.append(Folder(folderName))
switches 0:5c4d7b2438d3 53
switches 0:5c4d7b2438d3 54 return self.findChild(folderName)
switches 0:5c4d7b2438d3 55
switches 0:5c4d7b2438d3 56 class SimplicityV3(Exporter):
switches 0:5c4d7b2438d3 57 NAME = 'SimplicityV3'
switches 0:5c4d7b2438d3 58 TOOLCHAIN = 'GCC_ARM'
switches 0:5c4d7b2438d3 59
switches 0:5c4d7b2438d3 60 TARGETS = [
switches 0:5c4d7b2438d3 61 'EFM32GG_STK3700',
switches 0:5c4d7b2438d3 62 'EFM32ZG_STK3200',
switches 0:5c4d7b2438d3 63 'EFM32LG_STK3600',
switches 0:5c4d7b2438d3 64 'EFM32WG_STK3800',
switches 0:5c4d7b2438d3 65 'EFM32HG_STK3400',
switches 0:5c4d7b2438d3 66 'EFM32PG_STK3401'
switches 0:5c4d7b2438d3 67 ]
switches 0:5c4d7b2438d3 68
switches 0:5c4d7b2438d3 69 PARTS = {
switches 0:5c4d7b2438d3 70 'EFM32GG_STK3700': 'com.silabs.mcu.si32.efm32.efm32gg.efm32gg990f1024',
switches 0:5c4d7b2438d3 71 'EFM32ZG_STK3200': 'com.silabs.mcu.si32.efm32.efm32zg.efm32zg222f32',
switches 0:5c4d7b2438d3 72 'EFM32LG_STK3600': 'com.silabs.mcu.si32.efm32.efm32lg.efm32lg990f256',
switches 0:5c4d7b2438d3 73 'EFM32WG_STK3800': 'com.silabs.mcu.si32.efm32.efm32wg.efm32wg990f256',
switches 0:5c4d7b2438d3 74 'EFM32HG_STK3400': 'com.silabs.mcu.si32.efm32.efm32hg.efm32hg322f64',
switches 0:5c4d7b2438d3 75 'EFM32PG_STK3401': 'com.silabs.mcu.si32.efm32.efm32pg1b.efm32pg1b200f256gm48'
switches 0:5c4d7b2438d3 76 }
switches 0:5c4d7b2438d3 77
switches 0:5c4d7b2438d3 78 KITS = {
switches 0:5c4d7b2438d3 79 'EFM32GG_STK3700': 'com.silabs.kit.si32.efm32.efm32gg.stk3700',
switches 0:5c4d7b2438d3 80 'EFM32ZG_STK3200': 'com.silabs.kit.si32.efm32.efm32zg.stk3200',
switches 0:5c4d7b2438d3 81 'EFM32LG_STK3600': 'com.silabs.kit.si32.efm32.efm32lg.stk3600',
switches 0:5c4d7b2438d3 82 'EFM32WG_STK3800': 'com.silabs.kit.si32.efm32.efm32wg.stk3800',
switches 0:5c4d7b2438d3 83 'EFM32HG_STK3400': 'com.silabs.kit.si32.efm32.efm32hg.slstk3400a',
switches 0:5c4d7b2438d3 84 'EFM32PG_STK3401': 'com.silabs.kit.si32.efm32.efm32pg.slstk3401a'
switches 0:5c4d7b2438d3 85 }
switches 0:5c4d7b2438d3 86
switches 0:5c4d7b2438d3 87 FILE_TYPES = {
switches 0:5c4d7b2438d3 88 'c_sources':'1',
switches 0:5c4d7b2438d3 89 'cpp_sources':'1',
switches 0:5c4d7b2438d3 90 's_sources':'1'
switches 0:5c4d7b2438d3 91 }
switches 0:5c4d7b2438d3 92
switches 0:5c4d7b2438d3 93 EXCLUDED_LIBS = [
switches 0:5c4d7b2438d3 94 'm',
switches 0:5c4d7b2438d3 95 'c',
switches 0:5c4d7b2438d3 96 'gcc',
switches 0:5c4d7b2438d3 97 'nosys',
switches 0:5c4d7b2438d3 98 'supc++',
switches 0:5c4d7b2438d3 99 'stdc++'
switches 0:5c4d7b2438d3 100 ]
switches 0:5c4d7b2438d3 101
switches 0:5c4d7b2438d3 102 DOT_IN_RELATIVE_PATH = False
switches 0:5c4d7b2438d3 103
switches 0:5c4d7b2438d3 104 MBED_CONFIG_HEADER_SUPPORTED = True
switches 0:5c4d7b2438d3 105
switches 0:5c4d7b2438d3 106 orderedPaths = Folder("Root")
switches 0:5c4d7b2438d3 107
switches 0:5c4d7b2438d3 108 def check_and_add_path(self, path):
switches 0:5c4d7b2438d3 109 levels = path.split('/')
switches 0:5c4d7b2438d3 110 base = self.orderedPaths
switches 0:5c4d7b2438d3 111 for level in levels:
switches 0:5c4d7b2438d3 112 if base.contains(level):
switches 0:5c4d7b2438d3 113 base = base.findChild(level)
switches 0:5c4d7b2438d3 114 else:
switches 0:5c4d7b2438d3 115 base.addChild(level)
switches 0:5c4d7b2438d3 116 base = base.findChild(level)
switches 0:5c4d7b2438d3 117
switches 0:5c4d7b2438d3 118
switches 0:5c4d7b2438d3 119 def generate(self):
switches 0:5c4d7b2438d3 120 # "make" wants Unix paths
switches 0:5c4d7b2438d3 121 self.resources.win_to_unix()
switches 0:5c4d7b2438d3 122
switches 0:5c4d7b2438d3 123 main_files = []
switches 0:5c4d7b2438d3 124
switches 0:5c4d7b2438d3 125 EXCLUDED_LIBS = [
switches 0:5c4d7b2438d3 126 'm',
switches 0:5c4d7b2438d3 127 'c',
switches 0:5c4d7b2438d3 128 'gcc',
switches 0:5c4d7b2438d3 129 'nosys',
switches 0:5c4d7b2438d3 130 'supc++',
switches 0:5c4d7b2438d3 131 'stdc++'
switches 0:5c4d7b2438d3 132 ]
switches 0:5c4d7b2438d3 133
switches 0:5c4d7b2438d3 134 for r_type in ['s_sources', 'c_sources', 'cpp_sources']:
switches 0:5c4d7b2438d3 135 r = getattr(self.resources, r_type)
switches 0:5c4d7b2438d3 136 if r:
switches 0:5c4d7b2438d3 137 for source in r:
switches 0:5c4d7b2438d3 138 self.check_and_add_path(split(source)[0])
switches 0:5c4d7b2438d3 139
switches 0:5c4d7b2438d3 140 if not ('/' in source):
switches 0:5c4d7b2438d3 141 main_files.append(source)
switches 0:5c4d7b2438d3 142
switches 0:5c4d7b2438d3 143 libraries = []
switches 0:5c4d7b2438d3 144 for lib in self.resources.libraries:
switches 0:5c4d7b2438d3 145 l, _ = splitext(basename(lib))
switches 0:5c4d7b2438d3 146 if l[3:] not in EXCLUDED_LIBS:
switches 0:5c4d7b2438d3 147 libraries.append(l[3:])
switches 0:5c4d7b2438d3 148
switches 0:5c4d7b2438d3 149 defines = []
switches 0:5c4d7b2438d3 150 for define in self.toolchain.get_symbols():
switches 0:5c4d7b2438d3 151 if '=' in define:
switches 0:5c4d7b2438d3 152 keyval = define.split('=')
switches 0:5c4d7b2438d3 153 defines.append( (keyval[0], keyval[1]) )
switches 0:5c4d7b2438d3 154 else:
switches 0:5c4d7b2438d3 155 defines.append( (define, '') )
switches 0:5c4d7b2438d3 156
switches 0:5c4d7b2438d3 157 self.check_and_add_path(split(self.resources.linker_script)[0])
switches 0:5c4d7b2438d3 158
switches 0:5c4d7b2438d3 159 ctx = {
switches 0:5c4d7b2438d3 160 'name': self.project_name,
switches 0:5c4d7b2438d3 161 'main_files': main_files,
switches 0:5c4d7b2438d3 162 'recursiveFolders': self.orderedPaths,
switches 0:5c4d7b2438d3 163 'object_files': self.resources.objects,
switches 0:5c4d7b2438d3 164 'include_paths': self.resources.inc_dirs,
switches 0:5c4d7b2438d3 165 'library_paths': self.resources.lib_dirs,
switches 0:5c4d7b2438d3 166 'linker_script': self.resources.linker_script,
switches 0:5c4d7b2438d3 167 'libraries': libraries,
switches 0:5c4d7b2438d3 168 'defines': defines,
switches 0:5c4d7b2438d3 169 'part': self.PARTS[self.target],
switches 0:5c4d7b2438d3 170 'kit': self.KITS[self.target],
switches 0:5c4d7b2438d3 171 'loopcount': 0
switches 0:5c4d7b2438d3 172 }
switches 0:5c4d7b2438d3 173 ctx.update(self.flags)
switches 0:5c4d7b2438d3 174
switches 0:5c4d7b2438d3 175 ## Strip main folder from include paths because ssproj is not capable of handling it
switches 0:5c4d7b2438d3 176 if '.' in ctx['include_paths']:
switches 0:5c4d7b2438d3 177 ctx['include_paths'].remove('.')
switches 0:5c4d7b2438d3 178 ctx['include_root'] = True
switches 0:5c4d7b2438d3 179
switches 0:5c4d7b2438d3 180 '''
switches 0:5c4d7b2438d3 181 Suppress print statements
switches 0:5c4d7b2438d3 182 print('\n')
switches 0:5c4d7b2438d3 183 print(self.target)
switches 0:5c4d7b2438d3 184 print('\n')
switches 0:5c4d7b2438d3 185 print(ctx)
switches 0:5c4d7b2438d3 186 print('\n')
switches 0:5c4d7b2438d3 187 print(self.orderedPaths)
switches 0:5c4d7b2438d3 188 for path in self.orderedPaths.children:
switches 0:5c4d7b2438d3 189 print(path.name + "\n")
switches 0:5c4d7b2438d3 190 for bpath in path.children:
switches 0:5c4d7b2438d3 191 print("\t" + bpath.name + "\n")
switches 0:5c4d7b2438d3 192 '''
switches 0:5c4d7b2438d3 193
switches 0:5c4d7b2438d3 194 self.gen_file('simplicityv3_slsproj.tmpl', ctx, '%s.slsproj' % self.project_name)