-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrunme.py
103 lines (71 loc) · 2.44 KB
/
runme.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
api_dll_and_loader_path = 'C:/Program Files/STMicroelectronics/STM32Cube/STM32CubeProgrammer/api/lib/' # Directory containing DLLs, ExternalLoader and FlashLoader.
import os # noqa: E402
os.add_dll_directory(api_dll_and_loader_path) # Path to DLLs before importing CubeProgrammer_API. https://stackoverflow.com/a/67437837/101252
# noinspection PyUnresolvedReferences
import CubeProgrammer_API # noqa: E402
def init_progress_bar():
print(f'InitProgressBar')
def log_message(msgType : int, str):
if msgType < 22:
# print(f'{msgType}, {str}')
print(f'{str}')
def load_bar(curr_progress: int, total: int):
print(f'{100 * curr_progress / total}%')
api = CubeProgrammer_API.CubeProgrammer_API()
api.setDisplayCallbacks(
initProgressBar=init_progress_bar,
logMessage=log_message,
loadBar=load_bar)
api.setLoadersPath(api_dll_and_loader_path)
def check_connection():
x = api.checkDeviceConnection()
str = 'Connected' if 1==x else 'Not connected'
print(f'checkDeviceConnection: {str}')
check_connection()
list = api.getStLinkList()
print(f'list: {list}')
if len(list) == 1:
x = api.connectStLink()
if x < 0:
api.disconnect()
quit()
check_connection()
genInfo = api.getDeviceGeneralInf()
print(f'genInfo: {genInfo}')
resetFlag = api.reset(0)
if resetFlag != 0:
api.disconnect()
quit()
if False: # switch to enable downloads.
isVerify = 1 # add verification step
isSkipErase = 0 # no skip erase
filePath = r'C:\Users\james.frederick\src\uctq_Sandbox\E102878-Qx\QuadRfDriverFirmware\Debug\QuadRfDriverFirmware.elf'
downloadFileFlag = api.downloadFile(filePath) #, 0x08000000, isSkipErase, isVerify, "")
if downloadFileFlag != 0:
api.disconnect()
quit()
size = 64
startAddress = 0x08000000
data = api.readMemory(address=startAddress, byte_qty=size)
print(f'data: {data}')
print(f'\nReading 32-bit memory content')
print(f' Size : {size} Bytes')
print(f' Address: : 0x{startAddress:08X}')
i = 0
while i < size:
col = 0
print(f'\n@0x{startAddress + i:08X}:', end="")
while (col < 4) and (i < size):
# print(f' {data[i+3]:02X}{data[i+2]:02X}{data[i+1]:02X}{data[i]:02X} ', end="")
u32 = int.from_bytes(data[i:i + 4], byteorder='little', signed=False)
print(f' {u32:08X} ', end="")
col += 1
i += 4
print()
# Run application
executeFlag = api.execute()
if executeFlag != 0:
api.disconnect()
quit()
api.disconnect()
# input("Press Enter to continue...") # pause to see result