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