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.

MSP432P401R: How to output trace to SWO without CCS

Part Number: MSP432P401R

Dear Champ,

I had refer SWO Trace () to test SWO function in the CCS. I want to have SWO trace functionality without CCS. I add below into my code.

/*
* Initialize the SWO trace port for debug message printing
* \param portNumber Port bit mask to be configured
* \param cpuCoreFreqHz CPU core clock frequency in Hz
* \param swoSpeed SWO output bit rate in Hz
*/
void SwoInit(uint32_t portNumber, uint32_t cpuCoreFreqHz, uint32_t swoSpeed)
{
/* SWOSpeed in Hz, note that cpuCoreFreqHz is expected to be match the CPU core clock */
uint32_t swoPrescaler = (cpuCoreFreqHz / swoSpeed) - 1;

/* enable trace in core debug */
CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk;
/* ITM Lock Access Register, C5ACCE55 enables more write access to Control Register 0xE00 :: 0xFFC */
ITM->LAR = 0xC5ACCE55;
/* "Selected PIN Protocol Register": Select which protocol to use for trace output (2: SWO NRZ, 1: SWO Manchester encoding) */
TPI->SPPR = 0x00000002;
/* "Async Clock Prescaler Register". Scale the baud rate of the asynchronous output */
TPI->ACPR = swoPrescaler;
/* ITM Trace Control Register */
ITM->TCR = ITM_TCR_TraceBusID_Msk | ITM_TCR_SWOENA_Msk | ITM_TCR_DWTENA_Msk | ITM_TCR_SYNCENA_Msk | ITM_TCR_ITMENA_Msk;
/* ITM Trace Privilege Register */
ITM->TPR = ITM_TPR_PRIVMASK_Msk;
/* ITM Trace Enable Register. Enabled tracing on stimulus ports. One bit per stimulus port. */
ITM->TER = (1ul << portNumber);
/* DWT_CTRL */
DWT->CTRL = 0x400003FE;
/* Formatter and Flush Control Register */
TPI->FFCR = 0x00000100;
}


/*
* Sends a character over the SWO channel. See as well ITM_SendChar() in core_cm4.h
* \param c Character to be sent
* \param portNo SWO channel number, value in the range of 0 to 31
*/
void SwoPrintChar(char c, uint8_t portNo)
{
volatile int timeout;

/* check Trace Control Register if ITM trace is enabled*/
if ((ITM->TCR & ITM_TCR_ITMENA_Msk) == 0)
{
/* not enabled? */
return;
}

/* check Trace Enable Register if requested port is enabled */
if ((ITM->TER & (1ul << portNo)) == 0)
{
/* requested port not enabled? */
return;
}

/* arbitrary timeout value */
timeout = 5000;
while (ITM->PORT[portNo].u32 == 0)
{
/* Wait until STIMx is ready, then send data */
timeout--;
if (timeout == 0)
{
/* not able to send */
return;
}
}

/* send data */
ITM->PORT[portNo].u8 = c;
}


/*
* Sends a string over SWO to the host
* \param s String to send
* \param portNumber Port number, 0-31, use 0 for normal debug strings
*/
void SwoPrintString(const char *s, uint8_t portNumber)
{
while (*s != '\0')
{
SwoPrintChar(*s++, portNumber);
}
}

If I enter CCS debug mode without enable "Custom Core Trace", the log can output from SWO correctly. If I don't enter CCS debug mode, there is no output in the SWO. Can you tell me what do I miss in the SwoInit? Thanks.

Regards,

Jeffery

  • Jeffery,

    I can help you look into this some. Can you first inform me where you were referencing for your code above?

    Can you also help me understand why CCS can't be used in this instance?

    To my knowledge, we don't have a lot of active support around this use-case, but we do have this ITMLib in cTools that is lightly supported. The ITMLib provides "C" string amd binary value logging APIs for TI M3/M4 devices that includes an ITM module and supports SWD (Serial Wire Debug) with SWO (Serial Wire Output) Trace. Beyond this, i'm not sure what else to provide. Maybe if you could provide a little more about where you are referencing your code and what you intend to do, maybe we can give more guidance.

    http://processors.wiki.ti.com/index.php/CToolsLib#ITMLib

  • Evan,

    I found the code in the internet.

    Let me explain it more.

    1. I run my code in the CCS debug mode with "Custom Core Trace" enable. I can get SWO output with my code, SwoPrintString. I get SWO output in the TeraTerm.

    2. I run my code in the CCS debug mode without "Customer Core Trace" enable. I can get SWO output with my code, SwoInit and SwoPrintString. I get SWO output in the TeraTerm.

    3. I run my code without entry CCS debug mode. I can't get SWO output with my code, SwoInit and SwoPrintString. I get nothing in the TeraTerm. I also use scope to check and there is no signal in the SWO. I think I still missing few setting in the SwoInit for working without entry CCS debug mode.

    The customer thinks he can uses SWO to instead of physical UART for debug log. The HW engineer needs debug log without entry CCS debug mode. Please help me for this issue. Thanks.

    By the way, I will study CToolsLib.

    Regards,

    Jeffery

  • Evan,

    The CToolsLib can't meet my customer requirement. Because the CToolsLib needs CCS entry debug mode and XDS tool.

    Can you get the code for configuring ITM and SWO trace export that done in the CCS for reference? Thanks.

    Regards,

    Jeffery

  • Jeffery,

    I'm looking to ask around our tools team about this and will let you know what is and is not possible as soon as possible.
  • Jeffery,

    This is something we don't officially support, but I asked one of the developers for additional information and these are her comments:

    Dev team said:

    The user can use a COM port utility to view/capture the data. However, the SWO protocol also puts out header packets for data written to the ITM. So the output will have header data as well which can appear as odd characters in the terminal viewer.

    If the usage is going to be printf style character messages, then one possibility is to use ITM stimulus port 0 only for generating the trace data. The header bytes generated for writes to stimulus port 0 are usually not printable characters and do not get displayed in standard COM port utilities even though they are being received.

    Hope this helps,

    Rafael

  • Rafael,

    No, that is what I knew. Let me explain my question again.

    First step: I wrote the code for sending log to SWO. When I enter CCS debug mode with "Custom Core Trace" enabled and run my code, I can get the log from UART. I think SWO output function is correct.

    Second step: I wrote the code for enabling SWO. When I enter CCS debug mode with "Custom Core Trace" disabled and run my code, I can get the log from UART. I think I have correct code for SWO enabling. So I don't need to enable "Custom Coe Trace" in the CCS debug mode. Because I think when I enable "Custom Core Trace" in the CCS debug mode, it will enable SWO.

    Third step: I run my code without CCS. I can't get the log from UART. So I think I have miss few setting for SWO enabling and it should be done when entering CCS debug mode. Can you let me know what does it do? I can add it into my code. Thanks.

    Regards,

    Jeffery

  • Hello Jeffery

    The Auxilary COM port is setup for use by the XDS110 firmware only when you start a debug session. When a debug session is not active the COM port is disconnected from SWO Trace pin (TDO) and so you do not see any data.

    We are going to fix this in our next emulation release scheduled for Nov this year. In the meanwhile, you will need to start a debug session to be able to get SWO Trace on the COM port.

    Hope this helps.

    Regards

    Ashwini

  • Ashwini,

    I don't catch your point. I gets 2 COM ports in the Windows when I connect MSP432 launchpad. One is JTAG debug port and the other is virtual COM port. I use TeraTerm to open Virtual COM port and connect SWO of MSP432 pin to RX pin of Virtual COM port (by remove the jumps and make jump-wire as below). I also use scope the measure SWO signal. It always keep high when running my code without CCS. Can you help to review my code for enabling SWO and let me know what I have missing? Thanks.

    /*
    * Initialize the SWO trace port for debug message printing
    * \param portNumber Port bit mask to be configured
    * \param cpuCoreFreqHz CPU core clock frequency in Hz
    * \param swoSpeed SWO output bit rate in Hz
    */
    void SwoInit(uint32_t portNumber, uint32_t cpuCoreFreqHz, uint32_t swoSpeed)
    {
    /* SWOSpeed in Hz, note that cpuCoreFreqHz is expected to be match the CPU core clock */
    uint32_t swoPrescaler = (cpuCoreFreqHz / swoSpeed) - 1;

    /* enable trace in core debug */
    CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk;
    /* ITM Lock Access Register, C5ACCE55 enables more write access to Control Register 0xE00 :: 0xFFC */
    ITM->LAR = 0xC5ACCE55;
    /* "Selected PIN Protocol Register": Select which protocol to use for trace output (2: SWO NRZ, 1: SWO Manchester encoding) */
    TPI->SPPR = 0x00000002;
    /* "Async Clock Prescaler Register". Scale the baud rate of the asynchronous output */
    TPI->ACPR = swoPrescaler;
    /* ITM Trace Control Register */
    ITM->TCR = ITM_TCR_TraceBusID_Msk | ITM_TCR_SWOENA_Msk | ITM_TCR_DWTENA_Msk | ITM_TCR_SYNCENA_Msk | ITM_TCR_ITMENA_Msk;
    /* ITM Trace Privilege Register */
    ITM->TPR = ITM_TPR_PRIVMASK_Msk;
    /* ITM Trace Enable Register. Enabled tracing on stimulus ports. One bit per stimulus port. */
    ITM->TER = (1ul << portNumber);
    /* DWT_CTRL */
    DWT->CTRL = 0x400003FE;
    /* Formatter and Flush Control Register */
    TPI->FFCR = 0x00000100;
    }

    Regards,

    Jeffery

  • Hello Jeffery

    Two things here:

    1. The picture above shows a connection from TDI to XDS110 RX pin. It should be TDO to XDS110 RX pin. (SWO comes out on TDO).
    2. When a debugger session is connected, as per the CCS target configuration CCXML, the debug protocol hardware on the target is explicitly switched from 4-pin JTAG to 2-pin SWD by the debug stack (by toggling TCLK and TMS) where in the TDO pin becomes available for SWO Trace. When the debugger is disconnected, the device is switched back to 4-pin JTAG. This is why you do not see SWO Trace when the debugger is disconnected. This will also be fixed as part of our next emulation release where in the debug protocol will be kept as SWD when the debugger is disconnected making SWO Trace available in the absence of a debugger.

    Thanks
    Ashwini
  • Hi Ashwini,

    1. Yes, yu are right. I make mistake in the picture. I connect TDO to XDS110 RX pin in EVM.

    2. I want to confirm with you. Which one do you talk about 4-pin JTAG and 2-pin SWD? Is MSP432 or XDS110? If you are talking about XDS110, what happen I remove all jumps of JTAG in the EVM when the debugger is disconnected? If you are talking about MSP432, Is there any method that I can switch it from 4-pin JTAG to 2-pin SWD in the MSP432 itself?

    Regards,

    Jeffery

  • Hello Jeffery

    The 4-pin JTAG is the debug protocol that the MSP432 hardware comes up in on reset. External tools have to toggle TCLK and TMS in a specific pattern (which is what the XDS110 does) to switch the debug protocol of the MSP432 hardware to 2-pin SWD. The application cannot make this change and change has to come from external tools.

    As of now, you will need to connect via a debugger to do that.

    Thanks

    Ashwini

**Attention** This is a public forum