Development mbed library for MAX32630FTHR
Dependents: blinky_max32630fthr
tools/options.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 | from json import load |
switches | 0:5c4d7b2438d3 | 18 | from os.path import join, dirname |
switches | 0:5c4d7b2438d3 | 19 | from os import listdir |
switches | 0:5c4d7b2438d3 | 20 | from argparse import ArgumentParser |
switches | 0:5c4d7b2438d3 | 21 | from tools.toolchains import TOOLCHAINS |
switches | 0:5c4d7b2438d3 | 22 | from tools.targets import TARGET_NAMES |
switches | 0:5c4d7b2438d3 | 23 | from tools.utils import argparse_force_uppercase_type, \ |
switches | 0:5c4d7b2438d3 | 24 | argparse_lowercase_hyphen_type, argparse_many, \ |
switches | 0:5c4d7b2438d3 | 25 | argparse_filestring_type, args_error, argparse_profile_filestring_type |
switches | 0:5c4d7b2438d3 | 26 | |
switches | 0:5c4d7b2438d3 | 27 | def get_default_options_parser(add_clean=True, add_options=True, |
switches | 0:5c4d7b2438d3 | 28 | add_app_config=False): |
switches | 0:5c4d7b2438d3 | 29 | """Create a new options parser with the default compiler options added |
switches | 0:5c4d7b2438d3 | 30 | |
switches | 0:5c4d7b2438d3 | 31 | Keyword arguments: |
switches | 0:5c4d7b2438d3 | 32 | add_clean - add the clean argument? |
switches | 0:5c4d7b2438d3 | 33 | add_options - add the options argument? |
switches | 0:5c4d7b2438d3 | 34 | """ |
switches | 0:5c4d7b2438d3 | 35 | parser = ArgumentParser() |
switches | 0:5c4d7b2438d3 | 36 | |
switches | 0:5c4d7b2438d3 | 37 | targetnames = TARGET_NAMES |
switches | 0:5c4d7b2438d3 | 38 | targetnames.sort() |
switches | 0:5c4d7b2438d3 | 39 | toolchainlist = list(TOOLCHAINS) |
switches | 0:5c4d7b2438d3 | 40 | toolchainlist.sort() |
switches | 0:5c4d7b2438d3 | 41 | |
switches | 0:5c4d7b2438d3 | 42 | parser.add_argument("-m", "--mcu", |
switches | 0:5c4d7b2438d3 | 43 | help=("build for the given MCU (%s)" % |
switches | 0:5c4d7b2438d3 | 44 | ', '.join(targetnames)), |
switches | 0:5c4d7b2438d3 | 45 | metavar="MCU", |
switches | 0:5c4d7b2438d3 | 46 | type=argparse_many( |
switches | 0:5c4d7b2438d3 | 47 | argparse_force_uppercase_type( |
switches | 0:5c4d7b2438d3 | 48 | targetnames, "MCU"))) |
switches | 0:5c4d7b2438d3 | 49 | |
switches | 0:5c4d7b2438d3 | 50 | parser.add_argument("-t", "--tool", |
switches | 0:5c4d7b2438d3 | 51 | help=("build using the given TOOLCHAIN (%s)" % |
switches | 0:5c4d7b2438d3 | 52 | ', '.join(toolchainlist)), |
switches | 0:5c4d7b2438d3 | 53 | metavar="TOOLCHAIN", |
switches | 0:5c4d7b2438d3 | 54 | type=argparse_many( |
switches | 0:5c4d7b2438d3 | 55 | argparse_force_uppercase_type( |
switches | 0:5c4d7b2438d3 | 56 | toolchainlist, "toolchain"))) |
switches | 0:5c4d7b2438d3 | 57 | |
switches | 0:5c4d7b2438d3 | 58 | parser.add_argument("--color", |
switches | 0:5c4d7b2438d3 | 59 | help="print Warnings, and Errors in color", |
switches | 0:5c4d7b2438d3 | 60 | action="store_true", default=False) |
switches | 0:5c4d7b2438d3 | 61 | |
switches | 0:5c4d7b2438d3 | 62 | parser.add_argument("--cflags", default=[], action="append", |
switches | 0:5c4d7b2438d3 | 63 | help="Extra flags to provide to the C compiler") |
switches | 0:5c4d7b2438d3 | 64 | |
switches | 0:5c4d7b2438d3 | 65 | parser.add_argument("--asmflags", default=[], action="append", |
switches | 0:5c4d7b2438d3 | 66 | help="Extra flags to provide to the assembler") |
switches | 0:5c4d7b2438d3 | 67 | |
switches | 0:5c4d7b2438d3 | 68 | parser.add_argument("--ldflags", default=[], action="append", |
switches | 0:5c4d7b2438d3 | 69 | help="Extra flags to provide to the linker") |
switches | 0:5c4d7b2438d3 | 70 | |
switches | 0:5c4d7b2438d3 | 71 | if add_clean: |
switches | 0:5c4d7b2438d3 | 72 | parser.add_argument("-c", "--clean", action="store_true", default=False, |
switches | 0:5c4d7b2438d3 | 73 | help="clean the build directory") |
switches | 0:5c4d7b2438d3 | 74 | |
switches | 0:5c4d7b2438d3 | 75 | if add_options: |
switches | 0:5c4d7b2438d3 | 76 | parser.add_argument("--profile", dest="profile", action="append", |
switches | 0:5c4d7b2438d3 | 77 | type=argparse_profile_filestring_type, |
switches | 0:5c4d7b2438d3 | 78 | help="Build profile to use. Can be either path to json" \ |
switches | 0:5c4d7b2438d3 | 79 | "file or one of the default one ({})".format(", ".join(list_profiles())), |
switches | 0:5c4d7b2438d3 | 80 | default=[]) |
switches | 0:5c4d7b2438d3 | 81 | if add_app_config: |
switches | 0:5c4d7b2438d3 | 82 | parser.add_argument("--app-config", default=None, dest="app_config", |
switches | 0:5c4d7b2438d3 | 83 | type=argparse_filestring_type, |
switches | 0:5c4d7b2438d3 | 84 | help="Path of an app configuration file (Default is to look for 'mbed_app.json')") |
switches | 0:5c4d7b2438d3 | 85 | |
switches | 0:5c4d7b2438d3 | 86 | return parser |
switches | 0:5c4d7b2438d3 | 87 | |
switches | 0:5c4d7b2438d3 | 88 | def list_profiles(): |
switches | 0:5c4d7b2438d3 | 89 | """Lists available build profiles |
switches | 0:5c4d7b2438d3 | 90 | |
switches | 0:5c4d7b2438d3 | 91 | Checks default profile directory (mbed-os/tools/profiles/) for all the json files and return list of names only |
switches | 0:5c4d7b2438d3 | 92 | """ |
switches | 0:5c4d7b2438d3 | 93 | return [fn.replace(".json", "") for fn in listdir(join(dirname(__file__), "profiles")) if fn.endswith(".json")] |
switches | 0:5c4d7b2438d3 | 94 | |
switches | 0:5c4d7b2438d3 | 95 | def extract_profile(parser, options, toolchain): |
switches | 0:5c4d7b2438d3 | 96 | """Extract a Toolchain profile from parsed options |
switches | 0:5c4d7b2438d3 | 97 | |
switches | 0:5c4d7b2438d3 | 98 | Positional arguments: |
switches | 0:5c4d7b2438d3 | 99 | parser - parser used to parse the command line arguments |
switches | 0:5c4d7b2438d3 | 100 | options - The parsed command line arguments |
switches | 0:5c4d7b2438d3 | 101 | toolchain - the toolchain that the profile should be extracted for |
switches | 0:5c4d7b2438d3 | 102 | """ |
switches | 0:5c4d7b2438d3 | 103 | profile = {'c': [], 'cxx': [], 'ld': [], 'common': [], 'asm': []} |
switches | 0:5c4d7b2438d3 | 104 | filenames = options.profile or [join(dirname(__file__), "profiles", |
switches | 0:5c4d7b2438d3 | 105 | "default.json")] |
switches | 0:5c4d7b2438d3 | 106 | for filename in filenames: |
switches | 0:5c4d7b2438d3 | 107 | contents = load(open(filename)) |
switches | 0:5c4d7b2438d3 | 108 | try: |
switches | 0:5c4d7b2438d3 | 109 | for key in profile.iterkeys(): |
switches | 0:5c4d7b2438d3 | 110 | profile[key] += contents[toolchain][key] |
switches | 0:5c4d7b2438d3 | 111 | except KeyError: |
switches | 0:5c4d7b2438d3 | 112 | args_error(parser, ("argument --profile: toolchain {} is not" |
switches | 0:5c4d7b2438d3 | 113 | " supported by profile {}").format(toolchain, |
switches | 0:5c4d7b2438d3 | 114 | filename)) |
switches | 0:5c4d7b2438d3 | 115 | return profile |