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