Trace32 Lauterbach APIs for C program access to the application variables

落爺英雄遲暮 提交于 2019-12-23 03:29:13

问题


I have an ECU with Infineon controller and some xyz program flashed in it. Now the values of the variables of the program can be seen real time in Trace32 debugger with Lauterbach hardware. Now I have to note down all the values manually in report. I want to access those values using Trace32 APIs using C programming to automatically write those values in excel or notepad. I tried their API for Remote Control and JTAG Access document but could not do much. Can anyone please guide? I couldn't even configure Trace32 Software and not even send some command to Lauterbach. My main purpose is the values which I can see in Trace32 GUI should be accessible in C program using Trace32 APIs.


回答1:


First enable the remote API port of TRACE32. Ensure that file c:\t32\config.t32 contains the following lines (there must be a blank line before and after the two lines!):

RCL=NETASSIST
PORT=20000

To read a value of a variable myVariable via the remote API and store it to a log file write a C application like that:

#include "t32.h"
#include <stdio.h>

int main(int argc, char **argp) {
    uint32_t result;
    FILE    *fp;

    /* Connect to TRACE32 */
    T32_Config("NODE=", "localhost");
    T32_Config("PORT=", "20000");

    if ( T32_Init() != T32_OK )
        return 2;
    T32_Attach(T32_DEV_ICD);

    /* Read value of variable myVariable */
    if ( T32_Cmd("Eval Var.VALUE(myVariable)") != T32_OK ) {
        T32_Exit();
        return 3;
    }
    T32_EvalGet ( &result ); /* get data from previous Eval command */

    /* add data to logfile */
    fp = fopen ( "myLogfile.txt", "a" );
    if ( fp ) {
        fprintf( fp, "0x%08X\n", result);
        fclose( fp );
    }

    T32_Exit();
    puts("done");
    return 0;
}

There are also other ways to get memory content via the remote API, but this is the easiest way in my opinion.

Now compile this code and link it with hremote.c, hlinknet.c and the socket library. E.g. with this makefile:

VPATH := . /cygdrive/c/t32/demo/api/src
CC    := i686-pc-mingw32-gcc.exe

myProg.exe : myProg.o hremote.o hlinknet.o
    $(CC) -o $@  $^ -lws2_32

%.o : %.c t32.h
    $(CC) -c $(addprefix -I,$(VPATH)) -D T32HOST_WIN -o $@  $<

However maybe it is a lot more easy and flexible to do you task with a PRACTICE script (*.cmm) instead.

E.g. write a script myScript.cmm like that:

OPEN #1 myLogfile.txt /APPEND                      // Opens file myLogfile.txt for adding data
WRITE #1 "0x"+FORMAT.HEX(8,Var.VALUE(myVariable))  // Write value of myVariable to logfile 
CLOSE #1                                           // Close logfile

Execute this script in the command line of the TRACE32 GUI with the command

DO myScript.cmm 

Or execute this script via the remote API, e.g. with t32rem.exe:

C:\t32\bin\windows\t32rem.exe localhost port=20000 "DO myScript.cmm"


来源:https://stackoverflow.com/questions/28074701/trace32-lauterbach-apis-for-c-program-access-to-the-application-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!