Search code examples
ctrace32lauterbach

Print debug text from C code into Lauterbach TRACE32


Is it possible to print debug text from C code (running on embedded system) into Lauterbach TRACE32 (connected over Lauterbach hardware)? Previously we used to output it via UART (serial connection) but now it is not available.


Solution

  • It is possible to print text from the target application to TRACE32. Some vendors call the mechanism you are searching for a JTAG Terminal, Semihosting (ARM) or Hostlink (Synopsys).

    This is handled in TRACE32 with the TERM command group.

    The usual approach is as following:

    • Add t32term.c, t32term_memory.c and t32term.h to you project. You can find those files in your TRACE32 installation at <t32>/demo/etc/terminal/t32term.

    • Compile t32term.c and t32term_memory.c with defined macro T32_TERM_BLOCKED=1, T32_TERM_METHOD_MEMORY=1, and T32_TERM_MEMORY_BLOCKED_SIZE=256 . E.g.:

       TERMOPT:=-DT32_TERM_BLOCKED=1 -DT32_TERM_METHOD_MEMORY=1 -DT32_TERM_MEMORY_BLOCKED_SIZE=256
       gcc  $(TERMOPT) -c  -o t32term.o  t32term.c
       gcc  $(TERMOPT) -c  -o t32term_memory.o  t32term_memory.c
      

      Of course instead of just "gcc" you have to use here the cross-compiler for your target with all the CPU specific options.

    • In your application use function T32_Term_Puts(const char *str) to send a text-buffer to TRACE32

    • To use something like printf() write a wrapper function around T32_Term_Puts() around vsprintf(). Some compiler's C library provides already some printf(), which calls in the end some weakly declared puts() function, which you can overwrite with T32_Term_Puts().

    • During linking ensure that the buffers T32_Term_Memory_Tar2HostBuffer and T32_Term_Memory_Host2TarBuffer get placed into uncached memory.

    • In TRACE32 use the following commands:

       SYStem.MemAccess Enable   // Enable memory access to running CPU
       TERM.METHOD BufferE E:T32_Term_Memory_Tar2HostBuffer E:T32_Term_Memory_Host2TarBuffer
       TERM.GATE
      

    The window TERM.GATE receives the data you've send with T32_Term_Puts(). You have to keep it open.

    TERM.METHOD specifies the way how TRACE32 receives the printed data from your target application. The method BufferE is pretty common and works with all CPUs which support reading memory by the debugger while the CPU is running. There are other methods available you might have to use if BufferE is not possible.

    For the method BufferE you have to allow the debugger to access target memory while the CPU is running. This is done with the command SYStem.MemAccess Enable. Depending on the CPU family you are debugging and the version of TRACE32 you have to use the keyword CPU, DAP or NEXUS instead of Enable.

    The mechanism allows you not only to send text to TRACE32. It allows you also to open files from the PC running TRACE32, write data to a file, get the system time or start applications.

    If your target chip contains an ITM or STM hardware trace module and you own a tracing hardware from Lauterbach (like CombiProbe or PowerTrace) you can also use that mechanism to send text from you target application to TRACE32.