Mbed Host Tests
module_copy_pyocd.py
Go to the documentation of this file.
1"""
2mbed SDK
3Copyright (c) 2016-2016,2018 ARM Limited
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Author: Russ Butler <russ.butler@arm.com>
18"""
19
20import os
21from .host_test_plugins import HostTestPluginBase
22from pyocd.core.helpers import ConnectHelper
23from pyocd.flash.loader import FileProgrammer
24
25
27 # Plugin interface
28 name = 'HostTestPluginCopyMethod_pyOCD'
29 type = 'CopyMethod'
30 stable = True
31 capabilities = ['pyocd']
32 required_parameters = ['image_path', 'target_id']
33
34 def __init__(self):
35 """ ctor
36 """
37 HostTestPluginBase.__init__(self)
38
39 def setup(self, *args, **kwargs):
40 """ Configure plugin, this function should be called before plugin execute() method is used.
41 """
42 return True
43
44 def execute(self, capability, *args, **kwargs):
45 """! Executes capability by name
46
47 @param capability Capability name
48 @param args Additional arguments
49 @param kwargs Additional arguments
50 @return Capability call return value
51 """
52 if not self.check_parameters(capability, *args, **kwargs):
53 return False
54
55 if not kwargs['image_path']:
56 self.print_plugin_error("Error: image path not specified")
57 return False
58
59 if not kwargs['target_id']:
60 self.print_plugin_error("Error: Target ID")
61 return False
62
63 target_id = kwargs['target_id']
64 image_path = os.path.normpath(kwargs['image_path'])
65 with ConnectHelper.session_with_chosen_probe(unique_id=target_id, resume_on_disconnect=False) as session:
66 # Performance hack!
67 # Eventually pyOCD will know default clock speed
68 # per target
69 test_clock = 10000000
70 target_type = session.board.target_type
71 if target_type == "nrf51":
72 # Override clock since 10MHz is too fast
73 test_clock = 1000000
74 if target_type == "ncs36510":
75 # Override clock since 10MHz is too fast
76 test_clock = 1000000
77
78 # Configure link
79 session.probe.set_clock(test_clock)
80
81 # Program the file
82 programmer = FileProgrammer(session)
83 programmer.program(image_path)
84
85 return True
86
87
89 """ Returns plugin available in this module
90 """
print_plugin_error(self, text)
Interface helper methods - overload only if you need to have custom behaviour.
check_parameters(self, capability, *args, **kwargs)
This function should be ran each time we call execute() to check if none of the required parameters i...
execute(self, capability, *args, **kwargs)
Executes capability by name.