1 Commits

Author SHA1 Message Date
af153a89e7 Fix initialization with CH340 UARTs
Initialization is messed up with older Linux kernels and that
results in 9600 baud being used unconditionally. Setting the baud
rate separately seems to work around this successfully.
2015-12-15 16:43:37 +01:00
2 changed files with 7 additions and 15 deletions

View File

@ -131,10 +131,6 @@ class StcGal:
sys.stdout.flush();
print("Serial port error: %s" % e, file=sys.stderr)
return 1
except IOError as e:
sys.stdout.flush();
print("I/O error: %s" % e, file=sys.stderr)
return 1
try:
if self.opts.code_image:

View File

@ -446,13 +446,14 @@ class Stc15AOption(BaseOption):
class Stc15Option(BaseOption):
def __init__(self, msr):
assert len(msr) >= 4
assert len(msr) == 5
self.msr = bytearray(msr)
self.options = (
("reset_pin_enabled", self.get_reset_pin_enabled, self.set_reset_pin_enabled),
("clock_source", self.get_clock_source, self.set_clock_source),
("clock_gain", self.get_clock_gain, self.set_clock_gain),
("cpu_core_voltage", self.get_core_voltage, self.set_core_voltage),
("watchdog_por_enabled", self.get_watchdog, self.set_watchdog),
("watchdog_stop_idle", self.get_watchdog_idle, self.set_watchdog_idle),
("watchdog_prescale", self.get_watchdog_prescale, self.set_watchdog_prescale),
@ -467,9 +468,6 @@ class Stc15Option(BaseOption):
("uart2_pin_mode", self.get_uart_pin_mode, self.set_uart_pin_mode),
)
if len(msr) > 4:
self.options += ("cpu_core_voltage", self.get_core_voltage, self.set_core_voltage),
def get_reset_pin_enabled(self):
return not bool(self.msr[2] & 16)
@ -734,9 +732,10 @@ class StcBaseProtocol:
Set up serial port, send sync sequence and get part info.
"""
self.ser = serial.Serial(port=self.port, parity=self.PARITY)
# set baudrate separately to work around a bug with the CH340 driver
# on older Linux kernels
self.ser = serial.Serial(port=self.port,
parity=self.PARITY)
# set baudrate separately to workaround a bug with the CH340 driver
# in older Linux kernels
self.ser.baudrate = self.baud_handshake
# fast timeout values to deal with detection errors
@ -1927,10 +1926,7 @@ class Stc15Protocol(Stc15AProtocol):
0xff])
packet += bytes([msr[3]])
packet += bytes([0xff] * 23)
if len(msr) > 4:
packet += bytes([msr[4]])
else:
packet += bytes([0xff])
packet += bytes([msr[4]])
packet += bytes([0xff] * 3)
packet += bytes([self.trim_value[0], self.trim_value[1] + 0x3f])
packet += msr[0:3]