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.
Dependents: BLE_file_test BLE_Blink ExternalEncoder
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 import sys 00022 import json 00023 from time import sleep 00024 from shutil import copy 00025 from os.path import join, abspath, dirname 00026 00027 # Be sure that the tools directory is in the search path 00028 ROOT = abspath(join(dirname(__file__), "..")) 00029 sys.path.insert(0, ROOT) 00030 00031 from tools.utils import args_error 00032 from tools.paths import BUILD_DIR 00033 from tools.paths import MBED_LIBRARIES 00034 from tools.paths import RTOS_LIBRARIES 00035 from tools.paths import RPC_LIBRARY 00036 from tools.paths import ETH_LIBRARY 00037 from tools.paths import USB_HOST_LIBRARIES, USB_LIBRARIES 00038 from tools.paths import DSP_LIBRARIES 00039 from tools.paths import FS_LIBRARY 00040 from tools.paths import UBLOX_LIBRARY 00041 from tools.tests import TESTS, Test, TEST_MAP 00042 from tools.tests import TEST_MBED_LIB 00043 from tools.tests import test_known, test_name_known 00044 from tools.targets import TARGET_MAP 00045 from tools.options import get_default_options_parser 00046 from tools.options import extract_profile 00047 from tools.build_api import build_project 00048 from tools.build_api import mcu_toolchain_matrix 00049 from utils import argparse_filestring_type 00050 from utils import argparse_many 00051 from utils import argparse_dir_not_parent 00052 from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS 00053 from tools.settings import CLI_COLOR_MAP 00054 00055 if __name__ == '__main__': 00056 # Parse Options 00057 parser = get_default_options_parser(add_app_config=True) 00058 group = parser.add_mutually_exclusive_group(required=False) 00059 group.add_argument("-p", 00060 type=argparse_many(test_known), 00061 dest="program", 00062 help="The index of the desired test program: [0-%d]" % (len(TESTS)-1)) 00063 00064 group.add_argument("-n", 00065 type=argparse_many(test_name_known), 00066 dest="program", 00067 help="The name of the desired test program") 00068 00069 parser.add_argument("-j", "--jobs", 00070 type=int, 00071 dest="jobs", 00072 default=0, 00073 help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") 00074 00075 parser.add_argument("-v", "--verbose", 00076 action="store_true", 00077 dest="verbose", 00078 default=False, 00079 help="Verbose diagnostic output") 00080 00081 parser.add_argument("--silent", 00082 action="store_true", 00083 dest="silent", 00084 default=False, 00085 help="Silent diagnostic output (no copy, compile notification)") 00086 00087 parser.add_argument("-D", 00088 action="append", 00089 dest="macros", 00090 help="Add a macro definition") 00091 00092 group.add_argument("-S", "--supported-toolchains", 00093 action="store_true", 00094 dest="supported_toolchains", 00095 default=False, 00096 help="Displays supported matrix of MCUs and toolchains") 00097 00098 parser.add_argument('-f', '--filter', 00099 dest='general_filter_regex', 00100 default=None, 00101 help='For some commands you can use filter to filter out results') 00102 00103 # Local run 00104 parser.add_argument("--automated", action="store_true", dest="automated", 00105 default=False, help="Automated test") 00106 parser.add_argument("--host", dest="host_test", 00107 default=None, help="Host test") 00108 parser.add_argument("--extra", dest="extra", 00109 default=None, help="Extra files") 00110 parser.add_argument("--peripherals", dest="peripherals", 00111 default=None, help="Required peripherals") 00112 parser.add_argument("--dep", dest="dependencies", 00113 default=None, help="Dependencies") 00114 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, 00115 default=None, help="The source (input) directory", action="append") 00116 parser.add_argument("--duration", type=int, dest="duration", 00117 default=None, help="Duration of the test") 00118 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), 00119 default=None, help="The build (output) directory") 00120 parser.add_argument("-N", "--artifact-name", dest="artifact_name", 00121 default=None, help="The built project's name") 00122 parser.add_argument("-d", "--disk", dest="disk", 00123 default=None, help="The mbed disk") 00124 parser.add_argument("-s", "--serial", dest="serial", 00125 default=None, help="The mbed serial port") 00126 parser.add_argument("-b", "--baud", type=int, dest="baud", 00127 default=None, help="The mbed serial baud rate") 00128 group.add_argument("-L", "--list-tests", action="store_true", dest="list_tests", 00129 default=False, help="List available tests in order and exit") 00130 00131 # Ideally, all the tests with a single "main" thread can be run with, or 00132 # without the rtos, eth, usb_host, usb, dsp, fat, ublox 00133 parser.add_argument("--rtos", 00134 action="store_true", dest="rtos", 00135 default=False, help="Link with RTOS library") 00136 00137 parser.add_argument("--rpc", 00138 action="store_true", dest="rpc", 00139 default=False, help="Link with RPC library") 00140 00141 parser.add_argument("--eth", 00142 action="store_true", dest="eth", 00143 default=False, 00144 help="Link with Ethernet library") 00145 00146 parser.add_argument("--usb_host", 00147 action="store_true", 00148 dest="usb_host", 00149 default=False, 00150 help="Link with USB Host library") 00151 00152 parser.add_argument("--usb", 00153 action="store_true", 00154 dest="usb", 00155 default=False, 00156 help="Link with USB Device library") 00157 00158 parser.add_argument("--dsp", 00159 action="store_true", 00160 dest="dsp", 00161 default=False, 00162 help="Link with DSP library") 00163 00164 parser.add_argument("--fat", 00165 action="store_true", 00166 dest="fat", 00167 default=False, 00168 help="Link with FS ad SD card file system library") 00169 00170 parser.add_argument("--ublox", 00171 action="store_true", 00172 dest="ublox", 00173 default=False, 00174 help="Link with U-Blox library") 00175 00176 parser.add_argument("--testlib", 00177 action="store_true", 00178 dest="testlib", 00179 default=False, 00180 help="Link with mbed test library") 00181 00182 # Specify a different linker script 00183 parser.add_argument("-l", "--linker", dest="linker_script", 00184 type=argparse_filestring_type, 00185 default=None, help="use the specified linker script") 00186 00187 options = parser.parse_args() 00188 00189 # Only prints matrix of supported toolchains 00190 if options.supported_toolchains: 00191 print mcu_toolchain_matrix(platform_filter=options.general_filter_regex) 00192 exit(0) 00193 00194 # Print available tests in order and exit 00195 if options.list_tests is True: 00196 print '\n'.join(map(str, sorted(TEST_MAP.values()))) 00197 sys.exit() 00198 00199 # force program to "0" if a source dir is specified 00200 if options.source_dir is not None: 00201 p = 0 00202 else: 00203 # Program Number or name 00204 p = options.program 00205 00206 # If 'p' was set via -n to list of numbers make this a single element integer list 00207 if type(p) != type([]): 00208 p = [p] 00209 00210 # Target 00211 if options.mcu is None : 00212 args_error(parser, "argument -m/--mcu is required") 00213 mcu = options.mcu[0] 00214 00215 # Toolchain 00216 if options.tool is None: 00217 args_error(parser, "argument -t/--tool is required") 00218 toolchain = options.tool[0] 00219 00220 if (options.program is None) and (not options.source_dir): 00221 args_error(parser, "one of -p, -n, or --source is required") 00222 00223 if options.source_dir and not options.build_dir: 00224 args_error(parser, "argument --build is required when argument --source is provided") 00225 00226 00227 if options.color: 00228 # This import happens late to prevent initializing colorization when we don't need it 00229 import colorize 00230 if options.verbose: 00231 notify = mbedToolchain.print_notify_verbose 00232 else: 00233 notify = mbedToolchain.print_notify 00234 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) 00235 else: 00236 notify = None 00237 00238 if not TOOLCHAIN_CLASSES[toolchain].check_executable(): 00239 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" 00240 args_error(parser, "Could not find executable for %s.\n" 00241 "Currently set search path: %s" 00242 %(toolchain,search_path)) 00243 00244 # Test 00245 for test_no in p: 00246 test = Test(test_no) 00247 if options.automated is not None: test.automated = options.automated 00248 if options.dependencies is not None: test.dependencies = options.dependencies 00249 if options.host_test is not None: test.host_test = options.host_test; 00250 if options.peripherals is not None: test.peripherals = options.peripherals; 00251 if options.duration is not None: test.duration = options.duration; 00252 if options.extra is not None: test.extra_files = options.extra 00253 00254 if not test.is_supported(mcu, toolchain): 00255 print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) 00256 sys.exit() 00257 00258 # Linking with extra libraries 00259 if options.rtos: test.dependencies.append(RTOS_LIBRARIES) 00260 if options.rpc: test.dependencies.append(RPC_LIBRARY) 00261 if options.eth: test.dependencies.append(ETH_LIBRARY) 00262 if options.usb_host: test.dependencies.append(USB_HOST_LIBRARIES) 00263 if options.usb: test.dependencies.append(USB_LIBRARIES) 00264 if options.dsp: test.dependencies.append(DSP_LIBRARIES) 00265 if options.fat: test.dependencies.append(FS_LIBRARY) 00266 if options.ublox: test.dependencies.append(UBLOX_LIBRARY) 00267 if options.testlib: test.dependencies.append(TEST_MBED_LIB) 00268 00269 build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) 00270 if options.source_dir is not None: 00271 test.source_dir = options.source_dir 00272 build_dir = options.source_dir 00273 00274 if options.build_dir is not None: 00275 build_dir = options.build_dir 00276 00277 try: 00278 bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, 00279 test.dependencies, 00280 linker_script=options.linker_script, 00281 clean=options.clean, 00282 verbose=options.verbose, 00283 notify=notify, 00284 silent=options.silent, 00285 macros=options.macros, 00286 jobs=options.jobs, 00287 name=options.artifact_name, 00288 app_config=options.app_config, 00289 inc_dirs=[dirname(MBED_LIBRARIES)], 00290 build_profile=extract_profile(parser, 00291 options, 00292 toolchain)) 00293 print 'Image: %s'% bin_file 00294 00295 if options.disk: 00296 # Simple copy to the mbed disk 00297 copy(bin_file, options.disk) 00298 00299 if options.serial: 00300 # Import pyserial: https://pypi.python.org/pypi/pyserial 00301 from serial import Serial 00302 00303 sleep(TARGET_MAP[mcu].program_cycle_s) 00304 00305 serial = Serial(options.serial, timeout = 1) 00306 if options.baud: 00307 serial.setBaudrate(options.baud) 00308 00309 serial.flushInput() 00310 serial.flushOutput() 00311 00312 try: 00313 serial.sendBreak() 00314 except: 00315 # In linux a termios.error is raised in sendBreak and in setBreak. 00316 # The following setBreak() is needed to release the reset signal on the target mcu. 00317 try: 00318 serial.setBreak(False) 00319 except: 00320 pass 00321 00322 while True: 00323 c = serial.read(512) 00324 sys.stdout.write(c) 00325 sys.stdout.flush() 00326 00327 except KeyboardInterrupt, e: 00328 print "\n[CTRL+c] exit" 00329 except Exception,e: 00330 if options.verbose: 00331 import traceback 00332 traceback.print_exc(file=sys.stdout) 00333 else: 00334 print "[ERROR] %s" % str(e) 00335 00336 sys.exit(1)
Generated on Tue Jul 12 2022 15:19:41 by
