@@ -62,11 +62,22 @@ class TransferTimeoutError(TransferError):
6262 pass
6363
6464class TransferFaultError (TransferError ):
65- """! @brief An SWD Fault occurred"""
66- def __init__ (self , faultAddress = None , length = None ):
67- super (TransferFaultError , self ).__init__ (faultAddress )
68- self ._address = faultAddress
69- self ._length = length
65+ """! @brief A memory fault occurred.
66+
67+ This exception class is extended to optionally record the start address and an optional length of the
68+ attempted memory access that caused the fault. The address and length, if available, will be included
69+ in the description of the exception when it is converted to a string.
70+
71+ Positional arguments passed to the constructor are passed through to the superclass'
72+ constructor, and thus operate like any other standard exception class. Keyword arguments of
73+ 'fault_address' and 'length' can optionally be passed to the constructor to initialize the fault
74+ start address and length. Alternatively, the corresponding property setters can be used after
75+ the exception is created.
76+ """
77+ def __init__ (self , * args , ** kwargs ):
78+ super (TransferFaultError , self ).__init__ (* args )
79+ self ._address = kwargs .get ('fault_address' , None )
80+ self ._length = kwargs .get ('length' , None )
7081
7182 @property
7283 def fault_address (self ):
@@ -89,19 +100,30 @@ def fault_length(self, length):
89100 self ._length = length
90101
91102 def __str__ (self ):
92- desc = "SWD/JTAG Transfer Fault"
103+ desc = "Memory transfer fault"
104+ if self .args :
105+ if len (self .args ) == 1 :
106+ desc += " (" + str (self .args [0 ]) + ")"
107+ else :
108+ desc += " " + str (self .args ) + ""
93109 if self ._address is not None :
94110 desc += " @ 0x%08x" % self ._address
95111 if self ._length is not None :
96112 desc += "-0x%08x" % self .fault_end_address
97113 return desc
98114
99115class FlashFailure (TargetError ):
100- """! @brief Exception raised when flashing fails for some reason. """
101- def __init__ (self , msg , address = None , result_code = None ):
102- super (FlashFailure , self ).__init__ (msg )
103- self ._address = address
104- self ._result_code = result_code
116+ """! @brief Exception raised when flashing fails for some reason.
117+
118+ Positional arguments passed to the constructor are passed through to the superclass'
119+ constructor, and thus operate like any other standard exception class. The flash address that
120+ failed and/or result code from the algorithm can optionally be recorded in the exception, if
121+ passed to the constructor as 'address' and 'result_code' keyword arguments.
122+ """
123+ def __init__ (self , * args , ** kwargs ):
124+ super (FlashFailure , self ).__init__ (* args )
125+ self ._address = kwargs .get ('address' , None )
126+ self ._result_code = kwargs .get ('result_code' , None )
105127
106128 @property
107129 def address (self ):
@@ -111,6 +133,19 @@ def address(self):
111133 def result_code (self ):
112134 return self ._result_code
113135
136+ def __str__ (self ):
137+ desc = super (FlashFailure , self ).__str__ ()
138+ parts = []
139+ if self .address is not None :
140+ parts .append ("address 0x%08x" % self .address )
141+ if self .result_code is not None :
142+ parts .append ("result code 0x%x" % self .result_code )
143+ if parts :
144+ if desc :
145+ desc += " "
146+ desc += "(%s)" % ("; " .join (parts ))
147+ return desc
148+
114149class FlashEraseFailure (FlashFailure ):
115150 """! @brief An attempt to erase flash failed. """
116151 pass
0 commit comments