Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
tools/project.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 | """ The CLI entry point for exporting projects from the mbed tools to any of the |
switches | 0:5c4d7b2438d3 | 2 | supported IDEs or project structures. |
switches | 0:5c4d7b2438d3 | 3 | """ |
switches | 0:5c4d7b2438d3 | 4 | import sys |
switches | 0:5c4d7b2438d3 | 5 | from os.path import join, abspath, dirname, exists, basename |
switches | 0:5c4d7b2438d3 | 6 | ROOT = abspath(join(dirname(__file__), "..")) |
switches | 0:5c4d7b2438d3 | 7 | sys.path.insert(0, ROOT) |
switches | 0:5c4d7b2438d3 | 8 | |
switches | 0:5c4d7b2438d3 | 9 | from shutil import move, rmtree |
switches | 0:5c4d7b2438d3 | 10 | from argparse import ArgumentParser |
switches | 0:5c4d7b2438d3 | 11 | from os.path import normpath, realpath |
switches | 0:5c4d7b2438d3 | 12 | |
switches | 0:5c4d7b2438d3 | 13 | from tools.paths import EXPORT_DIR, MBED_HAL, MBED_LIBRARIES |
switches | 0:5c4d7b2438d3 | 14 | from tools.export import EXPORTERS, mcu_ide_matrix |
switches | 0:5c4d7b2438d3 | 15 | from tools.tests import TESTS, TEST_MAP |
switches | 0:5c4d7b2438d3 | 16 | from tools.tests import test_known, test_name_known, Test |
switches | 0:5c4d7b2438d3 | 17 | from tools.targets import TARGET_NAMES |
switches | 0:5c4d7b2438d3 | 18 | from tools.utils import argparse_filestring_type, argparse_many, args_error |
switches | 0:5c4d7b2438d3 | 19 | from tools.utils import argparse_force_lowercase_type |
switches | 0:5c4d7b2438d3 | 20 | from tools.utils import argparse_force_uppercase_type |
switches | 0:5c4d7b2438d3 | 21 | from tools.utils import print_large_string |
switches | 0:5c4d7b2438d3 | 22 | from tools.project_api import export_project, get_exporter_toolchain |
switches | 0:5c4d7b2438d3 | 23 | from tools.options import extract_profile |
switches | 0:5c4d7b2438d3 | 24 | |
switches | 0:5c4d7b2438d3 | 25 | |
switches | 0:5c4d7b2438d3 | 26 | def setup_project(ide, target, program=None, source_dir=None, build=None, export_path=None): |
switches | 0:5c4d7b2438d3 | 27 | """Generate a name, if not provided, and find dependencies |
switches | 0:5c4d7b2438d3 | 28 | |
switches | 0:5c4d7b2438d3 | 29 | Positional arguments: |
switches | 0:5c4d7b2438d3 | 30 | ide - IDE or project structure that will soon be exported to |
switches | 0:5c4d7b2438d3 | 31 | target - MCU that the project will build for |
switches | 0:5c4d7b2438d3 | 32 | |
switches | 0:5c4d7b2438d3 | 33 | Keyword arguments: |
switches | 0:5c4d7b2438d3 | 34 | program - the index of a test program |
switches | 0:5c4d7b2438d3 | 35 | source_dir - the directory, or directories that contain all of the sources |
switches | 0:5c4d7b2438d3 | 36 | build - a directory that will contain the result of the export |
switches | 0:5c4d7b2438d3 | 37 | """ |
switches | 0:5c4d7b2438d3 | 38 | # Some libraries have extra macros (called by exporter symbols) to we need |
switches | 0:5c4d7b2438d3 | 39 | # to pass them to maintain compilation macros integrity between compiled |
switches | 0:5c4d7b2438d3 | 40 | # library and header files we might use with it |
switches | 0:5c4d7b2438d3 | 41 | if source_dir: |
switches | 0:5c4d7b2438d3 | 42 | # --source is used to generate IDE files to toolchain directly |
switches | 0:5c4d7b2438d3 | 43 | # in the source tree and doesn't generate zip file |
switches | 0:5c4d7b2438d3 | 44 | project_dir = export_path or source_dir[0] |
switches | 0:5c4d7b2438d3 | 45 | if program: |
switches | 0:5c4d7b2438d3 | 46 | project_name = TESTS[program] |
switches | 0:5c4d7b2438d3 | 47 | else: |
switches | 0:5c4d7b2438d3 | 48 | project_name = basename(normpath(realpath(source_dir[0]))) |
switches | 0:5c4d7b2438d3 | 49 | src_paths = source_dir |
switches | 0:5c4d7b2438d3 | 50 | lib_paths = None |
switches | 0:5c4d7b2438d3 | 51 | else: |
switches | 0:5c4d7b2438d3 | 52 | test = Test(program) |
switches | 0:5c4d7b2438d3 | 53 | if not build: |
switches | 0:5c4d7b2438d3 | 54 | # Substitute the mbed library builds with their sources |
switches | 0:5c4d7b2438d3 | 55 | if MBED_LIBRARIES in test.dependencies: |
switches | 0:5c4d7b2438d3 | 56 | test.dependencies.remove(MBED_LIBRARIES) |
switches | 0:5c4d7b2438d3 | 57 | test.dependencies.append(MBED_HAL) |
switches | 0:5c4d7b2438d3 | 58 | |
switches | 0:5c4d7b2438d3 | 59 | |
switches | 0:5c4d7b2438d3 | 60 | src_paths = [test.source_dir] |
switches | 0:5c4d7b2438d3 | 61 | lib_paths = test.dependencies |
switches | 0:5c4d7b2438d3 | 62 | project_name = "_".join([test.id, ide, target]) |
switches | 0:5c4d7b2438d3 | 63 | project_dir = join(EXPORT_DIR, project_name) |
switches | 0:5c4d7b2438d3 | 64 | |
switches | 0:5c4d7b2438d3 | 65 | return project_dir, project_name, src_paths, lib_paths |
switches | 0:5c4d7b2438d3 | 66 | |
switches | 0:5c4d7b2438d3 | 67 | |
switches | 0:5c4d7b2438d3 | 68 | def export(target, ide, build=None, src=None, macros=None, project_id=None, |
switches | 0:5c4d7b2438d3 | 69 | clean=False, zip_proj=False, build_profile=None, export_path=None, |
switches | 0:5c4d7b2438d3 | 70 | silent=False): |
switches | 0:5c4d7b2438d3 | 71 | """Do an export of a project. |
switches | 0:5c4d7b2438d3 | 72 | |
switches | 0:5c4d7b2438d3 | 73 | Positional arguments: |
switches | 0:5c4d7b2438d3 | 74 | target - MCU that the project will compile for |
switches | 0:5c4d7b2438d3 | 75 | ide - the IDE or project structure to export to |
switches | 0:5c4d7b2438d3 | 76 | |
switches | 0:5c4d7b2438d3 | 77 | Keyword arguments: |
switches | 0:5c4d7b2438d3 | 78 | build - to use the compiled mbed libraries or not |
switches | 0:5c4d7b2438d3 | 79 | src - directory or directories that contain the source to export |
switches | 0:5c4d7b2438d3 | 80 | macros - extra macros to add to the project |
switches | 0:5c4d7b2438d3 | 81 | project_id - the name of the project |
switches | 0:5c4d7b2438d3 | 82 | clean - start from a clean state before exporting |
switches | 0:5c4d7b2438d3 | 83 | zip_proj - create a zip file or not |
switches | 0:5c4d7b2438d3 | 84 | |
switches | 0:5c4d7b2438d3 | 85 | Returns an object of type Exporter (tools/exports/exporters.py) |
switches | 0:5c4d7b2438d3 | 86 | """ |
switches | 0:5c4d7b2438d3 | 87 | project_dir, name, src, lib = setup_project(ide, target, program=project_id, |
switches | 0:5c4d7b2438d3 | 88 | source_dir=src, build=build, export_path=export_path) |
switches | 0:5c4d7b2438d3 | 89 | |
switches | 0:5c4d7b2438d3 | 90 | zip_name = name+".zip" if zip_proj else None |
switches | 0:5c4d7b2438d3 | 91 | |
switches | 0:5c4d7b2438d3 | 92 | return export_project(src, project_dir, target, ide, clean=clean, name=name, |
switches | 0:5c4d7b2438d3 | 93 | macros=macros, libraries_paths=lib, zip_proj=zip_name, |
switches | 0:5c4d7b2438d3 | 94 | build_profile=build_profile, silent=silent) |
switches | 0:5c4d7b2438d3 | 95 | |
switches | 0:5c4d7b2438d3 | 96 | |
switches | 0:5c4d7b2438d3 | 97 | def main(): |
switches | 0:5c4d7b2438d3 | 98 | """Entry point""" |
switches | 0:5c4d7b2438d3 | 99 | # Parse Options |
switches | 0:5c4d7b2438d3 | 100 | parser = ArgumentParser() |
switches | 0:5c4d7b2438d3 | 101 | |
switches | 0:5c4d7b2438d3 | 102 | targetnames = TARGET_NAMES |
switches | 0:5c4d7b2438d3 | 103 | targetnames.sort() |
switches | 0:5c4d7b2438d3 | 104 | toolchainlist = EXPORTERS.keys() |
switches | 0:5c4d7b2438d3 | 105 | toolchainlist.sort() |
switches | 0:5c4d7b2438d3 | 106 | |
switches | 0:5c4d7b2438d3 | 107 | parser.add_argument("-m", "--mcu", |
switches | 0:5c4d7b2438d3 | 108 | metavar="MCU", |
switches | 0:5c4d7b2438d3 | 109 | default='LPC1768', |
switches | 0:5c4d7b2438d3 | 110 | type=argparse_force_uppercase_type(targetnames, "MCU"), |
switches | 0:5c4d7b2438d3 | 111 | help="generate project for the given MCU ({})".format( |
switches | 0:5c4d7b2438d3 | 112 | ', '.join(targetnames))) |
switches | 0:5c4d7b2438d3 | 113 | |
switches | 0:5c4d7b2438d3 | 114 | parser.add_argument("-i", |
switches | 0:5c4d7b2438d3 | 115 | dest="ide", |
switches | 0:5c4d7b2438d3 | 116 | default='uvision', |
switches | 0:5c4d7b2438d3 | 117 | type=argparse_force_lowercase_type( |
switches | 0:5c4d7b2438d3 | 118 | toolchainlist, "toolchain"), |
switches | 0:5c4d7b2438d3 | 119 | help="The target IDE: %s"% str(toolchainlist)) |
switches | 0:5c4d7b2438d3 | 120 | |
switches | 0:5c4d7b2438d3 | 121 | parser.add_argument("-c", "--clean", |
switches | 0:5c4d7b2438d3 | 122 | action="store_true", |
switches | 0:5c4d7b2438d3 | 123 | default=False, |
switches | 0:5c4d7b2438d3 | 124 | help="clean the export directory") |
switches | 0:5c4d7b2438d3 | 125 | |
switches | 0:5c4d7b2438d3 | 126 | group = parser.add_mutually_exclusive_group(required=False) |
switches | 0:5c4d7b2438d3 | 127 | group.add_argument( |
switches | 0:5c4d7b2438d3 | 128 | "-p", |
switches | 0:5c4d7b2438d3 | 129 | type=test_known, |
switches | 0:5c4d7b2438d3 | 130 | dest="program", |
switches | 0:5c4d7b2438d3 | 131 | help="The index of the desired test program: [0-%s]"% (len(TESTS)-1)) |
switches | 0:5c4d7b2438d3 | 132 | |
switches | 0:5c4d7b2438d3 | 133 | group.add_argument("-n", |
switches | 0:5c4d7b2438d3 | 134 | type=test_name_known, |
switches | 0:5c4d7b2438d3 | 135 | dest="program", |
switches | 0:5c4d7b2438d3 | 136 | help="The name of the desired test program") |
switches | 0:5c4d7b2438d3 | 137 | |
switches | 0:5c4d7b2438d3 | 138 | parser.add_argument("-b", |
switches | 0:5c4d7b2438d3 | 139 | dest="build", |
switches | 0:5c4d7b2438d3 | 140 | default=False, |
switches | 0:5c4d7b2438d3 | 141 | action="store_true", |
switches | 0:5c4d7b2438d3 | 142 | help="use the mbed library build, instead of the sources") |
switches | 0:5c4d7b2438d3 | 143 | |
switches | 0:5c4d7b2438d3 | 144 | group.add_argument("-L", "--list-tests", |
switches | 0:5c4d7b2438d3 | 145 | action="store_true", |
switches | 0:5c4d7b2438d3 | 146 | dest="list_tests", |
switches | 0:5c4d7b2438d3 | 147 | default=False, |
switches | 0:5c4d7b2438d3 | 148 | help="list available programs in order and exit") |
switches | 0:5c4d7b2438d3 | 149 | |
switches | 0:5c4d7b2438d3 | 150 | group.add_argument("-S", "--list-matrix", |
switches | 0:5c4d7b2438d3 | 151 | action="store_true", |
switches | 0:5c4d7b2438d3 | 152 | dest="supported_ides", |
switches | 0:5c4d7b2438d3 | 153 | default=False, |
switches | 0:5c4d7b2438d3 | 154 | help="displays supported matrix of MCUs and IDEs") |
switches | 0:5c4d7b2438d3 | 155 | |
switches | 0:5c4d7b2438d3 | 156 | parser.add_argument("-E", |
switches | 0:5c4d7b2438d3 | 157 | action="store_true", |
switches | 0:5c4d7b2438d3 | 158 | dest="supported_ides_html", |
switches | 0:5c4d7b2438d3 | 159 | default=False, |
switches | 0:5c4d7b2438d3 | 160 | help="writes tools/export/README.md") |
switches | 0:5c4d7b2438d3 | 161 | |
switches | 0:5c4d7b2438d3 | 162 | parser.add_argument("--source", |
switches | 0:5c4d7b2438d3 | 163 | action="append", |
switches | 0:5c4d7b2438d3 | 164 | type=argparse_filestring_type, |
switches | 0:5c4d7b2438d3 | 165 | dest="source_dir", |
switches | 0:5c4d7b2438d3 | 166 | default=[], |
switches | 0:5c4d7b2438d3 | 167 | help="The source (input) directory") |
switches | 0:5c4d7b2438d3 | 168 | |
switches | 0:5c4d7b2438d3 | 169 | parser.add_argument("-D", |
switches | 0:5c4d7b2438d3 | 170 | action="append", |
switches | 0:5c4d7b2438d3 | 171 | dest="macros", |
switches | 0:5c4d7b2438d3 | 172 | help="Add a macro definition") |
switches | 0:5c4d7b2438d3 | 173 | |
switches | 0:5c4d7b2438d3 | 174 | parser.add_argument("--profile", |
switches | 0:5c4d7b2438d3 | 175 | type=argparse_filestring_type, |
switches | 0:5c4d7b2438d3 | 176 | default=[], |
switches | 0:5c4d7b2438d3 | 177 | help="Toolchain profile") |
switches | 0:5c4d7b2438d3 | 178 | |
switches | 0:5c4d7b2438d3 | 179 | parser.add_argument("--update-packs", |
switches | 0:5c4d7b2438d3 | 180 | dest="update_packs", |
switches | 0:5c4d7b2438d3 | 181 | action="store_true", |
switches | 0:5c4d7b2438d3 | 182 | default=False) |
switches | 0:5c4d7b2438d3 | 183 | |
switches | 0:5c4d7b2438d3 | 184 | options = parser.parse_args() |
switches | 0:5c4d7b2438d3 | 185 | |
switches | 0:5c4d7b2438d3 | 186 | # Print available tests in order and exit |
switches | 0:5c4d7b2438d3 | 187 | if options.list_tests is True: |
switches | 0:5c4d7b2438d3 | 188 | print '\n'.join([str(test) for test in sorted(TEST_MAP.values())]) |
switches | 0:5c4d7b2438d3 | 189 | sys.exit() |
switches | 0:5c4d7b2438d3 | 190 | |
switches | 0:5c4d7b2438d3 | 191 | # Only prints matrix of supported IDEs |
switches | 0:5c4d7b2438d3 | 192 | if options.supported_ides: |
switches | 0:5c4d7b2438d3 | 193 | print_large_string(mcu_ide_matrix()) |
switches | 0:5c4d7b2438d3 | 194 | exit(0) |
switches | 0:5c4d7b2438d3 | 195 | |
switches | 0:5c4d7b2438d3 | 196 | # Only prints matrix of supported IDEs |
switches | 0:5c4d7b2438d3 | 197 | if options.supported_ides_html: |
switches | 0:5c4d7b2438d3 | 198 | html = mcu_ide_matrix(verbose_html=True) |
switches | 0:5c4d7b2438d3 | 199 | try: |
switches | 0:5c4d7b2438d3 | 200 | with open("./export/README.md", "w") as readme: |
switches | 0:5c4d7b2438d3 | 201 | readme.write("Exporter IDE/Platform Support\n") |
switches | 0:5c4d7b2438d3 | 202 | readme.write("-----------------------------------\n") |
switches | 0:5c4d7b2438d3 | 203 | readme.write("\n") |
switches | 0:5c4d7b2438d3 | 204 | readme.write(html) |
switches | 0:5c4d7b2438d3 | 205 | except IOError as exc: |
switches | 0:5c4d7b2438d3 | 206 | print "I/O error({0}): {1}".format(exc.errno, exc.strerror) |
switches | 0:5c4d7b2438d3 | 207 | except: |
switches | 0:5c4d7b2438d3 | 208 | print "Unexpected error:", sys.exc_info()[0] |
switches | 0:5c4d7b2438d3 | 209 | raise |
switches | 0:5c4d7b2438d3 | 210 | exit(0) |
switches | 0:5c4d7b2438d3 | 211 | |
switches | 0:5c4d7b2438d3 | 212 | if options.update_packs: |
switches | 0:5c4d7b2438d3 | 213 | from tools.arm_pack_manager import Cache |
switches | 0:5c4d7b2438d3 | 214 | cache = Cache(True, True) |
switches | 0:5c4d7b2438d3 | 215 | cache.cache_descriptors() |
switches | 0:5c4d7b2438d3 | 216 | |
switches | 0:5c4d7b2438d3 | 217 | # Clean Export Directory |
switches | 0:5c4d7b2438d3 | 218 | if options.clean: |
switches | 0:5c4d7b2438d3 | 219 | if exists(EXPORT_DIR): |
switches | 0:5c4d7b2438d3 | 220 | rmtree(EXPORT_DIR) |
switches | 0:5c4d7b2438d3 | 221 | |
switches | 0:5c4d7b2438d3 | 222 | for mcu in options.mcu: |
switches | 0:5c4d7b2438d3 | 223 | zip_proj = not bool(options.source_dir) |
switches | 0:5c4d7b2438d3 | 224 | |
switches | 0:5c4d7b2438d3 | 225 | # Target |
switches | 0:5c4d7b2438d3 | 226 | if not options.mcu: |
switches | 0:5c4d7b2438d3 | 227 | args_error(parser, "argument -m/--mcu is required") |
switches | 0:5c4d7b2438d3 | 228 | |
switches | 0:5c4d7b2438d3 | 229 | # Toolchain |
switches | 0:5c4d7b2438d3 | 230 | if not options.ide: |
switches | 0:5c4d7b2438d3 | 231 | args_error(parser, "argument -i is required") |
switches | 0:5c4d7b2438d3 | 232 | |
switches | 0:5c4d7b2438d3 | 233 | if (options.program is None) and (not options.source_dir): |
switches | 0:5c4d7b2438d3 | 234 | args_error(parser, "one of -p, -n, or --source is required") |
switches | 0:5c4d7b2438d3 | 235 | # Export to selected toolchain |
switches | 0:5c4d7b2438d3 | 236 | exporter, toolchain_name = get_exporter_toolchain(options.ide) |
switches | 0:5c4d7b2438d3 | 237 | if options.mcu not in exporter.TARGETS: |
switches | 0:5c4d7b2438d3 | 238 | args_error(parser, "%s not supported by %s"%(options.mcu,options.ide)) |
switches | 0:5c4d7b2438d3 | 239 | profile = extract_profile(parser, options, toolchain_name) |
switches | 0:5c4d7b2438d3 | 240 | export(options.mcu, options.ide, build=options.build, |
switches | 0:5c4d7b2438d3 | 241 | src=options.source_dir, macros=options.macros, |
switches | 0:5c4d7b2438d3 | 242 | project_id=options.program, clean=options.clean, |
switches | 0:5c4d7b2438d3 | 243 | zip_proj=zip_proj, build_profile=profile) |
switches | 0:5c4d7b2438d3 | 244 | |
switches | 0:5c4d7b2438d3 | 245 | |
switches | 0:5c4d7b2438d3 | 246 | if __name__ == "__main__": |
switches | 0:5c4d7b2438d3 | 247 | main() |