This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F280049C: Running parts of a DSS file through a python3 script while not losing the debugSession details

Part Number: TMS320F280049C
Other Parts Discussed in Thread: CCSTUDIO

Tool/software:

The code atached below is a JS file that works as expected when using it with DSS. But I want to integrate the JS functions into a larger Python application that I have.

For example I want to create a debug Session, connect to the board and load the program after which the python application will perform the necessary tests and then the Stack usage function in the JS file should be run.

I have tried using Jython but the jython script needs to be run through a Jython command and cant be run through Python3 which resilts in the code losing the Session details once a part of the code is run.

Please Suggest me a way to run individual JS functions through a python Script while also keeping the debugSession Alive.

var PROJ_NAME = "gpio_ex3_interrupt"
var PROJ_WKSPC_LOC = "C:\\Users\\Sanskar Chandaliya\\Workspace_Stack_Paint"
 var PROJ_CONFIG = "CPU1_RAM"
var STACK_START_ADDR = 0xf4; // Example stack start address, adjust as necessary
var STACK_SIZE = 0x700;       // Example stack size, adjust as necessary
var PATTERN = 0xDEADBEEF;//

function calculatePeakStackUsage(startAddr, size, pattern) {
    var peakStackAddr = startAddr;
    for (var addr = startAddr; addr < startAddr + size; addr += 2) {
        var value = debugSession.memory.readData(1, addr, 32);
        if (value != pattern) {
            peakStackAddr = addr;
        }
    }
    return peakStackAddr;
}
//
// Import the DSS packages
//
importPackage(Packages.com.ti.debug.engine.scripting)
importPackage(Packages.com.ti.ccstudio.scripting.environment)
importPackage(Packages.java.lang)


var script = ScriptingEnvironment.instance();
// ccsServer = script.getServer("CCSServer.1")
// ccsSession = ccsServer.openSession(".*") 

script.traceSetConsoleLevel(TraceLevel.ALL)

var ds = script.getServer( "DebugServer.1" );


ds.setConfig("C:\\Users\\Sanskar Chandaliya\\Workspace_Stack_Paint\\gpio_ex3_interrupt\\targetConfigs\\TMS320F280049C.ccxml")
debugSession = ds.openSession( "*", "C28xx_CPU1" );
// debugSession.options.setBoolean("AutoRunToLabelOnReset", true);
try {
    // Connect to the target
    if (!debugSession.target.isConnected()) {
        debugSession.target.connect();
    }
} catch (ex) {
    script.traceWrite("Connect to target " + " failed!\nTerminating script.");
    throw ex; // Exit the script
}
if (!debugSession.target.isHalted()) {
    debugSession.target.halt();
}

// debugSession.memory.loadProgram("D:\\git_repos\\MC-BOOTLOADER\\UV_Bootloader\\CPU1_FLASH\\Bootloader.out")
debugSession.flash.options.setString("FlashEraseSelection", "Necessary Sectors Only (for Program Load)");
debugSession.options.setBoolean("AutoRunToLabelOnRestart", false);

debugSession.memory.loadProgram("D:\\git_repos\\MC-FIRMWARE-SUPER\\UV_MotorControl\\280049C_MC01\\UV_MotorControl.out")
if (!debugSession.target.isHalted()) {
    debugSession.target.halt();
}
print("Painting Stack")

for (var addr = STACK_START_ADDR; addr < STACK_START_ADDR + STACK_SIZE; addr += 2) {
    debugSession.memory.writeData(1, addr, PATTERN, 32); // Using 0 for PROGRAM memory page, adjust if needed
}
print("Stack Painted")

var verificationSuccess = true;
for (var addr = STACK_START_ADDR; addr < STACK_START_ADDR + STACK_SIZE; addr += 2) {
    var value = debugSession.memory.readData(1, addr, 32);
    if (value != PATTERN) {
        print("Verification failed at address 0x" + addr.toString(16) + ": expected 0xDEADBEEF, got 0x" + value.toString(16));
        verificationSuccess = false;
        break;
    }
}
if (verificationSuccess) {
    print("Stack verification successful.");
} else {
    print("Stack verification failed.");
}
print("Program is Loaded Successfully")
var properties=debugSession.breakpoint.createProperties();
properties.setString("Hardware Configuration.Type.Trigger 1", "");
properties.setString("Hardware Configuration.Type.Trigger 1.Location", 0x00760);
properties.setString("Hardware Configuration.Type.Trigger 1.Access", "Write");
properties.printProperties();
// env.traceWrite("--");

debugSession.breakpoint.add(properties);
debugSession.clock.runBenchmark()
if (debugSession.target.isHalted()) {
    print("targget is running")
    var peakStackAddr = calculatePeakStackUsage(STACK_START_ADDR, STACK_SIZE, PATTERN);
    print("Peak stack usage address: 0x" + peakStackAddr.toString(16));
    print("Peak stack usage size: " + (peakStackAddr - STACK_START_ADDR) + " bytes");
}

debugSession.target.runAsynch()
java.lang.Thread.sleep(10000); // Adjust sleep time as needed
if (!debugSession.target.isHalted()) {
    debugSession.target.halt();
}
print("Target is halted")
var haltedAddress = debugSession.memory.readRegister("PC"); // Adjust if needed based on the architecture
print("Target halted at address: 0x" + haltedAddress.toString(16));
// Calculate peak stack usage
var peakStackAddr = calculatePeakStackUsage(STACK_START_ADDR, STACK_SIZE, PATTERN);
print("Peak stack usage address: 0x" + peakStackAddr.toString(16));
print("Peak stack usage size: " + (peakStackAddr - STACK_START_ADDR) + " bytes");

while(1){}

  • Hello,

    You need a python implementation that can interface with Java APIs like Jython. Stock python will not work. Please note that the only language officially supported by DSS is javascript. Any other languages require an implementation that allow it to interface with Java APIs. Note that this functionality is available "as-is" and we cannot provide any support for this.

    Ideally you should use one environment (Jython) here instead of trying to mix and match.

    ki