1
1
# -*- coding: utf-8 -*-
2
2
#
3
3
# Copyright © 2020 NXP
4
- # Copyright © 2020 Chris Reed
4
+ # Copyright © 2020-2021 Chris Reed
5
5
#
6
6
# SPDX-License-Identifier: BSD-3-Clause
7
7
#
30
30
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
31
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
32
33
- import six
34
33
from pypemicro import PyPemicro , PEMicroException , PEMicroTransferException , PEMicroInterfaces
35
34
import logging
36
35
from time import sleep
@@ -88,7 +87,7 @@ def get_all_connected_probes(cls, unique_id=None, is_explicit=False):
88
87
# the PEMicro library but on which the plugin is installed.
89
88
if cls .NO_LIBRARY_ERR in str (exc ):
90
89
return []
91
- six . raise_from ( cls ._convert_exception (exc ), exc )
90
+ raise cls ._convert_exception (exc ) from exc
92
91
93
92
@classmethod
94
93
def get_probe_with_id (cls , unique_id , is_explicit = False ):
@@ -106,7 +105,7 @@ def get_probe_with_id(cls, unique_id, is_explicit=False):
106
105
# the PEMicro library but on which the plugin is installed.
107
106
if cls .NO_LIBRARY_ERR in str (exc ):
108
107
return None
109
- six . raise_from ( cls ._convert_exception (exc ), exc )
108
+ raise cls ._convert_exception (exc ) from exc
110
109
111
110
def __init__ (self , serial_number ):
112
111
super (PEMicroProbe , self ).__init__ ()
@@ -126,7 +125,7 @@ def __init__(self, serial_number):
126
125
self ._product_name = self ._pemicro .version () or "Unknown"
127
126
self ._pemicro .close ()
128
127
except PEMicroException as exc :
129
- six . raise_from ( self . _convert_exception (exc ), exc )
128
+ raise cls . _convert_exception (exc ) from exc
130
129
131
130
@property
132
131
def description (self ):
@@ -178,14 +177,14 @@ def open(self):
178
177
self ._default_protocol = DebugProbe .Protocol .SWD
179
178
180
179
except PEMicroException as exc :
181
- six . raise_from ( self . _convert_exception (exc ), exc )
180
+ raise cls . _convert_exception (exc ) from exc
182
181
183
182
def close (self ):
184
183
try :
185
184
self ._pemicro .close ()
186
185
self ._is_open = False
187
186
except PEMicroException as exc :
188
- six . raise_from ( self . _convert_exception (exc ), exc )
187
+ raise cls . _convert_exception (exc ) from exc
189
188
190
189
# ------------------------------------------- #
191
190
# Target control functions
@@ -219,7 +218,7 @@ def connect(self, protocol=None):
219
218
self ._pemicro .connect (iface , self .session .options .get ("swv_clock" ))
220
219
self ._protocol = protocol
221
220
except PEMicroException as exc :
222
- six . raise_from ( self . _convert_exception (exc ), exc )
221
+ raise cls . _convert_exception (exc ) from exc
223
222
224
223
def swj_sequence (self , length , bits ):
225
224
raise NotImplementedError ()
@@ -232,7 +231,7 @@ def set_clock(self, frequency):
232
231
try :
233
232
self ._pemicro .set_debug_frequency (frequency )
234
233
except PEMicroException as exc :
235
- six . raise_from ( self . _convert_exception (exc ), exc )
234
+ raise cls . _convert_exception (exc ) from exc
236
235
237
236
def reset (self ):
238
237
try :
@@ -259,14 +258,14 @@ def reset(self):
259
258
sleep (self .session .options .get ('reset.post_delay' ))
260
259
261
260
except PEMicroException as exc :
262
- six . raise_from ( self . _convert_exception (exc ), exc )
261
+ raise cls . _convert_exception (exc ) from exc
263
262
264
263
def assert_reset (self , asserted = False ):
265
264
try :
266
265
self ._pemicro .control_reset_line (asserted )
267
266
self .reset_pin_state = not asserted
268
267
except PEMicroException as exc :
269
- six . raise_from ( self . _convert_exception (exc ), exc )
268
+ raise cls . _convert_exception (exc ) from exc
270
269
271
270
def is_reset_asserted (self ):
272
271
return not self .reset_pin_state
@@ -278,13 +277,13 @@ def flush(self):
278
277
try :
279
278
self ._pemicro .flush_any_queued_data ()
280
279
except Exception as exc :
281
- six . raise_from ( self . _convert_exception (exc ), exc )
280
+ raise cls . _convert_exception (exc ) from exc
282
281
283
282
def read_dp (self , addr , now = True ):
284
283
try :
285
284
value = self ._pemicro .read_dp_register (addr = addr , now = now )
286
285
except PEMicroTransferException as exc :
287
- six . raise_from ( self . _convert_exception (exc ), exc )
286
+ raise cls . _convert_exception (exc ) from exc
288
287
else :
289
288
def read_reg_cb ():
290
289
return value
@@ -295,26 +294,26 @@ def write_dp(self, addr, data, now = True):
295
294
try :
296
295
self ._pemicro .write_dp_register (addr = addr , value = data )
297
296
except PEMicroTransferException as exc :
298
- six . raise_from ( self . _convert_exception (exc ), exc )
297
+ raise cls . _convert_exception (exc ) from exc
299
298
300
299
def read_ap (self , addr , now = True ):
301
- assert type (addr ) in ( six . integer_types )
300
+ assert isinstance (addr , int )
302
301
try :
303
302
value = self ._pemicro .read_ap_register (addr = (addr & self .APADDR ), now = now , apselect = ((addr & self .APSEL_APBANKSEL ) >> self .APSEL_SHIFT ))
304
303
except PEMicroTransferException as exc :
305
- six . raise_from ( self . _convert_exception (exc ), exc )
304
+ raise cls . _convert_exception (exc ) from exc
306
305
else :
307
306
def read_reg_cb ():
308
307
return value
309
308
310
309
return value if now else read_reg_cb
311
310
312
311
def write_ap (self , addr , data , now = True ):
313
- assert type (addr ) in ( six . integer_types )
312
+ assert isinstance (addr , int )
314
313
try :
315
314
self ._pemicro .write_ap_register (addr = (addr & self .APADDR ), value = data , apselect = ((addr & self .APSEL_APBANKSEL ) >> self .APSEL_SHIFT ))
316
315
except PEMicroTransferException as exc :
317
- six . raise_from ( self . _convert_exception (exc ), exc )
316
+ raise cls . _convert_exception (exc ) from exc
318
317
319
318
def read_ap_multiple (self , addr , count = 1 , now = True ):
320
319
results = [self .read_ap (addr , True ) for n in range (count )]
0 commit comments