How do I access to UDE using the Python script interpreter?
Coding instructions can be executed on the Python script console both as direct input or as script file.
Hint: Simple scripts can be developed and executed step by step in the Python console. After successful execution of the steps, the Python console history can be saved as a Python script file, edited and replayed as Python script file. Use the Context Menu - Save Command History as Script.
Per default, these UDE objects are available in Python script console:
UDEUtilities .. DIUDEUtilities UDEApplication .. IUDEApplication UDEWorkspace .. IUDEWorkspace
Reading and writing memory with Python
With the functions ReadMemory32()
/ WriteMemory32()
of a UDEDebugger object, the script read/write the content of a memory address (e.g. 0xC0000000
) via a 32-bit read access.
>>> UDEDebugger = UDEWorkspace.GetActiveCoreDebugger() # Create a UDEDebugger object >>> hex(UDEDebugger.ReadMemory32("0xC0000000") & 0xFFFFFFFF) # Read the memory content 0x87654321
Hint: Note the trick with the trailing '& 0xFFFFFFFF
', with interprets the return value (0x87654321
in this case) as an unsigned number and not as an integer value (-0x789abcdf
in thats case) in order to avoid negative values from hex()
.
Reading and writing registers with Python
With the functions ReadRegister()
/ WriteRegister(
) of a UDEDebugger object, the script read/write the content of core register or special function register (e.g. A0
).
>>> UDEDebugger = UDEWorkspace.GetActiveCoreDebugger() # Create a UDEDebugger object >>> hex(UDEDebugger.ReadRegister("A0") & 0xFFFFFFFF) # Read the register content 0x12345678
Reading and writing variables with Python
With the functions ReadVariable()
/ WriteVariable()
of a UDEDebugger object, the script read/write the content of a static variable (e.g. from timedemo sample).
>>> UDEDebugger = UDEWorkspace.GetActiveCoreDebugger() # Create a UDEDebugger object >>> hex(UDEDebugger.ReadVariable("Seconds") & 0xFFFFFFFF) # Read the variable content
Program loading with Python
With the function LoadProgramFile()
of a UDEDebugger object, the script load an .elf file (e.g. from timedemo sample).
>>> UDEDebugger.LoadProgramFile(r"D:\UdeSamples\TimeDemo\HighTec_IntRam\TimeDemo.elf") True
Starting, stopping and stepping through programs with Python
With the functions Go()
/ Break()
/ StepIn()
/ ResetTarget(
) of a UDEDebugger
object, the script starts and brakes the execution an *.elf
file (e.g. from timedemo sample).
>>> UDEDebugger.LoadProgramFile(r"D:\UdeSamples\TimeDemo\HighTec_IntRam\TimeDemo.elf") True >>> UDEDebugger.Start() # Start the excution of a loaded program pattern >>> UDEDebugger.Break() # Break the execution of a program >>> UDEDebugger.StepIn() # Step into the next instruction of a program >>> UDEDebugger.ResetTarget() # Reset the target