forked from filmak/SCuM-programmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscum_nrf_programmer.py
More file actions
89 lines (69 loc) · 2.23 KB
/
scum_nrf_programmer.py
File metadata and controls
89 lines (69 loc) · 2.23 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#python "C:\Users\mitch\OneDrive\SchoolFiles\_URMP\SCuM\Software\test_bootload.py"
import serial
import random
import argparse
import signal
import sys
import time
# User Defined Parameters ****************************************
# Com port of nRF board
nRF_port="COM10"
# Path to SCuM binary
binary_image="C:/Users/mitch/OneDrive/SchoolFiles/_West/nrfSerialPass/hello_world.bin"
# End User Defined Parameters ************************************
def signal_handler(signal, frame):
nRF_ser.reset_input_buffer()
nRF_ser.close()
print("\rBye...")
exit(0)
# Register the signal handler
signal.signal(signal.SIGINT, signal_handler)
# Serial connections
nRF_ser = None
boot_mode='3wb'
pad_random_payload=False
# Open COM port to nRF
nRF_ser = serial.Serial(
port=nRF_port,
baudrate=250000,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS)
# Open binary file from Keil
with open(binary_image, 'rb') as f:
bindata = bytearray(f.read())
# Need to know how long the binary payload to pad to 64kB
code_length = len(bindata) - 1
pad_length = 65536 - code_length - 1
#print(code_length)
# Optional: pad out payload with random data if desired
# Otherwise pad out with zeros - uC must receive full 64kB
if(pad_random_payload):
for i in range(pad_length):
bindata.append(random.randint(0,255))
code_length = len(bindata) - 1 - 8
else:
for i in range(pad_length):
bindata.append(0)
nRF_ser.reset_input_buffer()
# Send the binary data over uart
print("\r\nScuM nRF Serial Programmer.\r\n")
print("\rPress (Ctrl + c) to Exit\r\n")
nRF_ser.write(bindata)
# and wait for response that writing is complete
print(nRF_ser.read_until())
# Display 3WB confirmation message from nRF
print(nRF_ser.read_until())
print("Upload Complete -- Entering UART RX mode.\r\n")
print("\rPress (Ctrl + c) to Exit\r\n")
#set timout or forever be blocked
nRF_ser.timeout = 0.1
# Read bytes from nRF_port until EOL then print and repeat.
message = bytes()
while True:
char = nRF_ser.read(1);
message = message + char
char = char.decode("utf-8", "ignore")
if(char == '\n'):
print(message.decode("utf-8", "ignore"))
message = bytes()