5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 #! /usr/bin/env python2
group-onsemi 0:098463de4c5d 2 """
group-onsemi 0:098463de4c5d 3 mbed SDK
group-onsemi 0:098463de4c5d 4 Copyright (c) 2011-2013 ARM Limited
group-onsemi 0:098463de4c5d 5
group-onsemi 0:098463de4c5d 6 Licensed under the Apache License, Version 2.0 (the "License");
group-onsemi 0:098463de4c5d 7 you may not use this file except in compliance with the License.
group-onsemi 0:098463de4c5d 8 You may obtain a copy of the License at
group-onsemi 0:098463de4c5d 9
group-onsemi 0:098463de4c5d 10 http://www.apache.org/licenses/LICENSE-2.0
group-onsemi 0:098463de4c5d 11
group-onsemi 0:098463de4c5d 12 Unless required by applicable law or agreed to in writing, software
group-onsemi 0:098463de4c5d 13 distributed under the License is distributed on an "AS IS" BASIS,
group-onsemi 0:098463de4c5d 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-onsemi 0:098463de4c5d 15 See the License for the specific language governing permissions and
group-onsemi 0:098463de4c5d 16 limitations under the License.
group-onsemi 0:098463de4c5d 17
group-onsemi 0:098463de4c5d 18 LIBRARIES BUILD
group-onsemi 0:098463de4c5d 19 """
group-onsemi 0:098463de4c5d 20 import sys
group-onsemi 0:098463de4c5d 21 from time import time
group-onsemi 0:098463de4c5d 22 from os.path import join, abspath, dirname
group-onsemi 0:098463de4c5d 23
group-onsemi 0:098463de4c5d 24
group-onsemi 0:098463de4c5d 25 # Be sure that the tools directory is in the search path
group-onsemi 0:098463de4c5d 26 ROOT = abspath(join(dirname(__file__), ".."))
group-onsemi 0:098463de4c5d 27 sys.path.insert(0, ROOT)
group-onsemi 0:098463de4c5d 28
group-onsemi 0:098463de4c5d 29
group-onsemi 0:098463de4c5d 30 from tools.toolchains import TOOLCHAINS, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
group-onsemi 0:098463de4c5d 31 from tools.toolchains import mbedToolchain
group-onsemi 0:098463de4c5d 32 from tools.targets import TARGET_NAMES, TARGET_MAP
group-onsemi 0:098463de4c5d 33 from tools.options import get_default_options_parser
group-onsemi 0:098463de4c5d 34 from tools.options import extract_profile
group-onsemi 0:098463de4c5d 35 from tools.build_api import build_library, build_mbed_libs, build_lib
group-onsemi 0:098463de4c5d 36 from tools.build_api import mcu_toolchain_matrix
group-onsemi 0:098463de4c5d 37 from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
group-onsemi 0:098463de4c5d 38 from tools.build_api import print_build_results
group-onsemi 0:098463de4c5d 39 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
group-onsemi 0:098463de4c5d 40 from utils import argparse_filestring_type, args_error
group-onsemi 0:098463de4c5d 41 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP
group-onsemi 0:098463de4c5d 42 from utils import argparse_filestring_type, argparse_dir_not_parent
group-onsemi 0:098463de4c5d 43
group-onsemi 0:098463de4c5d 44 if __name__ == '__main__':
group-onsemi 0:098463de4c5d 45 start = time()
group-onsemi 0:098463de4c5d 46
group-onsemi 0:098463de4c5d 47 # Parse Options
group-onsemi 0:098463de4c5d 48 parser = get_default_options_parser()
group-onsemi 0:098463de4c5d 49
group-onsemi 0:098463de4c5d 50 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
group-onsemi 0:098463de4c5d 51 default=None, help="The source (input) directory", action="append")
group-onsemi 0:098463de4c5d 52
group-onsemi 0:098463de4c5d 53 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT),
group-onsemi 0:098463de4c5d 54 default=None, help="The build (output) directory")
group-onsemi 0:098463de4c5d 55
group-onsemi 0:098463de4c5d 56 parser.add_argument("--no-archive", dest="no_archive", action="store_true",
group-onsemi 0:098463de4c5d 57 default=False, help="Do not produce archive (.ar) file, but rather .o")
group-onsemi 0:098463de4c5d 58
group-onsemi 0:098463de4c5d 59 # Extra libraries
group-onsemi 0:098463de4c5d 60 parser.add_argument("-r", "--rtos",
group-onsemi 0:098463de4c5d 61 action="store_true",
group-onsemi 0:098463de4c5d 62 dest="rtos",
group-onsemi 0:098463de4c5d 63 default=False,
group-onsemi 0:098463de4c5d 64 help="Compile the rtos")
group-onsemi 0:098463de4c5d 65
group-onsemi 0:098463de4c5d 66 parser.add_argument("--rpc",
group-onsemi 0:098463de4c5d 67 action="store_true",
group-onsemi 0:098463de4c5d 68 dest="rpc",
group-onsemi 0:098463de4c5d 69 default=False,
group-onsemi 0:098463de4c5d 70 help="Compile the rpc library")
group-onsemi 0:098463de4c5d 71
group-onsemi 0:098463de4c5d 72 parser.add_argument("-e", "--eth",
group-onsemi 0:098463de4c5d 73 action="store_true", dest="eth",
group-onsemi 0:098463de4c5d 74 default=False,
group-onsemi 0:098463de4c5d 75 help="Compile the ethernet library")
group-onsemi 0:098463de4c5d 76
group-onsemi 0:098463de4c5d 77 parser.add_argument("-U", "--usb_host",
group-onsemi 0:098463de4c5d 78 action="store_true",
group-onsemi 0:098463de4c5d 79 dest="usb_host",
group-onsemi 0:098463de4c5d 80 default=False,
group-onsemi 0:098463de4c5d 81 help="Compile the USB Host library")
group-onsemi 0:098463de4c5d 82
group-onsemi 0:098463de4c5d 83 parser.add_argument("-u", "--usb",
group-onsemi 0:098463de4c5d 84 action="store_true",
group-onsemi 0:098463de4c5d 85 dest="usb",
group-onsemi 0:098463de4c5d 86 default=False,
group-onsemi 0:098463de4c5d 87 help="Compile the USB Device library")
group-onsemi 0:098463de4c5d 88
group-onsemi 0:098463de4c5d 89 parser.add_argument("-d", "--dsp",
group-onsemi 0:098463de4c5d 90 action="store_true",
group-onsemi 0:098463de4c5d 91 dest="dsp",
group-onsemi 0:098463de4c5d 92 default=False,
group-onsemi 0:098463de4c5d 93 help="Compile the DSP library")
group-onsemi 0:098463de4c5d 94
group-onsemi 0:098463de4c5d 95 parser.add_argument("-F", "--fat",
group-onsemi 0:098463de4c5d 96 action="store_true",
group-onsemi 0:098463de4c5d 97 dest="fat",
group-onsemi 0:098463de4c5d 98 default=False,
group-onsemi 0:098463de4c5d 99 help="Compile FS and SD card file system library")
group-onsemi 0:098463de4c5d 100
group-onsemi 0:098463de4c5d 101 parser.add_argument("-b", "--ublox",
group-onsemi 0:098463de4c5d 102 action="store_true",
group-onsemi 0:098463de4c5d 103 dest="ublox",
group-onsemi 0:098463de4c5d 104 default=False,
group-onsemi 0:098463de4c5d 105 help="Compile the u-blox library")
group-onsemi 0:098463de4c5d 106
group-onsemi 0:098463de4c5d 107 parser.add_argument( "--cpputest",
group-onsemi 0:098463de4c5d 108 action="store_true",
group-onsemi 0:098463de4c5d 109 dest="cpputest_lib",
group-onsemi 0:098463de4c5d 110 default=False,
group-onsemi 0:098463de4c5d 111 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
group-onsemi 0:098463de4c5d 112
group-onsemi 0:098463de4c5d 113 parser.add_argument("-D",
group-onsemi 0:098463de4c5d 114 action="append",
group-onsemi 0:098463de4c5d 115 dest="macros",
group-onsemi 0:098463de4c5d 116 help="Add a macro definition")
group-onsemi 0:098463de4c5d 117
group-onsemi 0:098463de4c5d 118 parser.add_argument("-S", "--supported-toolchains",
group-onsemi 0:098463de4c5d 119 action="store_true",
group-onsemi 0:098463de4c5d 120 dest="supported_toolchains",
group-onsemi 0:098463de4c5d 121 default=False,
group-onsemi 0:098463de4c5d 122 help="Displays supported matrix of MCUs and toolchains")
group-onsemi 0:098463de4c5d 123
group-onsemi 0:098463de4c5d 124 parser.add_argument('-f', '--filter',
group-onsemi 0:098463de4c5d 125 dest='general_filter_regex',
group-onsemi 0:098463de4c5d 126 default=None,
group-onsemi 0:098463de4c5d 127 help='For some commands you can use filter to filter out results')
group-onsemi 0:098463de4c5d 128
group-onsemi 0:098463de4c5d 129 parser.add_argument("--cppcheck",
group-onsemi 0:098463de4c5d 130 action="store_true",
group-onsemi 0:098463de4c5d 131 dest="cppcheck_validation",
group-onsemi 0:098463de4c5d 132 default=False,
group-onsemi 0:098463de4c5d 133 help="Forces 'cppcheck' static code analysis")
group-onsemi 0:098463de4c5d 134
group-onsemi 0:098463de4c5d 135 parser.add_argument("-j", "--jobs", type=int, dest="jobs",
group-onsemi 0:098463de4c5d 136 default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
group-onsemi 0:098463de4c5d 137 parser.add_argument("-N", "--artifact-name", dest="artifact_name",
group-onsemi 0:098463de4c5d 138 default=None, help="The built project's name")
group-onsemi 0:098463de4c5d 139
group-onsemi 0:098463de4c5d 140 parser.add_argument("-v", "--verbose",
group-onsemi 0:098463de4c5d 141 action="store_true",
group-onsemi 0:098463de4c5d 142 dest="verbose",
group-onsemi 0:098463de4c5d 143 default=False,
group-onsemi 0:098463de4c5d 144 help="Verbose diagnostic output")
group-onsemi 0:098463de4c5d 145
group-onsemi 0:098463de4c5d 146 parser.add_argument("--silent",
group-onsemi 0:098463de4c5d 147 action="store_true",
group-onsemi 0:098463de4c5d 148 dest="silent",
group-onsemi 0:098463de4c5d 149 default=False,
group-onsemi 0:098463de4c5d 150 help="Silent diagnostic output (no copy, compile notification)")
group-onsemi 0:098463de4c5d 151
group-onsemi 0:098463de4c5d 152 parser.add_argument("-x", "--extra-verbose-notifications",
group-onsemi 0:098463de4c5d 153 action="store_true",
group-onsemi 0:098463de4c5d 154 dest="extra_verbose_notify",
group-onsemi 0:098463de4c5d 155 default=False,
group-onsemi 0:098463de4c5d 156 help="Makes compiler more verbose, CI friendly.")
group-onsemi 0:098463de4c5d 157
group-onsemi 0:098463de4c5d 158 options = parser.parse_args()
group-onsemi 0:098463de4c5d 159
group-onsemi 0:098463de4c5d 160 # Only prints matrix of supported toolchains
group-onsemi 0:098463de4c5d 161 if options.supported_toolchains:
group-onsemi 0:098463de4c5d 162 print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
group-onsemi 0:098463de4c5d 163 exit(0)
group-onsemi 0:098463de4c5d 164
group-onsemi 0:098463de4c5d 165
group-onsemi 0:098463de4c5d 166 # Get target list
group-onsemi 0:098463de4c5d 167 targets = options.mcu if options.mcu else TARGET_NAMES
group-onsemi 0:098463de4c5d 168
group-onsemi 0:098463de4c5d 169 # Get toolchains list
group-onsemi 0:098463de4c5d 170 toolchains = options.tool if options.tool else TOOLCHAINS
group-onsemi 0:098463de4c5d 171
group-onsemi 0:098463de4c5d 172 if options.source_dir and not options.build_dir:
group-onsemi 0:098463de4c5d 173 args_error(parser, "argument --build is required by argument --source")
group-onsemi 0:098463de4c5d 174
group-onsemi 0:098463de4c5d 175 if options.color:
group-onsemi 0:098463de4c5d 176 # This import happens late to prevent initializing colorization when we don't need it
group-onsemi 0:098463de4c5d 177 import colorize
group-onsemi 0:098463de4c5d 178 if options.verbose:
group-onsemi 0:098463de4c5d 179 notify = mbedToolchain.print_notify_verbose
group-onsemi 0:098463de4c5d 180 else:
group-onsemi 0:098463de4c5d 181 notify = mbedToolchain.print_notify
group-onsemi 0:098463de4c5d 182 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
group-onsemi 0:098463de4c5d 183 else:
group-onsemi 0:098463de4c5d 184 notify = None
group-onsemi 0:098463de4c5d 185
group-onsemi 0:098463de4c5d 186 # Get libraries list
group-onsemi 0:098463de4c5d 187 libraries = []
group-onsemi 0:098463de4c5d 188
group-onsemi 0:098463de4c5d 189 # Additional Libraries
group-onsemi 0:098463de4c5d 190 if options.rtos:
group-onsemi 0:098463de4c5d 191 libraries.extend(["rtx", "rtos"])
group-onsemi 0:098463de4c5d 192 if options.rpc:
group-onsemi 0:098463de4c5d 193 libraries.extend(["rpc"])
group-onsemi 0:098463de4c5d 194 if options.eth:
group-onsemi 0:098463de4c5d 195 libraries.append("eth")
group-onsemi 0:098463de4c5d 196 if options.usb:
group-onsemi 0:098463de4c5d 197 libraries.append("usb")
group-onsemi 0:098463de4c5d 198 if options.usb_host:
group-onsemi 0:098463de4c5d 199 libraries.append("usb_host")
group-onsemi 0:098463de4c5d 200 if options.dsp:
group-onsemi 0:098463de4c5d 201 libraries.extend(["dsp"])
group-onsemi 0:098463de4c5d 202 if options.fat:
group-onsemi 0:098463de4c5d 203 libraries.extend(["fat"])
group-onsemi 0:098463de4c5d 204 if options.ublox:
group-onsemi 0:098463de4c5d 205 libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
group-onsemi 0:098463de4c5d 206 if options.cpputest_lib:
group-onsemi 0:098463de4c5d 207 libraries.extend(["cpputest"])
group-onsemi 0:098463de4c5d 208
group-onsemi 0:098463de4c5d 209 # Build results
group-onsemi 0:098463de4c5d 210 failures = []
group-onsemi 0:098463de4c5d 211 successes = []
group-onsemi 0:098463de4c5d 212 skipped = []
group-onsemi 0:098463de4c5d 213
group-onsemi 0:098463de4c5d 214 # CPPCHECK code validation
group-onsemi 0:098463de4c5d 215 if options.cppcheck_validation:
group-onsemi 0:098463de4c5d 216 for toolchain in toolchains:
group-onsemi 0:098463de4c5d 217 if not TOOLCHAIN_CLASSES[toolchain].check_executable():
group-onsemi 0:098463de4c5d 218 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
group-onsemi 0:098463de4c5d 219 args_error(parser, "Could not find executable for %s.\n"
group-onsemi 0:098463de4c5d 220 "Currently set search path: %s"
group-onsemi 0:098463de4c5d 221 % (toolchain, search_path))
group-onsemi 0:098463de4c5d 222 for target in targets:
group-onsemi 0:098463de4c5d 223 try:
group-onsemi 0:098463de4c5d 224 mcu = TARGET_MAP[target]
group-onsemi 0:098463de4c5d 225 # CMSIS and MBED libs analysis
group-onsemi 0:098463de4c5d 226 profile = extract_profile(parser, options, toolchain)
group-onsemi 0:098463de4c5d 227 static_analysis_scan(
group-onsemi 0:098463de4c5d 228 mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
group-onsemi 0:098463de4c5d 229 verbose=options.verbose, jobs=options.jobs,
group-onsemi 0:098463de4c5d 230 build_profile=profile)
group-onsemi 0:098463de4c5d 231 for lib_id in libraries:
group-onsemi 0:098463de4c5d 232 # Static check for library
group-onsemi 0:098463de4c5d 233 static_analysis_scan_lib(
group-onsemi 0:098463de4c5d 234 lib_id, mcu, toolchain, CPPCHECK_CMD,
group-onsemi 0:098463de4c5d 235 CPPCHECK_MSG_FORMAT,
group-onsemi 0:098463de4c5d 236 extra_verbose=options.extra_verbose_notify,
group-onsemi 0:098463de4c5d 237 verbose=options.verbose, jobs=options.jobs,
group-onsemi 0:098463de4c5d 238 clean=options.clean, macros=options.macros,
group-onsemi 0:098463de4c5d 239 build_profile=profile)
group-onsemi 0:098463de4c5d 240 pass
group-onsemi 0:098463de4c5d 241 except Exception, e:
group-onsemi 0:098463de4c5d 242 if options.verbose:
group-onsemi 0:098463de4c5d 243 import traceback
group-onsemi 0:098463de4c5d 244 traceback.print_exc(file=sys.stdout)
group-onsemi 0:098463de4c5d 245 sys.exit(1)
group-onsemi 0:098463de4c5d 246 print e
group-onsemi 0:098463de4c5d 247 else:
group-onsemi 0:098463de4c5d 248 # Build
group-onsemi 0:098463de4c5d 249 for toolchain in toolchains:
group-onsemi 0:098463de4c5d 250 for target in targets:
group-onsemi 0:098463de4c5d 251 tt_id = "%s::%s" % (toolchain, target)
group-onsemi 0:098463de4c5d 252 if toolchain not in TARGET_MAP[target].supported_toolchains:
group-onsemi 0:098463de4c5d 253 # Log this later
group-onsemi 0:098463de4c5d 254 print "%s skipped: toolchain not supported" % tt_id
group-onsemi 0:098463de4c5d 255 skipped.append(tt_id)
group-onsemi 0:098463de4c5d 256 else:
group-onsemi 0:098463de4c5d 257 try:
group-onsemi 0:098463de4c5d 258 mcu = TARGET_MAP[target]
group-onsemi 0:098463de4c5d 259 profile = extract_profile(parser, options, toolchain)
group-onsemi 0:098463de4c5d 260 if options.source_dir:
group-onsemi 0:098463de4c5d 261 lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain,
group-onsemi 0:098463de4c5d 262 extra_verbose=options.extra_verbose_notify,
group-onsemi 0:098463de4c5d 263 verbose=options.verbose,
group-onsemi 0:098463de4c5d 264 silent=options.silent,
group-onsemi 0:098463de4c5d 265 jobs=options.jobs,
group-onsemi 0:098463de4c5d 266 clean=options.clean,
group-onsemi 0:098463de4c5d 267 archive=(not options.no_archive),
group-onsemi 0:098463de4c5d 268 macros=options.macros,
group-onsemi 0:098463de4c5d 269 name=options.artifact_name,
group-onsemi 0:098463de4c5d 270 build_profile=profile)
group-onsemi 0:098463de4c5d 271 else:
group-onsemi 0:098463de4c5d 272 lib_build_res = build_mbed_libs(mcu, toolchain,
group-onsemi 0:098463de4c5d 273 extra_verbose=options.extra_verbose_notify,
group-onsemi 0:098463de4c5d 274 verbose=options.verbose,
group-onsemi 0:098463de4c5d 275 silent=options.silent,
group-onsemi 0:098463de4c5d 276 jobs=options.jobs,
group-onsemi 0:098463de4c5d 277 clean=options.clean,
group-onsemi 0:098463de4c5d 278 macros=options.macros,
group-onsemi 0:098463de4c5d 279 build_profile=profile)
group-onsemi 0:098463de4c5d 280
group-onsemi 0:098463de4c5d 281 for lib_id in libraries:
group-onsemi 0:098463de4c5d 282 build_lib(lib_id, mcu, toolchain,
group-onsemi 0:098463de4c5d 283 extra_verbose=options.extra_verbose_notify,
group-onsemi 0:098463de4c5d 284 verbose=options.verbose,
group-onsemi 0:098463de4c5d 285 silent=options.silent,
group-onsemi 0:098463de4c5d 286 clean=options.clean,
group-onsemi 0:098463de4c5d 287 macros=options.macros,
group-onsemi 0:098463de4c5d 288 jobs=options.jobs,
group-onsemi 0:098463de4c5d 289 build_profile=profile)
group-onsemi 0:098463de4c5d 290 if lib_build_res:
group-onsemi 0:098463de4c5d 291 successes.append(tt_id)
group-onsemi 0:098463de4c5d 292 else:
group-onsemi 0:098463de4c5d 293 skipped.append(tt_id)
group-onsemi 0:098463de4c5d 294 except Exception, e:
group-onsemi 0:098463de4c5d 295 if options.verbose:
group-onsemi 0:098463de4c5d 296 import traceback
group-onsemi 0:098463de4c5d 297 traceback.print_exc(file=sys.stdout)
group-onsemi 0:098463de4c5d 298 sys.exit(1)
group-onsemi 0:098463de4c5d 299 failures.append(tt_id)
group-onsemi 0:098463de4c5d 300 print e
group-onsemi 0:098463de4c5d 301
group-onsemi 0:098463de4c5d 302 # Write summary of the builds
group-onsemi 0:098463de4c5d 303 print
group-onsemi 0:098463de4c5d 304 print "Completed in: (%.2f)s" % (time() - start)
group-onsemi 0:098463de4c5d 305 print
group-onsemi 0:098463de4c5d 306
group-onsemi 0:098463de4c5d 307 for report, report_name in [(successes, "Build successes:"),
group-onsemi 0:098463de4c5d 308 (skipped, "Build skipped:"),
group-onsemi 0:098463de4c5d 309 (failures, "Build failures:"),
group-onsemi 0:098463de4c5d 310 ]:
group-onsemi 0:098463de4c5d 311 if report:
group-onsemi 0:098463de4c5d 312 print print_build_results(report, report_name),
group-onsemi 0:098463de4c5d 313
group-onsemi 0:098463de4c5d 314 if failures:
group-onsemi 0:098463de4c5d 315 sys.exit(1)