-
Notifications
You must be signed in to change notification settings - Fork 0
/
master-flash.py
executable file
·60 lines (48 loc) · 1.55 KB
/
master-flash.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
53
54
55
56
57
58
59
import subprocess
import sys
import time
if(len(sys.argv) < 3):
print('Specify arguments')
print('python master-flash [s/c] [d/r]')
exit()
def dots_print(s):
for i in range(4):
print(s + ' ' + ('.' * i) + (' ' * (4 - i)), end='\r')
time.sleep(0.1)
chipid = ''
if(sys.argv[1] == 'c'):
chipid = b'0x0410'
dots_print('Writing to the STM32F103')
elif(sys.argv[1] == 's'):
chipid = b'0x0411'
dots_print('Writing to the STM32F205')
else:
print('Invalid Arguments')
while(chipid not in subprocess.check_output(['st-info','--probe'])):
dots_print('Waiting for Chip ID')
while(b'flash: 0' in subprocess.check_output(['st-info','--probe'])):
dots_print('Waiting for reset pin removal')
sys.stdout.buffer.write((subprocess.check_output(['st-info','--probe'])))
time.sleep(0.1)
dots_print('Writing now ')
print('')
command = ''
if(sys.argv[1] == 's' and sys.argv[2] == 'd'):
command='st-flash write Sensors/Debug/Sensors.bin 0x8000000'
elif(sys.argv[1] == 's' and sys.argv[2] == 'r'):
command='st-flash write Sensors/Release/Sensors.bin 0x8000000'
elif(sys.argv[1] == 'c' and sys.argv[2] == 'd'):
command='st-flash write Communications/Debug/Communications.bin 0x8000000'
elif(sys.argv[1] == 'c' and sys.argv[2] == 'r'):
command='st-flash write Communications/Release/Communications.bin 0x8000000'
while(True):
try:
output = subprocess.check_output(command.split(' '), stderr=subprocess.STDOUT)
except(subprocess.CalledProcessError):
output = b''
if b'jolly good' in output:
print('JOLLY GOOD!')
break
else:
sys.stdout.buffer.write(output)
input()