-
Notifications
You must be signed in to change notification settings - Fork 3
/
avrdude.py
52 lines (48 loc) · 1.59 KB
/
avrdude.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import subprocess
import time
#
# AVRDUDE, dude
#
class Avrdude():
"avrdude properties"
def __init__(self):
self.path = ""
self.programmer = ""
self.programmerSN = ""
self.port = ""
self.baudrate = ""
self.configFile = ""
self.autoEraseFlash = True
def upload(self, target, timeout = 15):
#assemble argument array
cmd = [self.path, "-c", self.programmer, "-P", self.port]
if self.programmerSN:
cmd[2].append(":" + self.programmerSN)
if target.name:
cmd.append("-p" + target.name)
if self.baudrate:
cmd.append("-b" + self.baudrate)
if self.configFile:
cmd.append("-C" + self.configFile)
if self.autoEraseFlash:
cmd.append("-D")
if target.bootloader:
cmd.append("-Uflash:w:" + target.bootloader + ":i")
if target.extFuse:
cmd.append("-Uefuse:w:" + target.extFuse + ":m")
if target.highFuse:
cmd.append("-Uhfuse:w:" + target.highFuse + ":m")
if target.lowFuse:
cmd.append("-Ulfuse:w:" + target.lowFuse + ":m")
if target.lockBits:
cmd.append("-Ulock:w:" +target.lockBits + ":m")
#call avrdude as a subprocess
self.uploadProcess = subprocess.Popen(cmd)
timeoutCount = 0
while self.uploadProcess.poll() is None: # still alive
time.sleep(0.5)
timeoutCount += 0.5
if timeoutCount == timeout:
self.uploadProcess.kill()
return False
return True