wendlers / mpfshell

A simple shell based file explorer for ESP8266 Micropython based devices ⛺
MIT License
396 stars 84 forks source link

[Enhancement] Allow ConSerial to use RTS instead of DTR for reset #57

Open nevercast opened 6 years ago

nevercast commented 6 years ago

I'm using a LoPy from Pycom, the esptool expects RTS to be used for reset, so we have designed our production PCBs with this in mind. We would like to use mpfshell to copy files to our devices. You have used DTR in ConSerial as the reset line. It would be nice if this was configurable so that the ESP32 device would work correctly over serial.

For what its worth, Mpfshell works well with ESP32 over Telnet.

I should state I'm using Windows and its possible that Windows opens the COM port in a different state than ComSerial might expect with regards to DTR and RTS lines, for best configuration perhaps two states could be given as for "reset" and "nominal", with the high/low lines of both DTR and RTS set accordingly, something like.

def set_control_lines(nominal, reset):
    """ Change the state of the serial control lines during typical state or reset state """
    # nominal and reset are tuples of (Boolean, Boolean), DTR, RTS respectively
    self.ctrl_nominal = nominal
    self.ctrl_reset = reset

def _do_reset(self):
    self.serial.setDTR(self.ctrl_reset[0])
    self.serial.setRTS(self.ctrl_reset[1])
    time.sleep(0.25)
    self.serial.setDTR(self.ctrl_nominal[0])
    self.serial.setRTS(self.ctrl_nominal[1])

def __init__(...):
    ...
    if reset:
        logging.info("Hard resetting device at port: %s" % port)
        self._do_reset()
    ...

Let's discuss the best implementation of this, I can provide a PR once we have nailed down any concerns.

Kind regards, Josh.