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.
Fork of mbed-tools by
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 from time import sleep 00023 from shutil import copy 00024 from os.path import join, abspath, dirname 00025 00026 # Be sure that the tools directory is in the search path 00027 ROOT = abspath(join(dirname(__file__), "..")) 00028 sys.path.insert(0, ROOT) 00029 00030 from tools.utils import args_error 00031 from tools.paths import BUILD_DIR 00032 from tools.paths import RTOS_LIBRARIES 00033 from tools.paths import RPC_LIBRARY 00034 from tools.paths import ETH_LIBRARY 00035 from tools.paths import USB_HOST_LIBRARIES, USB_LIBRARIES 00036 from tools.paths import DSP_LIBRARIES 00037 from tools.paths import FS_LIBRARY 00038 from tools.paths import UBLOX_LIBRARY 00039 from tools.tests import TESTS, Test, TEST_MAP 00040 from tools.tests import TEST_MBED_LIB 00041 from tools.targets import TARGET_MAP 00042 from tools.options import get_default_options_parser 00043 from tools.build_api import build_project 00044 try: 00045 import tools.private_settings as ps 00046 except: 00047 ps = object() 00048 00049 00050 if __name__ == '__main__': 00051 # Parse Options 00052 parser = get_default_options_parser() 00053 parser.add_option("-p", 00054 type="int", 00055 dest="program", 00056 help="The index of the desired test program: [0-%d]" % (len(TESTS)-1)) 00057 00058 parser.add_option("-n", 00059 dest="program_name", 00060 help="The name of the desired test program") 00061 00062 parser.add_option("-j", "--jobs", 00063 type="int", 00064 dest="jobs", 00065 default=1, 00066 help="Number of concurrent jobs (default 1). Use 0 for auto based on host machine's number of CPUs") 00067 00068 parser.add_option("-v", "--verbose", 00069 action="store_true", 00070 dest="verbose", 00071 default=False, 00072 help="Verbose diagnostic output") 00073 00074 parser.add_option("--silent", 00075 action="store_true", 00076 dest="silent", 00077 default=False, 00078 help="Silent diagnostic output (no copy, compile notification)") 00079 00080 parser.add_option("-D", "", 00081 action="append", 00082 dest="macros", 00083 help="Add a macro definition") 00084 00085 # Local run 00086 parser.add_option("--automated", action="store_true", dest="automated", 00087 default=False, help="Automated test") 00088 parser.add_option("--host", dest="host_test", 00089 default=None, help="Host test") 00090 parser.add_option("--extra", dest="extra", 00091 default=None, help="Extra files") 00092 parser.add_option("--peripherals", dest="peripherals", 00093 default=None, help="Required peripherals") 00094 parser.add_option("--dep", dest="dependencies", 00095 default=None, help="Dependencies") 00096 parser.add_option("--source", dest="source_dir", 00097 default=None, help="The source (input) directory") 00098 parser.add_option("--duration", type="int", dest="duration", 00099 default=None, help="Duration of the test") 00100 parser.add_option("--build", dest="build_dir", 00101 default=None, help="The build (output) directory") 00102 parser.add_option("-d", "--disk", dest="disk", 00103 default=None, help="The mbed disk") 00104 parser.add_option("-s", "--serial", dest="serial", 00105 default=None, help="The mbed serial port") 00106 parser.add_option("-b", "--baud", type="int", dest="baud", 00107 default=None, help="The mbed serial baud rate") 00108 parser.add_option("-L", "--list-tests", action="store_true", dest="list_tests", 00109 default=False, help="List available tests in order and exit") 00110 00111 # Ideally, all the tests with a single "main" thread can be run with, or 00112 # without the rtos, eth, usb_host, usb, dsp, fat, ublox 00113 parser.add_option("--rtos", 00114 action="store_true", dest="rtos", 00115 default=False, help="Link with RTOS library") 00116 00117 parser.add_option("--rpc", 00118 action="store_true", dest="rpc", 00119 default=False, help="Link with RPC library") 00120 00121 parser.add_option("--eth", 00122 action="store_true", dest="eth", 00123 default=False, 00124 help="Link with Ethernet library") 00125 00126 parser.add_option("--usb_host", 00127 action="store_true", 00128 dest="usb_host", 00129 default=False, 00130 help="Link with USB Host library") 00131 00132 parser.add_option("--usb", 00133 action="store_true", 00134 dest="usb", 00135 default=False, 00136 help="Link with USB Device library") 00137 00138 parser.add_option("--dsp", 00139 action="store_true", 00140 dest="dsp", 00141 default=False, 00142 help="Link with DSP library") 00143 00144 parser.add_option("--fat", 00145 action="store_true", 00146 dest="fat", 00147 default=False, 00148 help="Link with FS ad SD card file system library") 00149 00150 parser.add_option("--ublox", 00151 action="store_true", 00152 dest="ublox", 00153 default=False, 00154 help="Link with U-Blox library") 00155 00156 parser.add_option("--testlib", 00157 action="store_true", 00158 dest="testlib", 00159 default=False, 00160 help="Link with mbed test library") 00161 00162 # Specify a different linker script 00163 parser.add_option("-l", "--linker", dest="linker_script", 00164 default=None, help="use the specified linker script") 00165 00166 (options, args) = parser.parse_args() 00167 00168 # Print available tests in order and exit 00169 if options.list_tests is True: 00170 print '\n'.join(map(str, sorted(TEST_MAP.values()))) 00171 sys.exit() 00172 00173 # force program to "0" if a source dir is specified 00174 if options.source_dir is not None: 00175 p = 0 00176 n = None 00177 else: 00178 # Program Number or name 00179 p, n = options.program, options.program_name 00180 00181 if n is not None and p is not None: 00182 args_error(parser, "[ERROR] specify either '-n' or '-p', not both") 00183 if n: 00184 # We will transform 'n' to list of 'p' (integers which are test numbers) 00185 nlist = n.split(',') 00186 for test_id in nlist: 00187 if test_id not in TEST_MAP.keys(): 00188 args_error(parser, "[ERROR] Program with name '%s' not found"% test_id) 00189 00190 p = [TEST_MAP[n].n for n in nlist] 00191 elif p is None or (p < 0) or (p > (len(TESTS)-1)): 00192 message = "[ERROR] You have to specify one of the following tests:\n" 00193 message += '\n'.join(map(str, sorted(TEST_MAP.values()))) 00194 args_error(parser, message) 00195 00196 # If 'p' was set via -n to list of numbers make this a single element integer list 00197 if type(p) != type([]): 00198 p = [p] 00199 00200 # Target 00201 if options.mcu is None : 00202 args_error(parser, "[ERROR] You should specify an MCU") 00203 mcu = options.mcu 00204 00205 # Toolchain 00206 if options.tool is None: 00207 args_error(parser, "[ERROR] You should specify a TOOLCHAIN") 00208 toolchain = options.tool 00209 00210 # Test 00211 for test_no in p: 00212 test = Test(test_no) 00213 if options.automated is not None: test.automated = options.automated 00214 if options.dependencies is not None: test.dependencies = options.dependencies 00215 if options.host_test is not None: test.host_test = options.host_test; 00216 if options.peripherals is not None: test.peripherals = options.peripherals; 00217 if options.duration is not None: test.duration = options.duration; 00218 if options.extra is not None: test.extra_files = options.extra 00219 00220 if not test.is_supported(mcu, toolchain): 00221 print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) 00222 sys.exit() 00223 00224 # Linking with extra libraries 00225 if options.rtos: test.dependencies.append(RTOS_LIBRARIES) 00226 if options.rpc: test.dependencies.append(RPC_LIBRARY) 00227 if options.eth: test.dependencies.append(ETH_LIBRARY) 00228 if options.usb_host: test.dependencies.append(USB_HOST_LIBRARIES) 00229 if options.usb: test.dependencies.append(USB_LIBRARIES) 00230 if options.dsp: test.dependencies.append(DSP_LIBRARIES) 00231 if options.fat: test.dependencies.append(FS_LIBRARY) 00232 if options.ublox: test.dependencies.append(UBLOX_LIBRARY) 00233 if options.testlib: test.dependencies.append(TEST_MBED_LIB) 00234 00235 build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) 00236 if options.source_dir is not None: 00237 test.source_dir = options.source_dir 00238 build_dir = options.source_dir 00239 00240 if options.build_dir is not None: 00241 build_dir = options.build_dir 00242 00243 target = TARGET_MAP[mcu] 00244 try: 00245 bin_file = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, options.options, 00246 linker_script=options.linker_script, 00247 clean=options.clean, 00248 verbose=options.verbose, 00249 silent=options.silent, 00250 macros=options.macros, 00251 jobs=options.jobs) 00252 print 'Image: %s'% bin_file 00253 00254 if options.disk: 00255 # Simple copy to the mbed disk 00256 copy(bin_file, options.disk) 00257 00258 if options.serial: 00259 # Import pyserial: https://pypi.python.org/pypi/pyserial 00260 from serial import Serial 00261 00262 sleep(target.program_cycle_s()) 00263 00264 serial = Serial(options.serial, timeout = 1) 00265 if options.baud: 00266 serial.setBaudrate(options.baud) 00267 00268 serial.flushInput() 00269 serial.flushOutput() 00270 00271 try: 00272 serial.sendBreak() 00273 except: 00274 # In linux a termios.error is raised in sendBreak and in setBreak. 00275 # The following setBreak() is needed to release the reset signal on the target mcu. 00276 try: 00277 serial.setBreak(False) 00278 except: 00279 pass 00280 00281 while True: 00282 c = serial.read(512) 00283 sys.stdout.write(c) 00284 sys.stdout.flush() 00285 00286 except KeyboardInterrupt, e: 00287 print "\n[CTRL+c] exit" 00288 except Exception,e: 00289 if options.verbose: 00290 import traceback 00291 traceback.print_exc(file=sys.stdout) 00292 else: 00293 print "[ERROR] %s" % str(e)
Generated on Thu Aug 11 2022 22:20:37 by
1.7.2
