Preliminary main mbed library for nexpaq development
tools/export/simplicityv3.py@0:6c56fb4bc5f0, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:27:58 2016 +0000
- Revision:
- 0:6c56fb4bc5f0
Moving to library for sharing updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | """ |
nexpaq | 0:6c56fb4bc5f0 | 2 | mbed SDK |
nexpaq | 0:6c56fb4bc5f0 | 3 | Copyright (c) 2014-2016 ARM Limited |
nexpaq | 0:6c56fb4bc5f0 | 4 | |
nexpaq | 0:6c56fb4bc5f0 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
nexpaq | 0:6c56fb4bc5f0 | 6 | you may not use this file except in compliance with the License. |
nexpaq | 0:6c56fb4bc5f0 | 7 | You may obtain a copy of the License at |
nexpaq | 0:6c56fb4bc5f0 | 8 | |
nexpaq | 0:6c56fb4bc5f0 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 0:6c56fb4bc5f0 | 10 | |
nexpaq | 0:6c56fb4bc5f0 | 11 | Unless required by applicable law or agreed to in writing, software |
nexpaq | 0:6c56fb4bc5f0 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
nexpaq | 0:6c56fb4bc5f0 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 0:6c56fb4bc5f0 | 14 | See the License for the specific language governing permissions and |
nexpaq | 0:6c56fb4bc5f0 | 15 | limitations under the License. |
nexpaq | 0:6c56fb4bc5f0 | 16 | """ |
nexpaq | 0:6c56fb4bc5f0 | 17 | from exporters import Exporter |
nexpaq | 0:6c56fb4bc5f0 | 18 | from os.path import split,splitext, basename |
nexpaq | 0:6c56fb4bc5f0 | 19 | |
nexpaq | 0:6c56fb4bc5f0 | 20 | class Folder: |
nexpaq | 0:6c56fb4bc5f0 | 21 | def __init__(self, name): |
nexpaq | 0:6c56fb4bc5f0 | 22 | self.name = name |
nexpaq | 0:6c56fb4bc5f0 | 23 | self.children = [] |
nexpaq | 0:6c56fb4bc5f0 | 24 | |
nexpaq | 0:6c56fb4bc5f0 | 25 | def contains(self, folderName): |
nexpaq | 0:6c56fb4bc5f0 | 26 | for child in self.children: |
nexpaq | 0:6c56fb4bc5f0 | 27 | if child.name == folderName: |
nexpaq | 0:6c56fb4bc5f0 | 28 | return True |
nexpaq | 0:6c56fb4bc5f0 | 29 | return False |
nexpaq | 0:6c56fb4bc5f0 | 30 | |
nexpaq | 0:6c56fb4bc5f0 | 31 | def __str__(self): |
nexpaq | 0:6c56fb4bc5f0 | 32 | retval = self.name + " " |
nexpaq | 0:6c56fb4bc5f0 | 33 | if len(self.children) > 0: |
nexpaq | 0:6c56fb4bc5f0 | 34 | retval += "[ " |
nexpaq | 0:6c56fb4bc5f0 | 35 | for child in self.children: |
nexpaq | 0:6c56fb4bc5f0 | 36 | retval += child.__str__() |
nexpaq | 0:6c56fb4bc5f0 | 37 | retval += " ]" |
nexpaq | 0:6c56fb4bc5f0 | 38 | |
nexpaq | 0:6c56fb4bc5f0 | 39 | return retval |
nexpaq | 0:6c56fb4bc5f0 | 40 | |
nexpaq | 0:6c56fb4bc5f0 | 41 | def findChild(self, folderName): |
nexpaq | 0:6c56fb4bc5f0 | 42 | for child in self.children: |
nexpaq | 0:6c56fb4bc5f0 | 43 | if child.name == folderName: |
nexpaq | 0:6c56fb4bc5f0 | 44 | return child |
nexpaq | 0:6c56fb4bc5f0 | 45 | return None |
nexpaq | 0:6c56fb4bc5f0 | 46 | |
nexpaq | 0:6c56fb4bc5f0 | 47 | def addChild(self, folderName): |
nexpaq | 0:6c56fb4bc5f0 | 48 | if folderName == '': |
nexpaq | 0:6c56fb4bc5f0 | 49 | return None |
nexpaq | 0:6c56fb4bc5f0 | 50 | |
nexpaq | 0:6c56fb4bc5f0 | 51 | if not self.contains(folderName): |
nexpaq | 0:6c56fb4bc5f0 | 52 | self.children.append(Folder(folderName)) |
nexpaq | 0:6c56fb4bc5f0 | 53 | |
nexpaq | 0:6c56fb4bc5f0 | 54 | return self.findChild(folderName) |
nexpaq | 0:6c56fb4bc5f0 | 55 | |
nexpaq | 0:6c56fb4bc5f0 | 56 | class SimplicityV3(Exporter): |
nexpaq | 0:6c56fb4bc5f0 | 57 | NAME = 'SimplicityV3' |
nexpaq | 0:6c56fb4bc5f0 | 58 | TOOLCHAIN = 'GCC_ARM' |
nexpaq | 0:6c56fb4bc5f0 | 59 | |
nexpaq | 0:6c56fb4bc5f0 | 60 | TARGETS = [ |
nexpaq | 0:6c56fb4bc5f0 | 61 | 'EFM32GG_STK3700', |
nexpaq | 0:6c56fb4bc5f0 | 62 | 'EFM32ZG_STK3200', |
nexpaq | 0:6c56fb4bc5f0 | 63 | 'EFM32LG_STK3600', |
nexpaq | 0:6c56fb4bc5f0 | 64 | 'EFM32WG_STK3800', |
nexpaq | 0:6c56fb4bc5f0 | 65 | 'EFM32HG_STK3400', |
nexpaq | 0:6c56fb4bc5f0 | 66 | 'EFM32PG_STK3401' |
nexpaq | 0:6c56fb4bc5f0 | 67 | ] |
nexpaq | 0:6c56fb4bc5f0 | 68 | |
nexpaq | 0:6c56fb4bc5f0 | 69 | PARTS = { |
nexpaq | 0:6c56fb4bc5f0 | 70 | 'EFM32GG_STK3700': 'com.silabs.mcu.si32.efm32.efm32gg.efm32gg990f1024', |
nexpaq | 0:6c56fb4bc5f0 | 71 | 'EFM32ZG_STK3200': 'com.silabs.mcu.si32.efm32.efm32zg.efm32zg222f32', |
nexpaq | 0:6c56fb4bc5f0 | 72 | 'EFM32LG_STK3600': 'com.silabs.mcu.si32.efm32.efm32lg.efm32lg990f256', |
nexpaq | 0:6c56fb4bc5f0 | 73 | 'EFM32WG_STK3800': 'com.silabs.mcu.si32.efm32.efm32wg.efm32wg990f256', |
nexpaq | 0:6c56fb4bc5f0 | 74 | 'EFM32HG_STK3400': 'com.silabs.mcu.si32.efm32.efm32hg.efm32hg322f64', |
nexpaq | 0:6c56fb4bc5f0 | 75 | 'EFM32PG_STK3401': 'com.silabs.mcu.si32.efm32.efm32pg1b.efm32pg1b200f256gm48' |
nexpaq | 0:6c56fb4bc5f0 | 76 | } |
nexpaq | 0:6c56fb4bc5f0 | 77 | |
nexpaq | 0:6c56fb4bc5f0 | 78 | KITS = { |
nexpaq | 0:6c56fb4bc5f0 | 79 | 'EFM32GG_STK3700': 'com.silabs.kit.si32.efm32.efm32gg.stk3700', |
nexpaq | 0:6c56fb4bc5f0 | 80 | 'EFM32ZG_STK3200': 'com.silabs.kit.si32.efm32.efm32zg.stk3200', |
nexpaq | 0:6c56fb4bc5f0 | 81 | 'EFM32LG_STK3600': 'com.silabs.kit.si32.efm32.efm32lg.stk3600', |
nexpaq | 0:6c56fb4bc5f0 | 82 | 'EFM32WG_STK3800': 'com.silabs.kit.si32.efm32.efm32wg.stk3800', |
nexpaq | 0:6c56fb4bc5f0 | 83 | 'EFM32HG_STK3400': 'com.silabs.kit.si32.efm32.efm32hg.slstk3400a', |
nexpaq | 0:6c56fb4bc5f0 | 84 | 'EFM32PG_STK3401': 'com.silabs.kit.si32.efm32.efm32pg.slstk3401a' |
nexpaq | 0:6c56fb4bc5f0 | 85 | } |
nexpaq | 0:6c56fb4bc5f0 | 86 | |
nexpaq | 0:6c56fb4bc5f0 | 87 | FILE_TYPES = { |
nexpaq | 0:6c56fb4bc5f0 | 88 | 'c_sources':'1', |
nexpaq | 0:6c56fb4bc5f0 | 89 | 'cpp_sources':'1', |
nexpaq | 0:6c56fb4bc5f0 | 90 | 's_sources':'1' |
nexpaq | 0:6c56fb4bc5f0 | 91 | } |
nexpaq | 0:6c56fb4bc5f0 | 92 | |
nexpaq | 0:6c56fb4bc5f0 | 93 | EXCLUDED_LIBS = [ |
nexpaq | 0:6c56fb4bc5f0 | 94 | 'm', |
nexpaq | 0:6c56fb4bc5f0 | 95 | 'c', |
nexpaq | 0:6c56fb4bc5f0 | 96 | 'gcc', |
nexpaq | 0:6c56fb4bc5f0 | 97 | 'nosys', |
nexpaq | 0:6c56fb4bc5f0 | 98 | 'supc++', |
nexpaq | 0:6c56fb4bc5f0 | 99 | 'stdc++' |
nexpaq | 0:6c56fb4bc5f0 | 100 | ] |
nexpaq | 0:6c56fb4bc5f0 | 101 | |
nexpaq | 0:6c56fb4bc5f0 | 102 | DOT_IN_RELATIVE_PATH = False |
nexpaq | 0:6c56fb4bc5f0 | 103 | |
nexpaq | 0:6c56fb4bc5f0 | 104 | MBED_CONFIG_HEADER_SUPPORTED = True |
nexpaq | 0:6c56fb4bc5f0 | 105 | |
nexpaq | 0:6c56fb4bc5f0 | 106 | orderedPaths = Folder("Root") |
nexpaq | 0:6c56fb4bc5f0 | 107 | |
nexpaq | 0:6c56fb4bc5f0 | 108 | def check_and_add_path(self, path): |
nexpaq | 0:6c56fb4bc5f0 | 109 | levels = path.split('/') |
nexpaq | 0:6c56fb4bc5f0 | 110 | base = self.orderedPaths |
nexpaq | 0:6c56fb4bc5f0 | 111 | for level in levels: |
nexpaq | 0:6c56fb4bc5f0 | 112 | if base.contains(level): |
nexpaq | 0:6c56fb4bc5f0 | 113 | base = base.findChild(level) |
nexpaq | 0:6c56fb4bc5f0 | 114 | else: |
nexpaq | 0:6c56fb4bc5f0 | 115 | base.addChild(level) |
nexpaq | 0:6c56fb4bc5f0 | 116 | base = base.findChild(level) |
nexpaq | 0:6c56fb4bc5f0 | 117 | |
nexpaq | 0:6c56fb4bc5f0 | 118 | |
nexpaq | 0:6c56fb4bc5f0 | 119 | def generate(self): |
nexpaq | 0:6c56fb4bc5f0 | 120 | # "make" wants Unix paths |
nexpaq | 0:6c56fb4bc5f0 | 121 | self.resources.win_to_unix() |
nexpaq | 0:6c56fb4bc5f0 | 122 | |
nexpaq | 0:6c56fb4bc5f0 | 123 | main_files = [] |
nexpaq | 0:6c56fb4bc5f0 | 124 | |
nexpaq | 0:6c56fb4bc5f0 | 125 | EXCLUDED_LIBS = [ |
nexpaq | 0:6c56fb4bc5f0 | 126 | 'm', |
nexpaq | 0:6c56fb4bc5f0 | 127 | 'c', |
nexpaq | 0:6c56fb4bc5f0 | 128 | 'gcc', |
nexpaq | 0:6c56fb4bc5f0 | 129 | 'nosys', |
nexpaq | 0:6c56fb4bc5f0 | 130 | 'supc++', |
nexpaq | 0:6c56fb4bc5f0 | 131 | 'stdc++' |
nexpaq | 0:6c56fb4bc5f0 | 132 | ] |
nexpaq | 0:6c56fb4bc5f0 | 133 | |
nexpaq | 0:6c56fb4bc5f0 | 134 | for r_type in ['s_sources', 'c_sources', 'cpp_sources']: |
nexpaq | 0:6c56fb4bc5f0 | 135 | r = getattr(self.resources, r_type) |
nexpaq | 0:6c56fb4bc5f0 | 136 | if r: |
nexpaq | 0:6c56fb4bc5f0 | 137 | for source in r: |
nexpaq | 0:6c56fb4bc5f0 | 138 | self.check_and_add_path(split(source)[0]) |
nexpaq | 0:6c56fb4bc5f0 | 139 | |
nexpaq | 0:6c56fb4bc5f0 | 140 | if not ('/' in source): |
nexpaq | 0:6c56fb4bc5f0 | 141 | main_files.append(source) |
nexpaq | 0:6c56fb4bc5f0 | 142 | |
nexpaq | 0:6c56fb4bc5f0 | 143 | libraries = [] |
nexpaq | 0:6c56fb4bc5f0 | 144 | for lib in self.resources.libraries: |
nexpaq | 0:6c56fb4bc5f0 | 145 | l, _ = splitext(basename(lib)) |
nexpaq | 0:6c56fb4bc5f0 | 146 | if l[3:] not in EXCLUDED_LIBS: |
nexpaq | 0:6c56fb4bc5f0 | 147 | libraries.append(l[3:]) |
nexpaq | 0:6c56fb4bc5f0 | 148 | |
nexpaq | 0:6c56fb4bc5f0 | 149 | defines = [] |
nexpaq | 0:6c56fb4bc5f0 | 150 | for define in self.toolchain.get_symbols(): |
nexpaq | 0:6c56fb4bc5f0 | 151 | if '=' in define: |
nexpaq | 0:6c56fb4bc5f0 | 152 | keyval = define.split('=') |
nexpaq | 0:6c56fb4bc5f0 | 153 | defines.append( (keyval[0], keyval[1]) ) |
nexpaq | 0:6c56fb4bc5f0 | 154 | else: |
nexpaq | 0:6c56fb4bc5f0 | 155 | defines.append( (define, '') ) |
nexpaq | 0:6c56fb4bc5f0 | 156 | |
nexpaq | 0:6c56fb4bc5f0 | 157 | self.check_and_add_path(split(self.resources.linker_script)[0]) |
nexpaq | 0:6c56fb4bc5f0 | 158 | |
nexpaq | 0:6c56fb4bc5f0 | 159 | ctx = { |
nexpaq | 0:6c56fb4bc5f0 | 160 | 'name': self.project_name, |
nexpaq | 0:6c56fb4bc5f0 | 161 | 'main_files': main_files, |
nexpaq | 0:6c56fb4bc5f0 | 162 | 'recursiveFolders': self.orderedPaths, |
nexpaq | 0:6c56fb4bc5f0 | 163 | 'object_files': self.resources.objects, |
nexpaq | 0:6c56fb4bc5f0 | 164 | 'include_paths': self.resources.inc_dirs, |
nexpaq | 0:6c56fb4bc5f0 | 165 | 'library_paths': self.resources.lib_dirs, |
nexpaq | 0:6c56fb4bc5f0 | 166 | 'linker_script': self.resources.linker_script, |
nexpaq | 0:6c56fb4bc5f0 | 167 | 'libraries': libraries, |
nexpaq | 0:6c56fb4bc5f0 | 168 | 'defines': defines, |
nexpaq | 0:6c56fb4bc5f0 | 169 | 'part': self.PARTS[self.target], |
nexpaq | 0:6c56fb4bc5f0 | 170 | 'kit': self.KITS[self.target], |
nexpaq | 0:6c56fb4bc5f0 | 171 | 'loopcount': 0 |
nexpaq | 0:6c56fb4bc5f0 | 172 | } |
nexpaq | 0:6c56fb4bc5f0 | 173 | ctx.update(self.flags) |
nexpaq | 0:6c56fb4bc5f0 | 174 | |
nexpaq | 0:6c56fb4bc5f0 | 175 | ## Strip main folder from include paths because ssproj is not capable of handling it |
nexpaq | 0:6c56fb4bc5f0 | 176 | if '.' in ctx['include_paths']: |
nexpaq | 0:6c56fb4bc5f0 | 177 | ctx['include_paths'].remove('.') |
nexpaq | 0:6c56fb4bc5f0 | 178 | |
nexpaq | 0:6c56fb4bc5f0 | 179 | ''' |
nexpaq | 0:6c56fb4bc5f0 | 180 | Suppress print statements |
nexpaq | 0:6c56fb4bc5f0 | 181 | print('\n') |
nexpaq | 0:6c56fb4bc5f0 | 182 | print(self.target) |
nexpaq | 0:6c56fb4bc5f0 | 183 | print('\n') |
nexpaq | 0:6c56fb4bc5f0 | 184 | print(ctx) |
nexpaq | 0:6c56fb4bc5f0 | 185 | print('\n') |
nexpaq | 0:6c56fb4bc5f0 | 186 | print(self.orderedPaths) |
nexpaq | 0:6c56fb4bc5f0 | 187 | for path in self.orderedPaths.children: |
nexpaq | 0:6c56fb4bc5f0 | 188 | print(path.name + "\n") |
nexpaq | 0:6c56fb4bc5f0 | 189 | for bpath in path.children: |
nexpaq | 0:6c56fb4bc5f0 | 190 | print("\t" + bpath.name + "\n") |
nexpaq | 0:6c56fb4bc5f0 | 191 | ''' |
nexpaq | 0:6c56fb4bc5f0 | 192 | |
nexpaq | 0:6c56fb4bc5f0 | 193 | self.gen_file('simplicityv3_slsproj.tmpl', ctx, '%s.slsproj' % self.project_name) |