From 0a20430e07801a277e2fc37de30035730d1084f2 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Wed, 1 Apr 2020 23:52:55 +0200 Subject: serial: Add Fysetc Cheetah board specific reset sequence Fysetc Cheetah v1.2 boards require a special sequence to reset reliably. This sequence works for me in all cases. Simpler sequences without double reset did not work correctly. This is likely because of a weird stateful circuitry for toggling the bootloader state. Cheetah boards use RTS to configure bootloader triggering. By default, pySerial sets RTS on connect, which unfortunately configures the board to start the bootloader on reset. Add a toggle for the RTS state to allow users to workaround. The RTS state is set before the serial connection is opened, so there are no glitches. Addresses #2026. Signed-off-by: Grigori Goronzy --- klippy/mcu.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'klippy/mcu.py') diff --git a/klippy/mcu.py b/klippy/mcu.py index 49ec6cb0..36e9c48d 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -386,16 +386,22 @@ class MCU: self._disconnect) # Serial port self._serialport = config.get('serial', '/dev/ttyS0') + serial_rts = True + if config.get('restart_method', None) == "cheetah": + # Special case: Cheetah boards require RTS to be deasserted, else + # a reset will trigger the built-in bootloader. + serial_rts = False baud = 0 if not (self._serialport.startswith("/dev/rpmsg_") or self._serialport.startswith("/tmp/klipper_host_")): baud = config.getint('baud', 250000, minval=2400) self._serial = serialhdl.SerialReader( - self._reactor, self._serialport, baud) + self._reactor, self._serialport, baud, serial_rts) # Restarts self._restart_method = 'command' if baud: - rmethods = {m: m for m in [None, 'arduino', 'command', 'rpi_usb']} + rmethods = {m: m for m in [None, 'arduino', 'cheetah', 'command', + 'rpi_usb']} self._restart_method = config.getchoice( 'restart_method', rmethods, None) self._reset_cmd = self._config_reset_cmd = None @@ -683,6 +689,10 @@ class MCU: logging.info("Attempting MCU '%s' reset", self._name) self._disconnect() serialhdl.arduino_reset(self._serialport, self._reactor) + def _restart_cheetah(self): + logging.info("Attempting MCU '%s' Cheetah-style reset", self._name) + self._disconnect() + serialhdl.cheetah_reset(self._serialport, self._reactor) def _restart_via_command(self): if ((self._reset_cmd is None and self._config_reset_cmd is None) or not self._clocksync.is_active()): @@ -713,6 +723,8 @@ class MCU: self._restart_rpi_usb() elif self._restart_method == 'command': self._restart_via_command() + elif self._restart_method == 'cheetah': + self._restart_cheetah() else: self._restart_arduino() # Misc external commands -- cgit v1.2.3-70-g09d2