Skip to content

Commit

Permalink
DFU mode: improve programming robustness.
Browse files Browse the repository at this point in the history
dfu.get_status() might return usb.core.USBError with errno == EPIPE,
when called in quick succession. This is the case when called from
dfu.block_on_state(). The next call usually works.

This change tries to catch this specific error and just re-tries in case
it happens.

Without this change, the error (and programming abort) might get
undetected, as click catches IOerror/EPIPE silently. This has
significant potential to brick a device.
  • Loading branch information
enrikb committed Sep 7, 2020
1 parent 76d7255 commit 2958b56
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion solo/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# http://opensource.org/licenses/MIT>, at your option. This file may not be
# copied, modified, or distributed except according to those terms.

import errno
import struct
import time

Expand Down Expand Up @@ -210,7 +211,10 @@ def block_on_state(self, state):
s = self.get_status()
while s.state == state:
time.sleep(s.timeout / 1000.0)
s = self.get_status()
try:
s = self.get_status()
except usb.core.USBError as e:
if e.errno != errno.EPIPE: raise

def read_option_bytes(self,):
ptr = 0x1FFF7800 # option byte address for STM32l432
Expand Down

0 comments on commit 2958b56

Please sign in to comment.