From 3a23a327a0faccad85b4ad2e590f513bb5bbe5a2 Mon Sep 17 00:00:00 2001 From: Chris Reed Date: Sun, 9 Dec 2018 14:34:44 -0600 Subject: [PATCH] Update pyocd support to version 0.14.0 or later. --- .../host_tests_plugins/module_copy_pyocd.py | 66 +++---------------- .../host_tests_plugins/module_reset_pyocd.py | 15 ++--- setup.py | 3 +- 3 files changed, 17 insertions(+), 67 deletions(-) diff --git a/mbed_host_tests/host_tests_plugins/module_copy_pyocd.py b/mbed_host_tests/host_tests_plugins/module_copy_pyocd.py index 09c56b2..2726f0f 100644 --- a/mbed_host_tests/host_tests_plugins/module_copy_pyocd.py +++ b/mbed_host_tests/host_tests_plugins/module_copy_pyocd.py @@ -1,6 +1,6 @@ """ mbed SDK -Copyright (c) 2016-2016 ARM Limited +Copyright (c) 2016-2016,2018 ARM Limited Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,16 +19,8 @@ import os from .host_test_plugins import HostTestPluginBase -from pyOCD.board import MbedBoard -from intelhex import IntelHex -import itertools - - -def _enum_continguous_addr_start_end(addr_list): - """Generator to get contiguous address ranges with start and end address""" - for _, b in itertools.groupby(enumerate(addr_list), lambda x_y: x_y[1] - x_y[0]): - b = list(b) - yield b[0][1], b[-1][1] +from pyocd.core.helpers import ConnectHelper +from pyocd.flash.loader import FileProgrammer class HostTestPluginCopyMethod_pyOCD(HostTestPluginBase): @@ -70,7 +62,7 @@ def execute(self, capability, *args, **kwargs): target_id = kwargs['target_id'] image_path = os.path.normpath(kwargs['image_path']) - with MbedBoard.chooseBoard(board_id=target_id) as board: + with ConnectHelper.session_with_chosen_probe(unique_id=target_id, resume_on_disconnect=False) as session: # Performance hack! # Eventually pyOCD will know default clock speed # per target @@ -84,51 +76,11 @@ def execute(self, capability, *args, **kwargs): test_clock = 1000000 # Configure link - board.link.set_clock(test_clock) - board.link.set_deferred_transfer(True) - - # Collect address, data pairs for programming - program_list = [] - extension = os.path.splitext(image_path)[1] - if extension == '.bin': - # Binary file format - memory_map = board.target.getMemoryMap() - rom_region = memory_map.getBootMemory() - with open(image_path, "rb") as file_handle: - program_data = file_handle.read() - program_list.append((rom_region.start, program_data)) - elif extension == '.hex': - # Intel hex file format - ihex = IntelHex(image_path) - addresses = ihex.addresses() - addresses.sort() - for start, end in _enum_continguous_addr_start_end(addresses): - size = end - start + 1 - data = ihex.tobinarray(start=start, size=size) - data = bytearray(data) - program_list.append((start, data)) - else: - # Unsupported - raise Exception("Unsupported file format %s" % extension) - - # Program data - flash_builder = board.flash.getFlashBuilder() - for addr, data in program_list: - flash_builder.addData(addr, list(bytearray(data))) - flash_builder.program() - - # Read back and verify programming was successful - for addr, data in program_list: - read_data = board.target.readBlockMemoryUnaligned8(addr, - len(data)) - read_data = bytearray(read_data) - if bytes(data) != bytes(read_data): - raise Exception("Flash programming error - failed to " - "program address 0x%x size %s" % - (addr, len(data))) - - # Cleanup - board.uninit(resume=False) + session.probe.set_clock(test_clock) + + # Program the file + programmer = FileProgrammer(session) + programmer.program(image_path) return True diff --git a/mbed_host_tests/host_tests_plugins/module_reset_pyocd.py b/mbed_host_tests/host_tests_plugins/module_reset_pyocd.py index 17ea445..9536b21 100644 --- a/mbed_host_tests/host_tests_plugins/module_reset_pyocd.py +++ b/mbed_host_tests/host_tests_plugins/module_reset_pyocd.py @@ -1,6 +1,6 @@ """ mbed SDK -Copyright (c) 2016-2016 ARM Limited +Copyright (c) 2016-2016,2018 ARM Limited Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,11 +17,8 @@ Author: Russ Butler """ -import re -import pkg_resources from .host_test_plugins import HostTestPluginBase -from os.path import join, basename -from pyOCD.board import MbedBoard +from pyocd.core.helpers import ConnectHelper class HostTestPluginResetMethod_pyOCD(HostTestPluginBase): @@ -65,10 +62,10 @@ def execute(self, capability, *args, **kwargs): if kwargs['target_id']: if capability == 'pyocd': target_id = kwargs['target_id'] - with MbedBoard.chooseBoard(board_id=target_id) as board: - board.target.reset() - board.target.resume() - board.uninit(resume=False) + with ConnectHelper.session_with_chosen_probe(unique_id=target_id, + resume_on_disconnect=False) as session: + session.target.reset() + session.target.resume() result = True return result diff --git a/setup.py b/setup.py index cd1d99e..92e947b 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ def read(fname): version='1.4.2', description=DESCRIPTION, long_description=read('README.md'), + long_description_content_type='text/markdown', author=OWNER_NAMES, author_email=OWNER_EMAILS, maintainer=OWNER_NAMES, @@ -57,6 +58,6 @@ def read(fname): "PrettyTable>=0.7.2", "requests", "mbed-ls>=1.0.0", - "pyOCD==0.12.0", + "pyocd>=0.14.0", "intelhex", "future"])