-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstm32duino-reset
executable file
·59 lines (41 loc) · 1.27 KB
/
stm32duino-reset
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
#!/usr/bin/env python
#
# Adapted from
# https://github.com/rogerclarkmelbourne/Arduino_STM32/blob/2363e7bf8821067b78571ed16fbe397a541968a0/tools/macosx/src/upload-reset/upload-reset.c#L132
import time
import argparse
import serial
def reset_target(port, speed=115200, wait=750, **kwargs):
assert port
print('opening {} @ {}'.format(port, speed))
s = serial.Serial(port, speed)
s.setRTS(0)
s.setDTR(0)
s.setDTR(1)
time.sleep(0.05)
s.setDTR(0)
s.setRTS(1)
s.setDTR(1)
time.sleep(0.05)
s.setDTR(0)
time.sleep(0.05)
s.write(b'1EAF')
# Change wait from milliseconds into seconds
time.sleep(wait / 1000)
s.close()
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port')
parser.add_argument('-d', '--device')
parser.add_argument('-s', '--speed', type=int, default=115200)
parser.add_argument('-w', '--wait', type=int, default=750)
args = parser.parse_args()
if args.device:
import serial.tools.list_ports
print('Looking for {}'.format(args.device))
found = [p for p in serial.tools.list_ports.grep(args.device)]
if found:
args.port = found[0].device
reset_target(**vars(args))
if __name__ == '__main__':
main()