Skip to content
This repository was archived by the owner on Jan 17, 2023. It is now read-only.

Commit c91f0af

Browse files
authored
Merge pull request #130 from NordicSemiconductor/fix/inform-about-msd-when-serial-dfu-fails
Add info about MSD in certain error scenarios
2 parents 16d5290 + cc05839 commit c91f0af

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

nordicsemi/dfu/dfu_transport_serial.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
# Python 3rd party imports
4646
from serial import Serial
47+
from serial.serialutil import SerialException
4748

4849
# Nordic Semiconductor imports
4950
from nordicsemi.dfu.dfu_transport import DfuTransport, DfuEvent, TRANSPORT_LOGGING_LEVEL
@@ -116,7 +117,12 @@ def __init__(self, serial_port):
116117
def send_message(self, data):
117118
packet = Slip.encode(data)
118119
logger.log(TRANSPORT_LOGGING_LEVEL, 'SLIP: --> ' + str(data))
119-
self.serial_port.write(packet)
120+
try:
121+
self.serial_port.write(packet)
122+
except SerialException as e:
123+
raise NordicSemiException('Writing to serial port failed: ' + str(e) + '. '
124+
'If MSD is enabled on the target device, try to disable it ref. '
125+
'https://wiki.segger.com/index.php?title=J-Link-OB_SAM3U')
120126

121127
def get_message(self):
122128
current_state = Slip.SLIP_STATE_DECODING
@@ -351,6 +357,11 @@ def __calculate_checksum(self):
351357
self.dfu_adapter.send_message([DfuTransportSerial.OP_CODE['CalcChecSum']])
352358
response = self.__get_response(DfuTransportSerial.OP_CODE['CalcChecSum'])
353359

360+
if response is None:
361+
raise NordicSemiException('Did not receive checksum response from DFU target. '
362+
'If MSD is enabled on the target device, try to disable it ref. '
363+
'https://wiki.segger.com/index.php?title=J-Link-OB_SAM3U')
364+
354365
(offset, crc) = struct.unpack('<II', bytearray(response))
355366
return {'offset': offset, 'crc': crc}
356367

0 commit comments

Comments
 (0)