Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
make.py
00001 #! /usr/bin/env python2 00002 """ 00003 mbed SDK 00004 Copyright (c) 2011-2013 ARM Limited 00005 00006 Licensed under the Apache License, Version 2.0 (the "License"); 00007 you may not use this file except in compliance with the License. 00008 You may obtain a copy of the License at 00009 00010 http://www.apache.org/licenses/LICENSE-2.0 00011 00012 Unless required by applicable law or agreed to in writing, software 00013 distributed under the License is distributed on an "AS IS" BASIS, 00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 See the License for the specific language governing permissions and 00016 limitations under the License. 00017 00018 00019 TEST BUILD & RUN 00020 """ 00021 from __future__ import print_function 00022 import sys 00023 import json 00024 from time import sleep 00025 from shutil import copy 00026 from os.path import join, abspath, dirname 00027 from json import load, dump 00028 00029 # Be sure that the tools directory is in the search path 00030 ROOT = abspath(join(dirname(__file__), "..")) 00031 sys.path.insert(0, ROOT) 00032 00033 from tools.utils import args_error 00034 from tools.utils import NotSupportedException 00035 from tools.paths import BUILD_DIR 00036 from tools.paths import MBED_LIBRARIES 00037 from tools.paths import RPC_LIBRARY 00038 from tools.paths import USB_LIBRARIES 00039 from tools.paths import DSP_LIBRARIES 00040 from tools.tests import TESTS, Test, TEST_MAP 00041 from tools.tests import TEST_MBED_LIB 00042 from tools.tests import test_known, test_name_known 00043 from tools.targets import TARGET_MAP 00044 from tools.options import get_default_options_parser 00045 from tools.options import extract_profile 00046 from tools.options import extract_mcus 00047 from tools.build_api import build_project 00048 from tools.build_api import mcu_toolchain_matrix 00049 from tools.build_api import mcu_toolchain_list 00050 from tools.build_api import mcu_target_list 00051 from tools.build_api import merge_build_data 00052 from utils import argparse_filestring_type 00053 from utils import argparse_many 00054 from utils import argparse_dir_not_parent 00055 from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS 00056 from tools.settings import CLI_COLOR_MAP 00057 00058 if __name__ == '__main__': 00059 # Parse Options 00060 parser = get_default_options_parser(add_app_config=True) 00061 group = parser.add_mutually_exclusive_group(required=False) 00062 group.add_argument( 00063 "-p", 00064 type=argparse_many(test_known), 00065 dest="program", 00066 help="The index of the desired test program: [0-%d]" % (len(TESTS)-1)) 00067 00068 group.add_argument( 00069 "-n", 00070 type=argparse_many(test_name_known), 00071 dest="program", 00072 help="The name of the desired test program") 00073 00074 parser.add_argument( 00075 "-j", "--jobs", 00076 type=int, 00077 dest="jobs", 00078 default=0, 00079 help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") 00080 00081 parser.add_argument( 00082 "-v", "--verbose", 00083 action="store_true", 00084 dest="verbose", 00085 default=False, 00086 help="Verbose diagnostic output") 00087 00088 parser.add_argument( 00089 "--silent", 00090 action="store_true", 00091 dest="silent", 00092 default=False, 00093 help="Silent diagnostic output (no copy, compile notification)") 00094 00095 parser.add_argument( 00096 "-D", 00097 action="append", 00098 dest="macros", 00099 help="Add a macro definition") 00100 00101 group.add_argument( 00102 "-S", "--supported-toolchains", 00103 dest="supported_toolchains", 00104 default=False, 00105 const="matrix", 00106 choices=["matrix", "toolchains", "targets"], 00107 nargs="?", 00108 help="Displays supported matrix of MCUs and toolchains") 00109 00110 parser.add_argument( 00111 '-f', '--filter', 00112 dest='general_filter_regex', 00113 default=None, 00114 help='For some commands you can use filter to filter out results') 00115 00116 parser.add_argument( 00117 "--stats-depth", 00118 type=int, 00119 dest="stats_depth", 00120 default=None, 00121 help="Depth level for static memory report") 00122 00123 # Local run 00124 parser.add_argument("--automated", action="store_true", dest="automated", 00125 default=False, help="Automated test") 00126 parser.add_argument("--host", dest="host_test", 00127 default=None, help="Host test") 00128 parser.add_argument("--extra", dest="extra", 00129 default=None, help="Extra files") 00130 parser.add_argument("--peripherals", dest="peripherals", 00131 default=None, help="Required peripherals") 00132 parser.add_argument("--dep", dest="dependencies", 00133 default=None, help="Dependencies") 00134 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, 00135 default=None, help="The source (input) directory", action="append") 00136 parser.add_argument("--duration", type=int, dest="duration", 00137 default=None, help="Duration of the test") 00138 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), 00139 default=None, help="The build (output) directory") 00140 parser.add_argument("-N", "--artifact-name", dest="artifact_name", 00141 default=None, help="The built project's name") 00142 parser.add_argument("-d", "--disk", dest="disk", 00143 default=None, help="The mbed disk") 00144 parser.add_argument("-s", "--serial", dest="serial", 00145 default=None, help="The mbed serial port") 00146 parser.add_argument("-b", "--baud", type=int, dest="baud", 00147 default=None, help="The mbed serial baud rate") 00148 group.add_argument("-L", "--list-tests", action="store_true", dest="list_tests", 00149 default=False, help="List available tests in order and exit") 00150 00151 # Ideally, all the tests with a single "main" thread can be run with, or 00152 # without the usb, dsp 00153 parser.add_argument("--rpc", 00154 action="store_true", dest="rpc", 00155 default=False, help="Link with RPC library") 00156 00157 parser.add_argument("--usb", 00158 action="store_true", 00159 dest="usb", 00160 default=False, 00161 help="Link with USB Device library") 00162 00163 parser.add_argument("--dsp", 00164 action="store_true", 00165 dest="dsp", 00166 default=False, 00167 help="Link with DSP library") 00168 00169 parser.add_argument("--testlib", 00170 action="store_true", 00171 dest="testlib", 00172 default=False, 00173 help="Link with mbed test library") 00174 00175 parser.add_argument("--build-data", 00176 dest="build_data", 00177 default=None, 00178 help="Dump build_data to this file") 00179 00180 # Specify a different linker script 00181 parser.add_argument("-l", "--linker", dest="linker_script", 00182 type=argparse_filestring_type, 00183 default=None, help="use the specified linker script") 00184 00185 options = parser.parse_args() 00186 00187 # Only prints matrix of supported toolchains 00188 if options.supported_toolchains: 00189 if options.supported_toolchains == "matrix": 00190 print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex)) 00191 elif options.supported_toolchains == "toolchains": 00192 toolchain_list = mcu_toolchain_list() 00193 # Only print the lines that matter 00194 for line in toolchain_list.split("\n"): 00195 if not "mbed" in line: 00196 print(line) 00197 elif options.supported_toolchains == "targets": 00198 print(mcu_target_list()) 00199 exit(0) 00200 00201 # Print available tests in order and exit 00202 if options.list_tests is True: 00203 print('\n'.join(map(str, sorted(TEST_MAP.values())))) 00204 sys.exit() 00205 00206 # force program to "0" if a source dir is specified 00207 if options.source_dir is not None: 00208 p = 0 00209 else: 00210 # Program Number or name 00211 p = options.program 00212 00213 # If 'p' was set via -n to list of numbers make this a single element integer list 00214 if type(p) != type([]): 00215 p = [p] 00216 00217 # Target 00218 if options.mcu is None : 00219 args_error(parser, "argument -m/--mcu is required") 00220 mcu = extract_mcus(parser, options)[0] 00221 00222 # Toolchain 00223 if options.tool is None: 00224 args_error(parser, "argument -t/--tool is required") 00225 toolchain = options.tool[0] 00226 00227 if (options.program is None) and (not options.source_dir): 00228 args_error(parser, "one of -p, -n, or --source is required") 00229 00230 if options.source_dir and not options.build_dir: 00231 args_error(parser, "argument --build is required when argument --source is provided") 00232 00233 00234 if options.color: 00235 # This import happens late to prevent initializing colorization when we don't need it 00236 import colorize 00237 if options.verbose: 00238 notify = mbedToolchain.print_notify_verbose 00239 else: 00240 notify = mbedToolchain.print_notify 00241 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) 00242 else: 00243 notify = None 00244 00245 if not TOOLCHAIN_CLASSES[toolchain].check_executable(): 00246 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" 00247 args_error(parser, "Could not find executable for %s.\n" 00248 "Currently set search path: %s" 00249 %(toolchain, search_path)) 00250 00251 # Test 00252 build_data_blob = {} if options.build_data else None 00253 for test_no in p: 00254 test = Test(test_no) 00255 if options.automated is not None: test.automated = options.automated 00256 if options.dependencies is not None: test.dependencies = options.dependencies 00257 if options.host_test is not None: test.host_test = options.host_test; 00258 if options.peripherals is not None: test.peripherals = options.peripherals; 00259 if options.duration is not None: test.duration = options.duration; 00260 if options.extra is not None: test.extra_files = options.extra 00261 00262 if not test.is_supported(mcu, toolchain): 00263 print('The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)) 00264 sys.exit() 00265 00266 # Linking with extra libraries 00267 if options.rpc: test.dependencies.append(RPC_LIBRARY) 00268 if options.usb: test.dependencies.append(USB_LIBRARIES) 00269 if options.dsp: test.dependencies.append(DSP_LIBRARIES) 00270 if options.testlib: test.dependencies.append(TEST_MBED_LIB) 00271 00272 build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) 00273 if options.source_dir is not None: 00274 test.source_dir = options.source_dir 00275 build_dir = options.source_dir 00276 00277 if options.build_dir is not None: 00278 build_dir = options.build_dir 00279 00280 try: 00281 bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, 00282 set(test.dependencies), 00283 linker_script=options.linker_script, 00284 clean=options.clean, 00285 verbose=options.verbose, 00286 notify=notify, 00287 report=build_data_blob, 00288 silent=options.silent, 00289 macros=options.macros, 00290 jobs=options.jobs, 00291 name=options.artifact_name, 00292 app_config=options.app_config, 00293 inc_dirs=[dirname(MBED_LIBRARIES)], 00294 build_profile=extract_profile(parser, 00295 options, 00296 toolchain), 00297 stats_depth=options.stats_depth) 00298 print('Image: %s'% bin_file) 00299 00300 if options.disk: 00301 # Simple copy to the mbed disk 00302 copy(bin_file, options.disk) 00303 00304 if options.serial: 00305 # Import pyserial: https://pypi.python.org/pypi/pyserial 00306 from serial import Serial 00307 00308 sleep(TARGET_MAP[mcu].program_cycle_s) 00309 00310 serial = Serial(options.serial, timeout = 1) 00311 if options.baud: 00312 serial.setBaudrate(options.baud) 00313 00314 serial.flushInput() 00315 serial.flushOutput() 00316 00317 try: 00318 serial.sendBreak() 00319 except: 00320 # In linux a termios.error is raised in sendBreak and in setBreak. 00321 # The following setBreak() is needed to release the reset signal on the target mcu. 00322 try: 00323 serial.setBreak(False) 00324 except: 00325 pass 00326 00327 while True: 00328 c = serial.read(512) 00329 sys.stdout.write(c) 00330 sys.stdout.flush() 00331 00332 except KeyboardInterrupt as e: 00333 print("\n[CTRL+c] exit") 00334 except NotSupportedException as e: 00335 print("\nCould not compile for %s: %s" % (mcu, str(e))) 00336 except Exception as e: 00337 if options.verbose: 00338 import traceback 00339 traceback.print_exc(file=sys.stdout) 00340 else: 00341 print("[ERROR] %s" % str(e)) 00342 00343 sys.exit(1) 00344 if options.build_data: 00345 merge_build_data(options.build_data, build_data_blob, "application")
Generated on Tue Jul 12 2022 13:24:57 by
1.7.2