Skip to content

Fix for issue sparkfun/Apollo3_Uploader_SVL#4 #6

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions svl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
import argparse
import serial
import serial.tools.list_ports as list_ports
import termios
import sys
import time
import math
import os.path
from sys import exit
import platform as sys_pf

SCRIPT_VERSION_MAJOR = "1"
SCRIPT_VERSION_MINOR = "7"
Expand Down Expand Up @@ -336,9 +338,28 @@ def main():
bl_success = False
entered_bootloader = False

system_type = sys_pf.system().lower()
for _ in range(num_tries):

with serial.Serial(args.port, args.baud, timeout=args.timeout) as ser:
# Set port to known state
if args.reset_port:
if system_type == "linux":
attrs = termios.tcgetattr(ser.fd)
c_iflag = 0
c_oflag = 0
port_speed = attrs[4]
c_cflag = termios.CS8 | termios.CREAD | termios.HUPCL | termios.CLOCAL | port_speed
c_lflag = 0
c_ispeed = port_speed
c_ospeed = port_speed

new_attrs = [c_iflag, c_oflag, c_cflag, c_lflag, c_ispeed, c_ospeed, attrs[6]]
if attrs != new_attrs:
verboseprint("Resetting Port config")
termios.tcsetattr(ser.fd, termios.TCSANOW, new_attrs)
ser.close()
ser.open()

# startup time for Artemis bootloader (experimentally determined - 0.095 sec min delay)
t_su = 0.15
Expand Down Expand Up @@ -393,6 +414,9 @@ def main():
parser.add_argument("-t", "--timeout", default=0.50, help="Communication timeout in seconds (default 0.5)",
type=float)

parser.add_argument("-r", "--reset-port", action="store_true", default=False,
help="Reset the port configuration.")

if len(sys.argv) < 2:
print("No port selected. Detected Serial Ports:")
devices = list_ports.comports()
Expand Down