Skip to content
This repository was archived by the owner on Aug 27, 2021. It is now read-only.

Allow use of USB programmers like avrispmkII #208

Closed
wants to merge 2 commits into from
Closed
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
72 changes: 43 additions & 29 deletions ino/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,28 @@ def run(self, args):
# if v1 is not specifid explicitly avrdude will
# try v2 first and fail
protocol = 'stk500v1'

if not os.path.exists(port):
raise Abort("%s doesn't exist. Is Arduino connected?" % port)

# send a hangup signal when the last process closes the tty
file_switch = '-f' if platform.system() == 'Darwin' else '-F'
ret = subprocess.call([self.e['stty'], file_switch, port, 'hupcl'])
if ret:
raise Abort("stty failed")

# pulse on DTR
try:
s = Serial(port, 115200)
except SerialException as e:
raise Abort(str(e))
s.setDTR(False)
sleep(0.1)
s.setDTR(True)
s.close()

if port == 'usb':
pass
else:
if not os.path.exists(port):
raise Abort("%s doesn't exist. Is Arduino connected?" % port)

# send a hangup signal when the last process closes the tty
file_switch = '-f' if platform.system() == 'Darwin' else '-F'
ret = subprocess.call([self.e['stty'], file_switch, port, 'hupcl'])
if ret:
raise Abort("stty failed")

# pulse on DTR
try:
s = Serial(port, 115200)
except SerialException as e:
raise Abort(str(e))
s.setDTR(False)
sleep(0.1)
s.setDTR(True)
s.close()

# Need to do a little dance for Leonardo and derivatives:
# open then close the port at the magic baudrate (usually 1200 bps) first
Expand Down Expand Up @@ -126,13 +129,24 @@ def run(self, args):
port = new_port

# call avrdude to upload .hex
subprocess.call([
self.e['avrdude'],
'-C', self.e['avrdude.conf'],
'-p', board['build']['mcu'],
'-P', port,
'-c', protocol,
'-b', board['upload']['speed'],
'-D',
'-U', 'flash:w:%s:i' % self.e['hex_path'],
])
if port == 'usb':
subprocess.call([
self.e['avrdude'],
'-C', self.e['avrdude.conf'],
'-p', board['build']['mcu'],
'-P', port,
'-c', protocol,
'-b', board['upload']['speed'],
'-U', 'flash:w:%s:i' % self.e['hex_path'],
])
else:
subprocess.call([
self.e['avrdude'],
'-C', self.e['avrdude.conf'],
'-p', board['build']['mcu'],
'-P', port,
'-c', protocol,
'-b', board['upload']['speed'],
'-D',
'-U', 'flash:w:%s:i' % self.e['hex_path'],
])