当前位置: 首页>>代码示例>>Python>>正文


Python board.MbedBoard类代码示例

本文整理汇总了Python中pyOCD.board.MbedBoard的典型用法代码示例。如果您正苦于以下问题:Python MbedBoard类的具体用法?Python MbedBoard怎么用?Python MbedBoard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MbedBoard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    args = parser.parse_args()
    gdb_server_settings = get_gdb_server_settings(args)
    setup_logging(args)

    gdb = None
    if args.list_all == True:
        MbedBoard.listConnectedBoards()
    else:
        try:
            board_selected = MbedBoard.chooseBoard(
                board_id=args.board_id,
                target_override=args.target_override,
                frequency=args.frequency)
            with board_selected as board:
                # Boost speed with deferred transfers
                board.transport.setDeferredTransfer(True)
                gdb = GDBServer(board, args.port_number, gdb_server_settings)
                while gdb.isAlive():
                    gdb.join(timeout=0.5)
        except KeyboardInterrupt:
            if gdb != None:
                gdb.stop()
        except Exception as e:
            print "uncaught exception: %s" % e
            traceback.print_exc()
            if gdb != None:
                gdb.stop()
开发者ID:arunpersaud,项目名称:pyOCD,代码行数:28,代码来源:gdb_server.py

示例2: run

    def run(self):
        self.args = self.build_parser().parse_args()
        self.gdb_server_settings = self.get_gdb_server_settings(self.args)
        self.setup_logging(self.args)

        self.process_commands(self.args.commands)

        gdb = None
        if self.args.list_all == True:
            MbedBoard.listConnectedBoards()
        else:
            try:
                board_selected = MbedBoard.chooseBoard(
                    board_id=self.args.board_id,
                    target_override=self.args.target_override,
                    frequency=self.args.frequency)
                with board_selected as board:
                    # Boost speed with deferred transfers
                    board.transport.setDeferredTransfer(True)
                    gdb = GDBServer(board, self.args.port_number, self.gdb_server_settings)
                    while gdb.isAlive():
                        gdb.join(timeout=0.5)
            except KeyboardInterrupt:
                if gdb != None:
                    gdb.stop()
            except Exception as e:
                print "uncaught exception: %s" % e
                traceback.print_exc()
                if gdb != None:
                    gdb.stop()
                return 1

        # Successful exit.
        return 0
开发者ID:ARMmbed,项目名称:yotta_osx_installer,代码行数:34,代码来源:gdb_server.py

示例3: main

def main():
    args = parser.parse_args()
    setup_logging(args)

    # Sanity checks before attaching to board
    if args.format == 'hex' and not intelhex_available:
        print("Unable to program hex file")
        print("Module 'intelhex' must be installed first")
        exit()

    if args.list_all:
        MbedBoard.listConnectedBoards()
    else:
        board_selected = MbedBoard.chooseBoard(board_id=args.board_id, target_override=args.target_override,
                                               frequency=args.frequency)
        with board_selected as board:
            flash = board.flash
            transport = board.transport

            # Boost speed with deferred transfers
            transport.setDeferredTransfer(True)

            progress = print_progress
            if args.hide_progress:
                progress = None

            chip_erase = None
            if args.chip_erase:
                chip_erase = True
            elif args.sector_erase:
                chip_erase = False

            # Binary file format
            if args.format == 'bin':
                # If no address is specified use the start of rom
                if args.address is None:
                    args.address = board.flash.getFlashInfo().rom_start

                with open(args.file, "rb") as f:
                    f.seek(args.skip, 0)
                    data = f.read()
                args.address += args.skip
                data = unpack(str(len(data)) + 'B', data)
                flash.flashBlock(args.address, data, chip_erase=chip_erase, progress_cb=progress,
                                 fast_verify=args.fast_program)

            # Intel hex file format
            if args.format == 'hex':
                hex = IntelHex(args.file)
                addresses = hex.addresses()
                addresses.sort()

                flash_builder = flash.getFlashBuilder()

                data_list = list(ranges(addresses))
                for start, end in data_list:
                    size = end - start + 1
                    data = list(hex.tobinarray(start=start, size=size))
                    flash_builder.addData(start, data)
                flash_builder.program(chip_erase=chip_erase, progress_cb=progress, fast_verify=args.fast_program)
开发者ID:geky,项目名称:pyOCD,代码行数:60,代码来源:flash_tool.py

示例4: getAdapter

def getAdapter():
    '''
    Get a CMSIS DAP debug adapter
    '''
    interfaces = INTERFACE[usb_backend].getAllConnectedInterface(VID, PID)
    if interfaces == None:
        print "Not find a mbed interface"
        sys.exit(1)

    first_interface = interfaces[0]
    adapter = MbedBoard("target_lpc1768", "flash_lpc1768", first_interface)
    adapter.init()
    return adapter
开发者ID:DonMorr,项目名称:pyOCD,代码行数:13,代码来源:flash_nrf51822.py

示例5: _launchPyOCDGDBServer

def _launchPyOCDGDBServer(msg_queue):
    logger.info('starting PyOCD gdbserver...')
    # ignore Ctrl-C, so we don't interrupt the GDB server when the
    # being-debugged program is being stopped:
    signal.signal(signal.SIGINT, _ignoreSignal);
    from pyOCD.gdbserver import GDBServer
    from pyOCD.board import MbedBoard
    gdb = None
    try:
        board_selected = MbedBoard.chooseBoard()
        with board_selected as board:
            gdb = GDBServer(
                board, 3333, {
                     'break_at_hardfault': True,
                    'step_into_interrupt': False,
                         'break_on_reset': False,
                }
            )
            if gdb.isAlive():
                msg_queue.put('alive')
                while gdb.isAlive():
                    gdb.join(timeout = 0.5)
                    # check for a "kill" message from the parent process:
                    try:
                        msg = msg_queue.get(False)
                        if msg == 'kill':
                            gdb.stop()
                            break
                    except Queue.Empty:
                        pass
    except Exception as e:
        if gdb != None:
            gdb.stop()
        raise
    msg_queue.put('dead')
开发者ID:ARMmbed,项目名称:yotta_osx_installer,代码行数:35,代码来源:gdb.py

示例6: search_and_lock

def search_and_lock(board_id):
    """Repeatedly lock a board with the given ID"""
    for _ in range(0, 20):
        device = DAPAccess.get_device(board_id)
        device.open()
        device.close()
        with MbedBoard.chooseBoard(board_id=board_id):
            pass
开发者ID:0xc0170,项目名称:pyOCD,代码行数:8,代码来源:parallel_test.py

示例7: list_boards

    def list_boards(self):
        self.disable_logging()

        try:
            all_mbeds = MbedBoard.getAllConnectedBoards(close=True, blocking=False)
            status = 0
            error = ""
        except Exception as e:
            all_mbeds = []
            status = 1
            error = str(e)
            if not self.args.output_json:
                raise

        if self.args.output_json:
            boards = []
            obj = {
                'pyocd_version' : __version__,
                'version' : { 'major' : 1, 'minor' : 0 },
                'status' : status,
                'boards' : boards,
                }

            if status != 0:
                obj['error'] = error

            for mbed in all_mbeds:
                d = {
                    'unique_id' : mbed.unique_id,
                    'info' : mbed.getInfo(),
                    'board_name' : mbed.getBoardName(),
                    'target' : mbed.getTargetType(),
                    'vendor_name' : '',
                    'product_name' : '',
                    }

                # Reopen the link so we can access the USB vendor and product names from the inteface.
                # If it's not a USB based link, then we don't attempt this.
                if isinstance(mbed.link, DAPAccessUSB):
                    try:
                        mbed.link.open()
                        d['vendor_name'] = mbed.link._interface.vendor_name
                        d['product_name'] = mbed.link._interface.product_name
                        mbed.link.close()
                    except Exception:
                        pass
                boards.append(d)

            print json.dumps(obj, indent=4) #, sys.stdout)
        else:
            index = 0
            if len(all_mbeds) > 0:
                for mbed in all_mbeds:
                    print("%d => %s boardId => %s" % (index, mbed.getInfo().encode('ascii', 'ignore'), mbed.unique_id))
                    index += 1
            else:
                print("No available boards are connected")
开发者ID:CobooGuo,项目名称:pyOCD,代码行数:57,代码来源:gdb_server.py

示例8: main

def main():
    log_file = "automated_test_result.txt"
    summary_file = "automated_test_summary.txt"

    parser = argparse.ArgumentParser(description='pyOCD automated testing')
    parser.add_argument('-d', '--debug',
                        action="store_true", help='Enable debug logging')
    args = parser.parse_args()

    # Setup logging
    if os.path.exists(log_file):
        os.remove(log_file)
    level = logging.DEBUG if args.debug else logging.INFO
    logging.basicConfig(level=level)
    logger = Logger(log_file)
    sys.stdout = logger
    sys.stderr = logger

    test_list = []
    board_list = []
    result_list = []

    # Put together list of tests
    test = Test("Basic Test", lambda board: basic_test(board, None))
    test_list.append(test)
    test_list.append(GdbServerJsonTest())
    test_list.append(SpeedTest())
    test_list.append(CortexTest())
    test_list.append(FlashTest())
    test_list.append(GdbTest())

    # Put together list of boards to test
    board_list = MbedBoard.getAllConnectedBoards(close=True, blocking=False)

    start = time()
    for board in board_list:
        print("--------------------------")
        print("TESTING BOARD %s" % board.getUniqueID())
        print("--------------------------")
        for test in test_list:
            test_start = time()
            result = test.run(board)
            test_stop = time()
            result.time = test_stop - test_start
            result_list.append(result)
    stop = time()
    test_time = (stop - start)

    print_summary(test_list, result_list, test_time)
    with open(summary_file, "wb") as output_file:
        print_summary(test_list, result_list, test_time, output_file)

    exit_val = 0 if Test.all_tests_pass(result_list) else -1
    exit(exit_val)
开发者ID:0xc0170,项目名称:pyOCD,代码行数:54,代码来源:automated_test.py

示例9: list_boards

    def list_boards(self):
        self.disable_logging()

        try:
            all_mbeds = MbedBoard.getAllConnectedBoards(close=True, blocking=False)
            status = 0
            error = ""
        except Exception as e:
            all_mbeds = []
            status = 1
            error = str(e)
            if not self.args.output_json:
                raise

        if self.args.output_json:
            boards = []
            obj = {
                'pyocd_version' : __version__,
                'version' : { 'major' : 1, 'minor' : 0 },
                'status' : status,
                'boards' : boards,
                }

            if status != 0:
                obj['error'] = error

            for mbed in all_mbeds:
                d = {
                    'unique_id' : mbed.unique_id,
                    'info' : mbed.getInfo(),
                    'board_name' : mbed.getBoardName(),
                    'target' : mbed.getTargetType(),
                    'vendor_name' : mbed.interface.vendor_name,
                    'product_name' : mbed.interface.product_name,
                    }
                boards.append(d)

            print json.dumps(obj, indent=4) #, sys.stdout)
        else:
            index = 0
            if len(all_mbeds) > 0:
                for mbed in all_mbeds:
                    print("%d => %s boardId => %s" % (index, mbed.getInfo().encode('ascii', 'ignore'), mbed.unique_id))
                    index += 1
            else:
                print("No available boards are connected")
开发者ID:oliviermartin,项目名称:pyOCD,代码行数:46,代码来源:gdb_server.py

示例10: run

    def run(self, args=None):
        try:
            self.args = self.build_parser().parse_args(args)
            self.gdb_server_settings = self.get_gdb_server_settings(self.args)
            self.setup_logging(self.args)
            DAPAccess.set_args(self.args.daparg)

            self.process_commands(self.args.commands)

            gdb = None
            if self.args.list_all == True:
                self.list_boards()
            elif self.args.list_targets == True:
                self.list_targets()
            else:
                try:
                    board_selected = MbedBoard.chooseBoard(
                        board_id=self.args.board_id,
                        target_override=self.args.target_override,
                        frequency=self.args.frequency)
                    with board_selected as board:
                        gdb = GDBServer(board, self.args.port_number, self.gdb_server_settings)
                        while gdb.isAlive():
                            gdb.join(timeout=0.5)
                except KeyboardInterrupt:
                    if gdb != None:
                        gdb.stop()
                except Exception as e:
                    print "uncaught exception: %s" % e
                    traceback.print_exc()
                    if gdb != None:
                        gdb.stop()
                    return 1

            # Successful exit.
            return 0
        except InvalidArgumentError as e:
            self.parser.error(e)
            return 1
开发者ID:matthewelse,项目名称:pyOCD,代码行数:39,代码来源:gdb_server.py

示例11: validate_boards

    def validate_boards(data):
        did_pass = True

        print 'boards',
        p = data.has_key('boards') and type(data['boards']) is list
        if p:
            b = data['boards']
        if p:
            print "PASSED"
        else:
            did_pass = False
            print"FAILED"

        try:
            all_mbeds = MbedBoard.getAllConnectedBoards(close=True, blocking=False)
            p = len(all_mbeds) == len(b)
            matching_boards = 0
            if p:
                for mbed in all_mbeds:
                    for brd in b:
                        if mbed.unique_id == brd['unique_id']:
                            matching_boards += 1
                            p = brd.has_key('info') and brd.has_key('target') and brd.has_key('board_name')
                            if not p:
                                break
                    if not p:
                        break
                p = matching_boards == len(all_mbeds)
            if p:
                print "PASSED"
            else:
                did_pass = False
                print"FAILED"
        except Exception:
            print "FAILED"
            did_pass = False

        return did_pass
开发者ID:0xc0170,项目名称:pyOCD,代码行数:38,代码来源:gdb_server_json_test.py

示例12: _launchPyOCDGDBServer

def _launchPyOCDGDBServer(msg_queue):
    logger.info('preparing PyOCD gdbserver...')
    from pyOCD.gdbserver import GDBServer
    from pyOCD.board import MbedBoard
    gdb = None
    try:
        logger.info('finding connected board...')
        board_selected = MbedBoard.chooseBoard(blocking=False)
        if board_selected is not None:
            with board_selected as board:
                logger.info('starting PyOCD gdbserver...')
                gdb = GDBServer(
                    board, 3333, {
                         'break_at_hardfault': True,
                        'step_into_interrupt': False,
                             'break_on_reset': False,
                    }
                )
                if gdb.isAlive():
                    msg_queue.put('alive')
                    while gdb.isAlive():
                        gdb.join(timeout = 0.5)
                        # check for a "kill" message from the parent process:
                        try:
                            msg = msg_queue.get(False)
                            if msg == 'kill':
                                gdb.stop()
                                break
                        except Queue.Empty:
                            pass
        else:
            logger.error('failed to find a connected board')
    except Exception as e:
        logger.error('exception in GDB server thread: %s', e)
        if gdb != None:
            gdb.stop()
        raise
    msg_queue.put('dead')
开发者ID:pombredanne,项目名称:valinor,代码行数:38,代码来源:gdb.py

示例13: Exception

build_type = build_types[0].strip().split("=")[1]
if build_type != "Debug":
    raise Exception("CMAKE_BUILD_TYPE was '%s', expected 'Debug'. Rebuild with `yt build -d`." % build_type)

# create crashdump folder
mkdir_p("crashdump")

# copy over AXF file
potential_axf = [f for f in os.listdir(yotta_build_path) if isfile(join(yotta_build_path, f)) and "." not in f]
if len(potential_axf) != 1:
    raise Exception("Found %d files without extension in %s, expected 1" % (len(potential_axf), yotta_build_path))
copyfile(join(yotta_build_path, potential_axf[0]), "crashdump/" + potential_axf[0] + ".axf")

print "[2/6] Build verified. Connecting to board..."

with MbedBoard.chooseBoard(frequency=10000000) as board:

    memory_map = board.target.getMemoryMap()
    ram_regions = [region for region in memory_map if region.type == 'ram']
    ram_region = ram_regions[0]
    rom_region = memory_map.getBootMemory()
    target_type = board.getTargetType()

    print "[3/6] Board recognized as %s. Downloading ROM..." % target_type

    addr = rom_region.start
    size = rom_region.length
    data = board.target.readBlockMemoryUnaligned8(addr, size)
    data = bytearray(data)
    with open("crashdump/rom.bin", 'wb') as f:
        f.write(data)
开发者ID:ARMmbed,项目名称:post-mortem-debugging,代码行数:31,代码来源:dump_firmware.py

示例14: speed_test

def speed_test(board_id):
    with MbedBoard.chooseBoard(board_id=board_id, frequency=1000000) as board:
        target_type = board.getTargetType()

        test_clock = 10000000
        if target_type == "nrf51":
            # Override clock since 10MHz is too fast
            test_clock = 1000000

        memory_map = board.target.getMemoryMap()
        ram_regions = [region for region in memory_map if region.type == "ram"]
        ram_region = ram_regions[0]
        rom_region = memory_map.getBootMemory()

        ram_start = ram_region.start
        ram_size = ram_region.length
        rom_start = rom_region.start
        rom_size = rom_region.length

        target = board.target
        link = board.link

        test_pass_count = 0
        test_count = 0
        result = SpeedTestResult()

        link.set_clock(test_clock)
        link.set_deferred_transfer(True)

        print("\r\n\r\n------ TEST RAM READ / WRITE SPEED ------")
        test_addr = ram_start
        test_size = ram_size
        data = [randrange(1, 50) for x in range(test_size)]
        start = time()
        target.writeBlockMemoryUnaligned8(test_addr, data)
        target.flush()
        stop = time()
        diff = stop - start
        result.write_speed = test_size / diff
        print("Writing %i byte took %s seconds: %s B/s" % (test_size, diff, result.write_speed))
        start = time()
        block = target.readBlockMemoryUnaligned8(test_addr, test_size)
        target.flush()
        stop = time()
        diff = stop - start
        result.read_speed = test_size / diff
        print("Reading %i byte took %s seconds: %s B/s" % (test_size, diff, result.read_speed))
        error = False
        for i in range(len(block)):
            if block[i] != data[i]:
                error = True
                print("ERROR: 0x%X, 0x%X, 0x%X!!!" % ((addr + i), block[i], data[i]))
        if error:
            print("TEST FAILED")
        else:
            print("TEST PASSED")
            test_pass_count += 1
        test_count += 1

        print("\r\n\r\n------ TEST ROM READ SPEED ------")
        test_addr = rom_start
        test_size = rom_size
        start = time()
        block = target.readBlockMemoryUnaligned8(test_addr, test_size)
        target.flush()
        stop = time()
        diff = stop - start
        print("Reading %i byte took %s seconds: %s B/s" % (test_size, diff, test_size / diff))
        print("TEST PASSED")
        test_pass_count += 1
        test_count += 1

        target.reset()

        result.passed = test_count == test_pass_count
        return result
开发者ID:arekzaluski,项目名称:pyOCD,代码行数:76,代码来源:speed_test.py

示例15: run

    def run(self):
        board = None
        exitCode = 0

        try:
            # Read command-line arguments.
            args = self.get_args()

            if args.verbose:
                logging.basicConfig(level=logging.INFO)

            # Print a list of all connected boards.
            if args.action == ACTION_LIST:
                MbedBoard.listConnectedBoards()
                sys.exit(0)

            board = MbedBoard.chooseBoard(board_id=args.board, target_override=args.target, init_board=False)
            board.target.setAutoUnlock(False)
            try:
                board.init()
            except Exception, e:
                print "Exception:", e

            target = board.target
            transport = board.transport
            flash = board.flash

            # Set specified SWD clock.
            if args.clock > 0:
                print "Setting SWD clock to %d kHz" % args.clock
                transport.setClock(args.clock * 1000)

            # Handle reset action first
            if args.action == ACTION_RESET:
                print "Resetting target"
                target.reset()
                sys.exit(0)

            # Handle a device with flash security enabled.
            didErase = False
            if target.isLocked() and args.action != ACTION_UNLOCK:
                print "Target is locked, cannot complete operation. Use --unlock to mass erase and unlock."

            # Handle actions.
            if args.action == ACTION_INFO:
                print "Unique ID: %s" % board.getUniqueID()
                print "Core ID:   0x%08x" % target.readIDCode()
                if isinstance(target, pyOCD.target.target_kinetis.Kinetis):
                    print "MDM-AP Control: 0x%08x" % transport.readAP(target_kinetis.MDM_CTRL)
                    print "MDM-AP Status:  0x%08x" % transport.readAP(target_kinetis.MDM_STATUS)
                status = target.getState()
                if status == pyOCD.target.cortex_m.TARGET_HALTED:
                    print "Core status:    Halted"
                    self.dumpRegisters(target)
                elif status == pyOCD.target.cortex_m.TARGET_RUNNING:
                    print "Core status:    Running"
            elif args.action == ACTION_READ:
                if args.width == 8:
                    data = target.readBlockMemoryUnaligned8(args.read, args.len)
                elif args.width == 16:
                    if args.read & 0x1:
                        raise ToolError("read address 0x%08x is not 16-bit aligned" % args.read)

                    byteData = target.readBlockMemoryUnaligned8(args.read, args.len * 2)
                    i = 0
                    data = []
                    while i < len(byteData):
                        data.append(byteData[i] | (byteData[i + 1] << 8))
                        i += 2
                elif args.width == 32:
                    if args.read & 0x3:
                        raise ToolError("read address 0x%08x is not 32-bit aligned" % args.read)

                    data = target.readBlockMemoryAligned32(args.read, args.len / 4)

                # Either print disasm or hex dump of output
                if args.disasm:
                    if args.width == 8:
                        code = bytearray(data)
                    elif args.width == 16:
                        code = bytearray(byteData)
                    elif args.width == 32:
                        byteData = []
                        for v in data:
                            byteData.extend([(v >> 24) & 0xff, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff])
                        code = bytearray(byteData)

                    self.disasm(str(code), args.read)
                else:
                    dumpHexData(data, args.read, width=args.width)
            elif args.action == ACTION_WRITE:
                if args.width == 8:
                    target.writeBlockMemoryUnaligned8(args.write, args.data)
                elif args.width == 16:
                    if args.write & 0x1:
                        raise ToolError("write address 0x%08x is not 16-bit aligned" % args.write)

                    print "16-bit writes are currently not supported"
                elif args.width == 32:
                    if args.write & 0x3:
#.........这里部分代码省略.........
开发者ID:kaizen8501,项目名称:pyOCD,代码行数:101,代码来源:pyocd.py


注:本文中的pyOCD.board.MbedBoard类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。