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


Python MbedBoard.chooseBoard方法代码示例

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


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

示例1: main

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
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,代码行数:62,代码来源:flash_tool.py

示例2: _launchPyOCDGDBServer

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
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,代码行数:37,代码来源:gdb.py

示例3: main

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
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,代码行数:30,代码来源:gdb_server.py

示例4: run

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
    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,代码行数:36,代码来源:gdb_server.py

示例5: search_and_lock

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
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,代码行数:10,代码来源:parallel_test.py

示例6: run

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
    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,代码行数:41,代码来源:gdb_server.py

示例7: _launchPyOCDGDBServer

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
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,代码行数:40,代码来源:gdb.py

示例8: run

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
    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,代码行数:103,代码来源:pyocd.py

示例9: speed_test

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
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,代码行数:78,代码来源:speed_test.py

示例10: run

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
    def run(self):
        try:
            # Read command-line arguments.
            self.args = self.get_args()
            self.cmd = self.args.cmd
            if self.cmd:
                self.cmd = self.cmd.lower()

            # Set logging level
            self.configure_logging()

            # Check for a valid command.
            if self.cmd and self.cmd not in self.command_list:
                print "Error: unrecognized command '%s'" % self.cmd
                return 1

            # List command must be dealt with specially.
            if self.cmd == 'list':
                self.handle_list([])
                return 0

            if self.args.clock != DEFAULT_CLOCK_FREQ_KHZ:
                print "Setting SWD clock to %d kHz" % self.args.clock

            # Connect to board.
            self.board = MbedBoard.chooseBoard(board_id=self.args.board, target_override=self.args.target, init_board=False, frequency=(self.args.clock * 1000))
            self.board.target.setAutoUnlock(False)
            self.board.target.setHaltOnConnect(False)
            try:
                self.board.init()
            except Exception as e:
                print "Exception while initing board:", e

            self.target = self.board.target
            self.link = self.board.link
            self.flash = self.board.flash

            # Halt if requested.
            if self.args.halt:
                self.handle_halt([])

            # Handle a device with flash security enabled.
            self.didErase = False
            if self.target.isLocked() and self.cmd != 'unlock':
                print "Error: Target is locked, cannot complete operation. Use unlock command to mass erase and unlock."
                if self.cmd and self.cmd not in ['reset', 'info']:
                    return 1

            # If no command, enter interactive mode.
            if not self.cmd:
                # Say what we're connected to.
                print "Connected to %s [%s]: %s" % (self.target.part_number,
                    CORE_STATUS_DESC[self.target.getState()], self.board.getUniqueID())

                # Remove list command that disrupts the connection.
                self.command_list.pop('list')
                COMMAND_INFO.pop('list')

                # Run the command line.
                console = PyOCDConsole(self)
                console.run()
            else:
                # Invoke action handler.
                result = self.command_list[self.cmd](self.args.args)
                if result is not None:
                    self.exitCode = result

        except ToolExitException:
            self.exitCode = 0
        except ValueError:
            print "Error: invalid argument"
        except DAPAccess.TransferError:
            print "Error: transfer failed"
            self.exitCode = 2
        except ToolError as e:
            print "Error:", e
            self.exitCode = 1
        finally:
            if self.board != None:
                # Pass false to prevent target resume.
                self.board.uninit(False)

        return self.exitCode
开发者ID:CobooGuo,项目名称:pyOCD,代码行数:85,代码来源:pyocd.py

示例11: N

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
parser.add_option("-d", "--debug", dest = "debug_level", default = 'info', help = "Set the level of system logging output, the available value for DEBUG_LEVEL: debug, info, warning, error, critical" )
parser.add_option("-t", "--target", dest = "target_override", default = None, help = "Override target to debug" )
parser.add_option("-n", "--nobreak", dest = "break_at_hardfault", default = True, action="store_false", help = "Disable breakpoint at hardfault handler. Required for nrf51 chip with SoftDevice based application." )
parser.add_option("-s", "--skip", dest = "skip_bytes", default = False, help = "Skip N (hexidecimal) first bytes of flash (for example SoftDevice on nrf51 chip). " )
(option, args) = parser.parse_args()
if (option.skip_bytes):
    option.skip_bytes = int(option.skip_bytes, 16)

gdb = None
level = LEVELS.get(option.debug_level, logging.NOTSET)
logging.basicConfig(level=level)
if option.list_all == True:
    MbedBoard.listConnectedBoards()
else:
    try:
        board_selected = MbedBoard.chooseBoard(board_id = option.board_id, target_override = option.target_override)
        if board_selected != None:
            try:
                gdb = GDBServer(board_selected, int(option.port_number), {'skip_bytes' : option.skip_bytes, 'break_at_hardfault' : option.break_at_hardfault})
                while gdb.isAlive():
                    gdb.join(timeout = 0.5)
            except ValueError:
                logging.error("Port number error!")
    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:Shengliang,项目名称:pyOCD,代码行数:33,代码来源:gdb_server.py

示例12: test_gdb

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
def test_gdb(board_id=None):
    result = GdbTestResult()
    with MbedBoard.chooseBoard(board_id=board_id) 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()
        binary_file = os.path.join(parentdir, "binaries", board.getTestBinary())
        if board_id is None:
            board_id = board.getUniqueID()
        test_clock = 10000000
        test_port = 3334
        error_on_invalid_access = True
        # Hardware breakpoints are not supported above 0x20000000 on
        # CortexM devices
        ignore_hw_bkpt_result = 1 if ram_region.start >= 0x20000000 else 0
        if target_type == "nrf51":
            # Override clock since 10MHz is too fast
            test_clock = 1000000
            # Reading invalid ram returns 0 or nrf51
            error_on_invalid_access = False

        # Program with initial test image
        board.flash.flashBinary(binary_file, rom_region.start)
        board.uninit(False)

    # Write out the test configuration
    test_params = {}
    test_params["rom_start"] = rom_region.start
    test_params["rom_length"] = rom_region.length
    test_params["ram_start"] = ram_region.start
    test_params["ram_length"] = ram_region.length
    test_params["invalid_start"] = 0xFFFF0000
    test_params["invalid_length"] = 0x1000
    test_params["expect_error_on_invalid_access"] = error_on_invalid_access
    test_params["ignore_hw_bkpt_result"] = ignore_hw_bkpt_result
    with open(TEST_PARAM_FILE, "wb") as f:
        f.write(json.dumps(test_params))

    # Run the test
    gdb = [PYTHON_GDB, "--command=gdb_script.py"]
    with open("output.txt", "wb") as f:
        program = Popen(gdb, stdin=PIPE, stdout=f, stderr=STDOUT)
        args = ["-p=%i" % test_port, "-f=%i" % test_clock, "-b=%s" % board_id]
        server = GDBServerTool()
        server.run(args)
        program.wait()

    # Read back the result
    with open(TEST_RESULT_FILE, "rb") as f:
        test_result = json.loads(f.read())

    # Print results
    if set(TEST_RESULT_KEYS).issubset(test_result):
        print("----------------Test Results----------------")
        print("HW breakpoint count: %s" % test_result["breakpoint_count"])
        print("Watchpoint count: %s" % test_result["watchpoint_count"])
        print("Average instruction step time: %s" % test_result["step_time_si"])
        print("Average single step time: %s" % test_result["step_time_s"])
        print("Average over step time: %s" % test_result["step_time_n"])
        print("Failure count: %i" % test_result["fail_count"])
        result.passed = test_result["fail_count"] == 0
    else:
        result.passed = False

    # Cleanup
    os.remove(TEST_RESULT_FILE)
    os.remove(TEST_PARAM_FILE)

    return result
开发者ID:CobooGuo,项目名称:pyOCD,代码行数:73,代码来源:gdb_test.py

示例13: OptionParser

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
parser = OptionParser()
parser.add_option("-p", "--port", dest = "port_number", default = 3333, help = "Write the port number that GDB server will open")
parser.add_option("-b", "--board", dest = "board_id", default = None, help = "Write the board id you want to connect")
parser.add_option("-l", "--list", action = "store_true", dest = "list_all", default = False, help = "List all the connected board")
parser.add_option("-d", "--debug", dest = "debug_level", default = 'info', help = "Set the level of system logging output, the available value for DEBUG_LEVEL: debug, info, warning, error, critical" )
(option, args) = parser.parse_args()

gdb = None
level = LEVELS.get(option.debug_level, logging.NOTSET)
logging.basicConfig(level=level)
if option.list_all == True:
    MbedBoard.listConnectedBoards()
else:
    try:
        board_selected = MbedBoard.chooseBoard(board_id = option.board_id)
        if board_selected != None:
            try:
                gdb = GDBServer(board_selected, int(option.port_number))
                while gdb.isAlive():
                    gdb.join(timeout = 0.5)
            except ValueError:
                logging.error("Port number error!")
    except KeyboardInterrupt:
        if gdb != None:
            gdb.shutdown_event.set()
            #gdb.stop()       
    except Exception as e:
        print "uncaught exception: %s" % e
        traceback.print_exc()
        if gdb != None:
开发者ID:ynsta,项目名称:pyOCD,代码行数:32,代码来源:gdb_server.py

示例14: cortex_test

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
def cortex_test(board_id):
    with MbedBoard.chooseBoard(board_id=board_id, frequency=1000000) as board:
        target_type = board.getTargetType()

        binary_file = os.path.join(parentdir, 'binaries', board.getTestBinary())

        test_clock = 10000000
        addr_invalid = 0x3E000000 # Last 16MB of ARM SRAM region - typically empty
        if target_type == "nrf51":
            # Override clock since 10MHz is too fast
            test_clock = 1000000
        if target_type == "ncs36510":
            # 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()

        addr = ram_region.start + 1
        size = 0x502
        addr_bin = rom_region.start

        target = board.target
        link = board.link
        flash = board.flash

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

        test_pass_count = 0
        test_count = 0
        result = CortexTestResult()

        print "\r\n\r\n----- FLASH NEW BINARY BEFORE TEST -----"
        flash.flashBinary(binary_file, addr_bin)
        # Let the target run for a bit so it
        # can initialize the watchdog if it needs to
        target.resume()
        sleep(0.2)
        target.halt()

        print "PROGRAMMING COMPLETE"


        print "\r\n\r\n----- TESTING CORTEX-M PERFORMANCE -----"
        test_time = test_function(board, target.getTResponse)
        print("Function getTResponse time: %f" % test_time)

        # Step
        test_time = test_function(board, target.step)
        print("Function step time: %f" % test_time)

        # Breakpoint
        def set_remove_breakpoint():
            target.setBreakpoint(0)
            target.removeBreakpoint(0)
        test_time = test_function(board, set_remove_breakpoint)
        print("Add and remove breakpoint: %f" % test_time)

        # getRegisterContext
        test_time = test_function(board, target.getRegisterContext)
        print("Function getRegisterContext: %f" % test_time)

        # setRegisterContext
        context = target.getRegisterContext()
        def set_register_context():
            target.setRegisterContext(context)
        test_time = test_function(board, set_register_context)
        print("Function setRegisterContext: %f" % test_time)

        # Run / Halt
        def run_halt():
            target.resume()
            target.halt()
        test_time = test_function(board, run_halt)
        print("Resume and halt: %f" % test_time)

        # GDB stepping
        def simulate_step():
            target.step()
            target.getTResponse()
            target.setBreakpoint(0)
            target.resume()
            target.halt()
            target.getTResponse()
            target.removeBreakpoint(0)
        test_time = test_function(board, simulate_step)
        print("Simulated GDB step: %f" % test_time)

        # Test passes if there are no exceptions
        test_pass_count += 1
        test_count += 1
        print("TEST PASSED")


        print "\r\n\r\n------ Testing Invalid Memory Access Recovery ------"
        memory_access_pass = True
        try:
#.........这里部分代码省略.........
开发者ID:cerevo,项目名称:pyOCD,代码行数:103,代码来源:cortex_test.py

示例15: flash_test

# 需要导入模块: from pyOCD.board import MbedBoard [as 别名]
# 或者: from pyOCD.board.MbedBoard import chooseBoard [as 别名]
def flash_test(board_id):
    with MbedBoard.chooseBoard(board_id=board_id, frequency=1000000) as board:
        target_type = board.getTargetType()

        test_clock = 10000000
        if target_type == "kl25z":
            ram_start = 0x1ffff000
            ram_size = 0x4000
            rom_start = 0x00000000
            rom_size = 0x20000
        elif target_type == "kl46z":
            ram_start = 0x1fffe000
            ram_size = 0x8000
            rom_start = 0x00000000
            rom_size = 0x40000
        elif target_type == "k22f":
            ram_start = 0x1fff0000
            ram_size = 0x20000
            rom_start = 0x00000000
            rom_size = 0x80000
        elif target_type == "k64f":
            ram_start = 0x1FFF0000
            ram_size = 0x40000
            rom_start = 0x00000000
            rom_size = 0x100000
        elif target_type == "lpc11u24":
            ram_start = 0x10000000
            ram_size = 0x2000
            rom_start = 0x00000000
            rom_size = 0x8000
        elif target_type == "lpc1768":
            ram_start = 0x10000000
            ram_size = 0x8000
            rom_start = 0x00000000
            rom_size = 0x80000
        elif target_type == "lpc4330":
            ram_start = 0x10000000
            ram_size = 0x20000
            rom_start = 0x14000000
            rom_size = 0x100000
        elif target_type == "lpc800":
            ram_start = 0x10000000
            ram_size = 0x1000
            rom_start = 0x00000000
            rom_size = 0x4000
        elif target_type == "nrf51822":
            ram_start = 0x20000000
            ram_size = 0x4000
            rom_start = 0x00000000
            rom_size = 0x40000
            # Override clock since 10MHz is too fast
            test_clock = 1000000
        else:
            raise Exception("The board is not supported by this test script.")

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

        transport.setClock(test_clock)

        test_pass_count = 0
        test_count = 0

        print "\r\n\r\n------ Test 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)
        stop = time()
        diff = stop-start
        print("Writing %i byte took %s seconds: %s B/s" % (test_size, diff,  test_size / diff))
        start = time()
        block = target.readBlockMemoryUnaligned8(test_addr, test_size)
        stop = time()
        diff = stop-start
        print("Reading %i byte took %s seconds: %s B/s" % (test_size, diff,  test_size / diff))
        if same(block, data):
            print("TEST PASSED")
            test_pass_count += 1
        else:
            print("TEST FAILED")
        test_count += 1

        def print_progress(progress):
            assert progress >= 0.0
            assert progress <= 1.0
            assert (progress == 0 and print_progress.prev_progress == 1.0) or (progress >= print_progress.prev_progress)

            # Reset state on 0.0
            if progress == 0.0:
                print_progress.prev_progress = 0
                print_progress.backwards_progress = False
                print_progress.done = False

            # Check for backwards progress
            if progress < print_progress.prev_progress:
                print_progress.backwards_progress = True
#.........这里部分代码省略.........
开发者ID:johosemi,项目名称:pyOCD,代码行数:103,代码来源:flash_test.py


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