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.
detect_targets.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 import sys 00019 import os 00020 import re 00021 00022 ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) 00023 sys.path.insert(0, ROOT) 00024 00025 from tools.options import get_default_options_parser 00026 00027 # Check: Extra modules which are required by core test suite 00028 from tools.utils import check_required_modules 00029 check_required_modules(['prettytable']) 00030 00031 # Imports related to mbed build api 00032 from tools.build_api import mcu_toolchain_matrix 00033 from tools.test_api import get_autodetected_MUTS_list 00034 from tools.test_api import get_module_avail 00035 from argparse import ArgumentParser 00036 00037 try: 00038 import mbed_lstools 00039 except: 00040 pass 00041 00042 def main(): 00043 """Entry Point""" 00044 try: 00045 # Parse Options 00046 parser = ArgumentParser() 00047 00048 parser.add_argument("-S", "--supported-toolchains", 00049 action="store_true", 00050 dest="supported_toolchains", 00051 default=False, 00052 help="Displays supported matrix of" 00053 " targets and toolchains") 00054 00055 parser.add_argument('-f', '--filter', 00056 dest='general_filter_regex', 00057 default=None, 00058 help='Filter targets') 00059 00060 parser.add_argument("-v", "--verbose", 00061 action="store_true", 00062 dest="verbose", 00063 default=False, 00064 help="Verbose diagnostic output") 00065 00066 options = parser.parse_args() 00067 00068 # Only prints matrix of supported toolchains 00069 if options.supported_toolchains: 00070 print mcu_toolchain_matrix( 00071 platform_filter=options.general_filter_regex) 00072 exit(0) 00073 00074 # If auto_detect attribute is present, we assume other auto-detection 00075 # parameters like 'toolchains_filter' are also set. 00076 muts = get_autodetected_MUTS_list() 00077 00078 mcu_filter = options.general_filter_regex or ".*" 00079 00080 count = 0 00081 for mut in muts.values(): 00082 if re.match(mcu_filter, mut['mcu']): 00083 interface_version = get_interface_version(mut['disk']) 00084 print "" 00085 print "[mbed] Detected %s, port %s, mounted %s, interface version %s:" % \ 00086 (mut['mcu'], mut['port'], mut['disk'], interface_version) 00087 00088 print "[mbed] Supported toolchains for %s" % mut['mcu'] 00089 print mcu_toolchain_matrix(platform_filter=mut['mcu']) 00090 count += 1 00091 00092 if count == 0: 00093 print "[mbed] No mbed targets were detected on your system." 00094 00095 except KeyboardInterrupt: 00096 print "\n[CTRL+c] exit" 00097 except Exception as exc: 00098 import traceback 00099 traceback.print_exc(file=sys.stdout) 00100 print "[ERROR] %s" % str(exc) 00101 sys.exit(1) 00102 00103 def get_interface_version(mount_point): 00104 """ Function returns interface version from the target mounted on the specified mount point 00105 00106 mount_point can be acquired via the following: 00107 muts = get_autodetected_MUTS_list() 00108 for mut in muts.values(): 00109 mount_point = mut['disk'] 00110 00111 @param mount_point Name of disk where platform is connected to host machine. 00112 """ 00113 if get_module_avail('mbed_lstools'): 00114 try : 00115 mbeds = mbed_lstools.create() 00116 details_txt = mbeds.get_details_txt(mount_point) 00117 00118 if 'Interface Version' in details_txt: 00119 return details_txt['Interface Version'] 00120 00121 elif 'Version' in details_txt: 00122 return details_txt['Version'] 00123 00124 except : 00125 return 'unknown' 00126 00127 return 'unknown' 00128 00129 if __name__ == '__main__': 00130 main()
Generated on Thu Jul 14 2022 14:36:14 by
