serialhdl: Clear "hupcl" bit from serial port

The arduino style serial port interfaces can reset the MCU when the
serial port is opened.  Clearing the HUPCL flag makes this less
likely.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-12-09 19:04:30 -05:00
parent cad1e0b985
commit 74fa8a3907
2 changed files with 8 additions and 1 deletions

View File

@ -6,7 +6,7 @@
import time, logging, threading import time, logging, threading
import serial import serial
import msgproto, chelper import msgproto, chelper, util
class SerialReader: class SerialReader:
BITS_PER_BYTE = 10. BITS_PER_BYTE = 10.
@ -298,6 +298,7 @@ class SerialBootStrap:
# Attempt to place an AVR stk500v2 style programmer into normal mode # Attempt to place an AVR stk500v2 style programmer into normal mode
def stk500v2_leave(ser, reactor): def stk500v2_leave(ser, reactor):
logging.debug("Starting stk500v2 leave programmer sequence") logging.debug("Starting stk500v2 leave programmer sequence")
util.clear_hupcl(ser.fileno())
origbaud = ser.baudrate origbaud = ser.baudrate
# Request a dummy speed first as this seems to help reset the port # Request a dummy speed first as this seems to help reset the port
ser.baudrate = 2400 ser.baudrate = 2400

View File

@ -16,6 +16,12 @@ def set_nonblock(fd):
fcntl.fcntl(fd, fcntl.F_SETFL fcntl.fcntl(fd, fcntl.F_SETFL
, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK) , fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
# Clear HUPCL flag
def clear_hupcl(fd):
attrs = termios.tcgetattr(fd)
attrs[2] = attrs[2] & ~termios.HUPCL
termios.tcsetattr(fd, termios.TCSADRAIN, attrs)
# Support for creating a pseudo-tty for emulating a serial port # Support for creating a pseudo-tty for emulating a serial port
def create_pty(ptyname): def create_pty(ptyname):
mfd, sfd = pty.openpty() mfd, sfd = pty.openpty()