winIDEA SDK
read_uint64.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5"""
6This script demonstrates reading of GPRs using readRegister() and
7SFRs with bitfields using method evaluate().
8It reads from a register specified in command line and prints its value.
9"""
10
11import isystem.connect as ic
12import sys
13
14
15winidea_id = ''
16
17
18def unsigned64(x: int) -> int:
19 """
20 This function performs a kind of cast from signed 64-bint int to unsigned one.
21 """
22 return x & 0xffffffffffffffff
23
24
25# First we obtain connection and controller objects
26cmgr = ic.ConnectionMgr()
27cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
28
29debugCtrl = ic.CDebugFacade(cmgr)
30
31if len(sys.argv) != 2:
32 print("Usage : ", sys.argv[0], "<general purpose register name>")
33 print("Example: ", sys.argv[0], "R0")
34 exit(-1)
35
36registerName = sys.argv[1]
37value = debugCtrl.readRegister(ic.IConnectDebug.fRealTime, registerName)
38print(registerName, '=', hex(unsigned64(value.getLong())))
39
40# For SFRs we have to use method evaluate()
41registerName = '@GPIOA\\ODR'
42value = debugCtrl.evaluate(ic.IConnectDebug.fRealTime, registerName)
43print(registerName, '=', hex(unsigned64(value.getLong())))
44
45# We can also specify bitfields (STM32F103 specific)
46registerName = '@GPIOA\\LCKR\\LCKK'
47value = debugCtrl.evaluate(ic.IConnectDebug.fRealTime, registerName)
48print(registerName, '=', hex(unsigned64(value.getLong())))