Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 9 additions & 57 deletions mbed_host_tests/host_tests_plugins/module_copy_pyocd.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
15 changes: 6 additions & 9 deletions mbed_host_tests/host_tests_plugins/module_reset_pyocd.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -17,11 +17,8 @@
Author: Russ Butler <russ.butler@arm.com>
"""

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):
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"])