Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UART DTR control support via command-line arguments #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pymcuprog/nvmserialupdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ def __init__(self, transport, device_info, options=""):
"""
port = transport.serialport
timeout = transport.timeout
dtr = transport.dtr
baudrate = transport.baudrate
self.avr = None
self.options = options
NvmAccessProvider.__init__(self, device_info)
self.dut = Dut(device_info)
self.avr = UpdiApplication(port, baudrate, self.dut, timeout=timeout)
self.avr = UpdiApplication(port, baudrate, self.dut, timeout=timeout, dtr=dtr)
# Read the device info to set up the UPDI stack variant
self.avr.read_device_info()

Expand Down
5 changes: 5 additions & 0 deletions pymcuprog/pymcuprog.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ def main():
default="1.0",
help="Timeout for read operations to complete (when using -t uart). Defaults to 1.0s")

parser.add_argument("--uart-dtr",
type=int,
default=-1,
help="Set serial port DTR line high (0) or low (1). Default for all connections is low.")

parser.add_argument("-i", "--interface",
type=str,
help="Programming interface to use")
Expand Down
2 changes: 1 addition & 1 deletion pymcuprog/pymcuprog_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def _setup_tool_connection(args):
if args.tool == "uart":
baudrate = _clk_as_int(args)
# Embedded GPIO/UART tool (eg: raspberry pi) => no USB connection
toolconnection = ToolSerialConnection(serialport=args.uart, baudrate=baudrate, timeout=args.uart_timeout)
toolconnection = ToolSerialConnection(serialport=args.uart, baudrate=baudrate, timeout=args.uart_timeout, dtr=args.uart_dtr)
else:
usb_serial = args.serialnumber
product = args.tool
Expand Down
4 changes: 2 additions & 2 deletions pymcuprog/serialupdi/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class UpdiApplication:
:type timeout: int
"""

def __init__(self, serialport, baud, device=None, timeout=None):
def __init__(self, serialport, baud, device=None, timeout=None, dtr=-1):
self.logger = getLogger(__name__)
self.device = device
# Build the UPDI stack:
# Create a physical
self.phy = UpdiPhysical(serialport, baud, timeout)
self.phy = UpdiPhysical(serialport, baud, timeout, dtr)

# Create a DL - use 24-bit until otherwise known
datalink = UpdiDatalink24bit()
Expand Down
12 changes: 8 additions & 4 deletions pymcuprog/serialupdi/physical.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UpdiPhysical:
PDI physical driver using a given serial port at a given baud
"""

def __init__(self, port, baud=DEFAULT_SERIALUPDI_BAUD, timeout=None):
def __init__(self, port, baud=DEFAULT_SERIALUPDI_BAUD, timeout=None, dtr=-1):
"""
Serial port physical interface for UPDI

Expand All @@ -42,13 +42,14 @@ def __init__(self, port, baud=DEFAULT_SERIALUPDI_BAUD, timeout=None):
self.timeout = timeout
else:
self.timeout = 1.0
self.dtr = dtr
self.ser = None

self.initialise_serial(self.port, self.baud, self.timeout)
self.initialise_serial(self.port, self.baud, self.timeout, self.dtr)
# send an initial break as handshake
self.send([constants.UPDI_BREAK])

def initialise_serial(self, port, baud, timeout):
def initialise_serial(self, port, baud, timeout, dtr):
"""
Standard serial port initialisation

Expand All @@ -67,6 +68,9 @@ def initialise_serial(self, port, baud, timeout):
self.logger.error("Unable to open serial port '%s'", port)
raise

if dtr != -1:
self.ser.dtr = (dtr != 0)

def _loginfo(self, msg, data):
if data and isinstance(data[0], str):
i_data = [ord(x) for x in data]
Expand Down Expand Up @@ -109,7 +113,7 @@ def send_double_break(self):

# Re-init at the real baud
temporary_serial.close()
self.initialise_serial(self.port, self.baud, self.timeout)
self.initialise_serial(self.port, self.baud, self.timeout, self.dtr)

def send(self, command):
"""
Expand Down
4 changes: 3 additions & 1 deletion pymcuprog/toolconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ToolSerialConnection(ToolConnection):
"""
serialport = None

def __init__(self, serialport="COM1", baudrate=DEFAULT_SERIALUPDI_BAUD, timeout=None):
def __init__(self, serialport="COM1", baudrate=DEFAULT_SERIALUPDI_BAUD, timeout=None, dtr=-1):
"""
:param serialport: Serial port name to connect to.
:type serialport: str
Expand All @@ -43,7 +43,9 @@ def __init__(self, serialport="COM1", baudrate=DEFAULT_SERIALUPDI_BAUD, timeout=
:param timeout: timeout value for serial reading.
When UPDI is not enabled, attempting to read will return after this timeout period.
:type timeout: float
:type timeout: int
"""
self.serialport = serialport
self.baudrate = baudrate
self.timeout = timeout
self.dtr = dtr