-
Notifications
You must be signed in to change notification settings - Fork 4
/
osccal
executable file
·42 lines (32 loc) · 1.47 KB
/
osccal
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
#!/usr/bin/python3
import os
import subprocess
import sys
import time
projDir = os.path.dirname( os.path.realpath(sys.argv[0]) )
os.chdir( projDir )
sys.stderr.write("########################################################\n")
sys.stderr.write("############### burning calibrator #####################\n")
sys.stderr.write("########################################################\n")
subprocess.call(["avrdude", "-qq", "-p", "atmega328p", "-c", "usbasp", "-e", "-V", "-U", "lfuse:w:0xE2:m", "-U", "hfuse:w:0xD2:m", "-U", "efuse:w:0xfd:m", "-U", "eeprom:w:0xff:m", "-U", "flash:w:./calibrator/calibrator.hex"])
time.sleep(3)
sys.stderr.write("########################################################\n")
sys.stderr.write("################# reading result #######################\n")
sys.stderr.write("########################################################\n")
p=subprocess.Popen(["avrdude", "-qq", "-c", "usbasp", "-p", "atmega328p", "-U", "eeprom:r:-:h"],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
out = p.communicate()[0]
if out=='':
sys.stderr.write("No eeprom data\n")
sys.exit(1)
o = [ int(x,16) for x in out.split(b',')[:4] ]
if o[0]==5 and o[3]==5 and o[1]+o[2]==255:
optimal_osccal = o[1]
if len(sys.argv)>1 and sys.argv[1]=='-b':
os.chdir("ATmegaBOOT")
subprocess.call(["make","isp","OPTIMAL_OSCCAL_VALUE="+str(optimal_osccal)])
else:
print(optimal_osccal)
else:
sys.stderr.write("No OSCCAL found in eeprom\n")
sys.exit(1)