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: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
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.utils import NotSupportedException 00033 from tools.paths import BUILD_DIR 00034 from tools.paths import MBED_LIBRARIES 00035 from tools.paths import RTOS_LIBRARIES 00036 from tools.paths import RPC_LIBRARY 00037 from tools.paths import ETH_LIBRARY 00038 from tools.paths import USB_HOST_LIBRARIES, USB_LIBRARIES 00039 from tools.paths import DSP_LIBRARIES 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, 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("--ublox", 00165 action="store_true", 00166 dest="ublox", 00167 default=False, 00168 help="Link with U-Blox library") 00169 00170 parser.add_argument("--testlib", 00171 action="store_true", 00172 dest="testlib", 00173 default=False, 00174 help="Link with mbed test library") 00175 00176 # Specify a different linker script 00177 parser.add_argument("-l", "--linker", dest="linker_script", 00178 type=argparse_filestring_type, 00179 default=None, help="use the specified linker script") 00180 00181 options = parser.parse_args() 00182 00183 # Only prints matrix of supported toolchains 00184 if options.supported_toolchains: 00185 print mcu_toolchain_matrix(platform_filter=options.general_filter_regex) 00186 exit(0) 00187 00188 # Print available tests in order and exit 00189 if options.list_tests is True: 00190 print '\n'.join(map(str, sorted(TEST_MAP.values()))) 00191 sys.exit() 00192 00193 # force program to "0" if a source dir is specified 00194 if options.source_dir is not None: 00195 p = 0 00196 else: 00197 # Program Number or name 00198 p = options.program 00199 00200 # If 'p' was set via -n to list of numbers make this a single element integer list 00201 if type(p) != type([]): 00202 p = [p] 00203 00204 # Target 00205 if options.mcu is None : 00206 args_error(parser, "argument -m/--mcu is required") 00207 mcu = options.mcu[0] 00208 00209 # Toolchain 00210 if options.tool is None: 00211 args_error(parser, "argument -t/--tool is required") 00212 toolchain = options.tool[0] 00213 00214 if (options.program is None) and (not options.source_dir): 00215 args_error(parser, "one of -p, -n, or --source is required") 00216 00217 if options.source_dir and not options.build_dir: 00218 args_error(parser, "argument --build is required when argument --source is provided") 00219 00220 00221 if options.color: 00222 # This import happens late to prevent initializing colorization when we don't need it 00223 import colorize 00224 if options.verbose: 00225 notify = mbedToolchain.print_notify_verbose 00226 else: 00227 notify = mbedToolchain.print_notify 00228 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) 00229 else: 00230 notify = None 00231 00232 if not TOOLCHAIN_CLASSES[toolchain].check_executable(): 00233 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" 00234 args_error(parser, "Could not find executable for %s.\n" 00235 "Currently set search path: %s" 00236 %(toolchain,search_path)) 00237 00238 # Test 00239 for test_no in p: 00240 test = Test(test_no) 00241 if options.automated is not None: test.automated = options.automated 00242 if options.dependencies is not None: test.dependencies = options.dependencies 00243 if options.host_test is not None: test.host_test = options.host_test; 00244 if options.peripherals is not None: test.peripherals = options.peripherals; 00245 if options.duration is not None: test.duration = options.duration; 00246 if options.extra is not None: test.extra_files = options.extra 00247 00248 if not test.is_supported(mcu, toolchain): 00249 print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) 00250 sys.exit() 00251 00252 # Linking with extra libraries 00253 if options.rtos: test.dependencies.append(RTOS_LIBRARIES) 00254 if options.rpc: test.dependencies.append(RPC_LIBRARY) 00255 if options.eth: test.dependencies.append(ETH_LIBRARY) 00256 if options.usb_host: test.dependencies.append(USB_HOST_LIBRARIES) 00257 if options.usb: test.dependencies.append(USB_LIBRARIES) 00258 if options.dsp: test.dependencies.append(DSP_LIBRARIES) 00259 if options.ublox: test.dependencies.append(UBLOX_LIBRARY) 00260 if options.testlib: test.dependencies.append(TEST_MBED_LIB) 00261 00262 build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) 00263 if options.source_dir is not None: 00264 test.source_dir = options.source_dir 00265 build_dir = options.source_dir 00266 00267 if options.build_dir is not None: 00268 build_dir = options.build_dir 00269 00270 try: 00271 bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, 00272 set(test.dependencies), 00273 linker_script=options.linker_script, 00274 clean=options.clean, 00275 verbose=options.verbose, 00276 notify=notify, 00277 silent=options.silent, 00278 macros=options.macros, 00279 jobs=options.jobs, 00280 name=options.artifact_name, 00281 app_config=options.app_config, 00282 inc_dirs=[dirname(MBED_LIBRARIES)], 00283 build_profile=extract_profile(parser, 00284 options, 00285 toolchain)) 00286 print 'Image: %s'% bin_file 00287 00288 if options.disk: 00289 # Simple copy to the mbed disk 00290 copy(bin_file, options.disk) 00291 00292 if options.serial: 00293 # Import pyserial: https://pypi.python.org/pypi/pyserial 00294 from serial import Serial 00295 00296 sleep(TARGET_MAP[mcu].program_cycle_s) 00297 00298 serial = Serial(options.serial, timeout = 1) 00299 if options.baud: 00300 serial.setBaudrate(options.baud) 00301 00302 serial.flushInput() 00303 serial.flushOutput() 00304 00305 try: 00306 serial.sendBreak() 00307 except: 00308 # In linux a termios.error is raised in sendBreak and in setBreak. 00309 # The following setBreak() is needed to release the reset signal on the target mcu. 00310 try: 00311 serial.setBreak(False) 00312 except: 00313 pass 00314 00315 while True: 00316 c = serial.read(512) 00317 sys.stdout.write(c) 00318 sys.stdout.flush() 00319 00320 except KeyboardInterrupt, e: 00321 print "\n[CTRL+c] exit" 00322 except NotSupportedException, e: 00323 print "\nNot supported for selected target" 00324 except Exception,e: 00325 if options.verbose: 00326 import traceback 00327 traceback.print_exc(file=sys.stdout) 00328 else: 00329 print "[ERROR] %s" % str(e) 00330 00331 sys.exit(1)
Generated on Tue Jul 12 2022 11:02:29 by
1.7.2