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.

LAUNCHXL-CC1310: How to printf() to the console or serial port using ITM?

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310, LAUNCHXL-CC1352P1,

Hi all,

We've tried to printf() some string to the console or serial monitor by using the code given in this link .  Unfortunately, we haven't seen any output. How it should be done?

Regards

  • Hi YiKai,

    Thank you for the reply. We have used System_printf() so far, but, as described in SimpleLink Academy under Debugging section, even System_printf() can affect performance of the MCU, especially in real-time applications. As far as we know, ITM has not or just some overhead on the MCU so we're greatly interested to utilize it. We found a blog post (link is given below) in which it is said that "ITM can be used to redirect printf() output to a console view in the debugger". Therefore, is it possible in CCS? If so, how to make it work?

    Link:

    blog.atollic.com/cortex-m-debugging-introduction-to-serial-wire-viewer-swv-event-and-data-tracing

    Regards

  • Sorry, I am not sure if this works on CCS. Maybe wait someone from TI to chime in if CCS can do this.
  • Hello,

    The example in the SWO Trace wiki for Software Messages should work:

    http://processors.wiki.ti.com/index.php/SWO_Trace#Software_Messages:

    You should see the messages in the Trace Viewer

    Make sure you route the pins needed for SWO trace.

    Here is a quick example based on the wiki page for the CC1310 LaunchPad (it relies on the SimpleLink CC13x0 SDK v3.10 being installed)

    /cfs-file/__key/communityserver-discussions-components-files/156/SW_5F00_msg_5F00_example_5F00_CC1310_5F00_LAUNCHXL_5F00_nortos_5F00_ccs.zip

    Thanks

    ki

  • Ok, after rereading your question, I see that you are not asking about getting ITM messaging to work but how to redirect it to a the output console or uart. This, I am not sure about. I will need to investigate further.

    Thanks
    ki
  • Hi Ki-Soo,

    Thank you for the replies. We've noticed that we are able to see outputs in Trace Viewer only when system is paused. Is it possible to see the printouts continuously?

    Regards

  • Not with the Trace Viewer. Perhaps you can redirect the messages to C I/O via uart. I will need to investigate the possibility of that.
  • Hi Ki-Soo,

    We connected SWV port to the UART-TX port on LAUNCHXL-CC1352P1  board (which is IOID_13), started capturing from the Event Analysis (Tools->Code Analysis->Event Analysis) in debug mode and set the baud rate of the serial receiver application over than 4000000. After these steps we got the printouts in real-time, which is great. Is it possible to capture automatically (by write some code or script) without clicking on capture each time?

    The code we used in TI Drivers empty project for LAUNCHXL-CC1352P1 board is below:

    /*
     *  ======== empty.c ========
     */
    
    #include <stdio.h>
    #include <stdint.h>
    #include <stdbool.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    
    /* Board Header file */
    #include "Board.h"
    
    /*
     *  ======== mainThread ========
     */
    
    const unsigned ITM_BASE_ADDRESS = 0xE0000000;
    const unsigned ITM_NUM_PORTS = 32;
    const unsigned NUM_TRIALS = 2;
    
    typedef volatile unsigned* ITM_port_t;
    
    void delay(unsigned num_loops)
    {
      unsigned i;
      for (i=0; i<num_loops; i++)
      {
          asm (" NOP");
      }
    }
    
    void port_wait(ITM_port_t port)
    {
        delay(10);
        /* Wait while fifo ready */
        while (*port == 0);
    }
    
    /* Send a nul terminated string to the port */
    void ITM_put_string(ITM_port_t port, const char* data)
    {
        unsigned datapos  = 0;
        unsigned portpos  = 0;
        unsigned portdata = 0;
    
        while('\0' != data[datapos])
        {
            port_wait(port);
            portdata = 0;
    
            /* Get the next 4 bytes of data */
            for (portpos=0; portpos<4; ++portpos) {
                portdata |= data[datapos] << (8*portpos);
                if ('\0' != data[datapos]) {
                    ++datapos;
                }
            }
    
            /* Write the next 4 bytes of data */
            *port = portdata;
        }
    }
    
    /* Send a 32 bit value to the port */
    void ITM_put_32(ITM_port_t port, unsigned data)
    {
        port_wait(port);
        *port = data;
    }
    
    /* Send a 16 bit value to the port */
    void ITM_put_16(ITM_port_t port, unsigned short data)
    {
        /* Cast port for 16-bit data */
        volatile unsigned short* myport = (volatile unsigned short*)port;
        port_wait(port);
        *myport = data;
    }
    
    /* Send a 8 bit value to the port */
    void ITM_put_08(ITM_port_t port, unsigned char data)
    {
        /* Cast port for 8-bit data */
        volatile unsigned char* myport = (volatile unsigned char*)port;
        port_wait(port);
        *myport = data;
    }
    
    void *mainThread(void *arg0)
    {
        IOCPortConfigureSet(IOID_13, IOC_PORT_MCU_SWV, IOC_STD_OUTPUT);
    
        /* 1 second delay */
        uint32_t time = 1;
    
        /* Call driver init functions */
        GPIO_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        /* Turn on user LED */
        GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
    
        while (1) {
            sleep(time);
    //        delay(100);
            GPIO_toggle(Board_GPIO_LED0);
            ITM_put_string((ITM_port_t)ITM_BASE_ADDRESS, "hello world\n\r");
        }
    }
    

    We'll try to do the same for LAUNCHXL-CC1310 and other boards for the future use.

    Regards

  • Hi,


    As we described above the code above works fine on LAUNCHXL-CC1352P1 board.  On LAUNCHXL-CC1310 board we use Hardware Trace Analyzer -> Custom Core Trace to start SWV to trace. We used oscilloscope to compute baud rate which we computed as 4058442, but the output is not clear as it shown in picture below:

    We think that the baud rate we computed is not correct. How to set correct baud rate?

    Regards

  • Hello,

    The baud rate should be configurable. But otherwise I am not too familiar with the UART on the device. It might be best to start a new thread in the device forum.

    Thanks

    ki