diff options
-rwxr-xr-x | Basic-Test-Package/BSL/MSP432/msp432-bsl-start.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Basic-Test-Package/BSL/MSP432/msp432-bsl-start.py b/Basic-Test-Package/BSL/MSP432/msp432-bsl-start.py new file mode 100755 index 0000000..75df7f8 --- /dev/null +++ b/Basic-Test-Package/BSL/MSP432/msp432-bsl-start.py | |||
@@ -0,0 +1,76 @@ | |||
1 | #!/usr/bin/python | ||
2 | |||
3 | import serial, time | ||
4 | |||
5 | |||
6 | #initialization and open the port | ||
7 | |||
8 | #possible timeout values: | ||
9 | # 1. None: wait forever, block call | ||
10 | # 2. 0: non-blocking mode, return immediately | ||
11 | # 3. x, x is bigger than 0, float allowed, timeout block call | ||
12 | ser = serial.Serial() | ||
13 | ser.port = "/dev/ttyUSB0" # Linux | ||
14 | #ser.port = "COM1" # Windows | ||
15 | ser.baudrate = 115200 | ||
16 | ser.bytesize = serial.EIGHTBITS #number of bits per bytes | ||
17 | ser.parity = serial.PARITY_NONE #set parity check: no parity | ||
18 | ser.stopbits = serial.STOPBITS_ONE #number of stop bits | ||
19 | #ser.timeout = None #block read | ||
20 | #ser.timeout = 1 #non-block read | ||
21 | ser.timeout = 2 #timeout block read | ||
22 | ser.xonxoff = False #disable software flow control | ||
23 | ser.rtscts = False #disable hardware (RTS/CTS) flow control | ||
24 | ser.dsrdtr = False #disable hardware (DSR/DTR) flow control | ||
25 | ser.writeTimeout = 1 #timeout for write | ||
26 | ser.readTimeout = 1 #timeout for read | ||
27 | |||
28 | try: | ||
29 | ser.open() | ||
30 | |||
31 | except Exception as e: | ||
32 | print ("error open serial port: " + str(e)) | ||
33 | exit(1) | ||
34 | |||
35 | if ser.isOpen(): | ||
36 | |||
37 | try: | ||
38 | |||
39 | #if inverted: | ||
40 | set_bootloader_pin = ser.setRTS | ||
41 | set_reset_pin = ser.setDTR | ||
42 | |||
43 | #else: | ||
44 | #set_bootloader_pin = ser.setDTR | ||
45 | #set_reset_pin = ser.setRTS | ||
46 | |||
47 | print("Forze BL[RTS] to Idle State (high)") | ||
48 | print("Set RST[DTS] active (low) ") | ||
49 | |||
50 | set_bootloader_pin(0) | ||
51 | set_reset_pin(1) | ||
52 | time.sleep(0.2) | ||
53 | |||
54 | # Start Sequence: High to Low | ||
55 | set_bootloader_pin(1) | ||
56 | time.sleep(0.001) | ||
57 | |||
58 | # RST Low to High | ||
59 | set_reset_pin(0) | ||
60 | # RST High to Low | ||
61 | set_reset_pin(1) | ||
62 | # RST Low to High Again | ||
63 | set_reset_pin(0) | ||
64 | |||
65 | # Restore Default State | ||
66 | time.sleep(0.3) # Time to enter BSL | ||
67 | |||
68 | ser.close() | ||
69 | |||
70 | except Exception as e1: | ||
71 | print ("error communicating...: " + str(e1)) | ||
72 | exit(1) | ||
73 | |||
74 | else: | ||
75 | print ("cannot open serial port ") | ||
76 | exit(1) | ||