Skip to content

Commit 959ab55

Browse files
committed
tinyprog: (read)timeout=2.0 writeTimeout=5.0
Double the read timeout to reduce risk of short reads causing verify errors. Substantially increase the write timeout to try to reduce the risk of an incomplete write, or a write being abandoned when it was nearly finished due to a minor SPI flash delay.
1 parent c15dd00 commit 959ab55

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

programmer/tinyprog/__init__.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,20 @@ def __str__(self):
113113
return self.port_name
114114

115115
def __enter__(self):
116+
# Timeouts:
117+
# - Read: 2.0 seconds (timeout)
118+
# - Write: 5.0 seconds (writeTimeout)
119+
#
120+
# Rationale: hitting the writeTimeout is fatal, so it pays to be
121+
# patient in case there is a brief delay; readTimeout is less
122+
# fatal, but can result in short reads if it is hit, so we want
123+
# a timeout high enough that is never hit normally. In practice
124+
# 1.0 seconds is *usually* enough, so the chosen values are double
125+
# and five times the "usually enough" values.
126+
#
116127
try:
117128
self.ser = serial.Serial(
118-
self.port_name, timeout=1.0, writeTimeout=1.0).__enter__()
129+
self.port_name, timeout=2.0, writeTimeout=5.0).__enter__()
119130
except serial.SerialException as e:
120131
raise PortError("Failed to open serial port:\n%s" % str(e))
121132

0 commit comments

Comments
 (0)