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.

CCS/TM4C123GH6PM: Accessing Variables from CCS in .js script

Part Number: TM4C123GH6PM

Tool/software: Code Composer Studio

I want to write a unit test script code(.js ) to test a code written in  in TM4c123GH6PM .I have taken a very simple code of adding two numbers to learn unit testing

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
int summer(int,int);
int i=0;
int c;
int m;
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
m=summer(5,6);
}


int summer(int a,int b)
{
	c=a+b;
    return c;
}

I want to test the "summer" function ..I want to write a test script for same in .js . Can i access the variable  "m" into the .js script in a conventional .js scripting. I learnt the tutorials like breakpoints and others which were the starting point tutorials ...

Thanking you  

  • Hello,

    You can use the DSS APIs to get the address of "m" and then read the data at that address.

    var addr = debugSession.symbol.getAddress("m");

    var val = debugSession.memory.readWord(addr);

    Thanks

    ki

  • Thank you Mr Ki-Soo Lee

    It worked for me..

    Thanks
  • API suggested By you Worked Mr Ki
  • Mr Ki, I am again struck at a point where i have to run a particular test case function "port_read" who i want to call

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/gpio.h"
    int  port_read(void);
    
    int x=0;
    int y=0;
    
    int main(void)
    {
    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, 2);
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 2);
    //x=port_read();
    
    }
    
    
    int  port_read(void)
    {
    	return GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1);
    
    }

    My script is as follows 

    // Import the DSS packages into our namespace to save on typing
    importPackage(Packages.com.ti.debug.engine.scripting);
    importPackage(Packages.com.ti.ccstudio.scripting.environment);
    importPackage(Packages.java.lang);
    print("New Code Under Execution");
    //buildProject "red_led";
    
    // Modify these variables to match your environment. Use forward slashes
    var ccs5InstallDir = "C:/ti";
    var DSSWorkshopDir = "C:/CCSWorkshop/dss"
    var deviceCCXMLFile = DSSWorkshopDir + "/lab1/StellarisLaunchPad.ccxml";
    
    var programToLoad = DSSWorkshopDir + "/workspace/Simple_Trial3/Debug/Simple_Trial3.out";
    
    var logFile = DSSWorkshopDir + "/workspace/Simple_Trial3/log.xml";
    
    // Create our scripting environment object - which is the main entry point 
    // into any script and the factory for creating other Scriptable Servers and Sessions
    var script = ScriptingEnvironment.instance();
    
    // Create a log file in the current directory to log script execution
    script.traceBegin(logFile, ccs5InstallDir + "/ccsv6/ccs_base/scripting/examples/DebugServerExamples/DefaultStylesheet.xsl");
    
    // Set trace levels for console and logs
    script.traceSetConsoleLevel(TraceLevel.INFO);
    script.traceSetFileLevel(TraceLevel.ALL);
    
    script.traceWrite("Begin scripting session");
    
    // Get the Debug Server and start a Debug Session
    var debugServer = script.getServer("DebugServer.1");
    debugServer.setConfig(deviceCCXMLFile);
    var debugSession = debugServer.openSession(".*");
    
    // Check to see if target is already connected
    // target.isConnected() API will return 'true' is connected
    if (!debugSession.target.isConnected())
    {
      // Connect to the CPU
      debugSession.target.connect();
    }
    
    // Load a program
    debugSession.memory.loadProgram(programToLoad);
    debugSession.breakpoint.removeAll();
    
    // Run the target
    debugSession.target.run();
    print("Running");
    
    
    
    var address1 = debugSession.symbol.getAddress("port_read");
    debugSession.memory.writeRegister("PC", address1);
    debugSession.target.run();
    
    
    
    
    
    
    // All done
    debugServer.stop();
    
    script.traceWrite("End scripting session");
    
    // Stop logging and exit.
    script.traceEnd();
    
    
    
    
    
    
    
    

    When i run the code I am getting following problems 

    New Code Under Execution
    Running
    Unable to get address for symbol: port_read (C:\CCSWorkshop\dss\workspace\Simple_Trial3\lab3.js#57)

    Tried many times .. But it is hanging at that line 57 for a very long time and throwing me the message i pasted above

  • Please make sure that the symbol "port_read" is in scope when trying to get the address for it.

    Thanks
    ki