I've enabled SWO output on pin P0_2 for SWO and called the following Init() method, but the SWO_WriteBuf() does not provide any output.
Can someone link me to what I may be doing wrong or an example on how to configure this?
Thanks
static inline bool SWO_WriteChar(char c, uint8_t portNo) {
volatile int timeout = 5000; /* arbitrary timeout value */
while (ITM->PORT[portNo].u32 == 0) {
/* Wait until STIMx is ready, then send data */
timeout--;
if (timeout==0) {
return false; /* not able to send */
}
}
ITM->PORT[portNo].u8 = c;
return true;
}
static void SWO_WriteBuf(char *buf, size_t count, uint8_t portNo) {
while(count>0) {
SWO_WriteChar(*buf, portNo);
buf++;
count--;
}
}
/*!
* \brief Initialize the SWO trace port for debug message printing
* \param portBits Port bit mask to be configured
* \param cpuCoreFreqHz CPU core clock frequency in Hz
*/
static void Init(uint32_t traceClockHz, uint32_t SWOSpeed, uint32_t port)
{
CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk;
if ((CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) == 0U) {
assert(false);
}
ITM->LAR = 0xC5ACCE55U; /* ITM Lock Access Register, C5ACCE55 enables more write access to Control Register 0xE00 :: 0xFFC */
ITM->TER &= ~(1UL << port); /* ITM Trace Enable Register. Enabled tracing on stimulus ports. One bit per stimulus port. Disable it */
ITM->TCR = 0U; /* ITM Trace Control Register */
TPI->SPPR = 0x2; /* "Selected PIN Protocol Register": Select which protocol to use for trace output (2: SWO NRZ (UART), 1: SWO Manchester encoding) */
SetSWOSpeed(traceClockHz, SWOSpeed); /* set baud rate with prescaler */
ITM->TPR = 0U; /* allow unprivileged access */
ITM->TCR = ITM_TCR_ITMENA_Msk | ITM_TCR_SYNCENA_Msk /* enable ITM */
#ifdef ITM_TCR_TraceBusID_Msk
| ITM_TCR_TraceBusID_Msk
#elif defined(ITM_TCR_TRACEBUSID_Msk)
| ITM_TCR_TRACEBUSID_Msk
#endif
| ITM_TCR_SWOENA_Msk | ITM_TCR_DWTENA_Msk;
ITM->TER = 1UL << port; /* enable the port bits */
}
Hello @threeboystech
For SWO function, If you use MCUXpresso IDE, I recommend you refer to <MCUXpresso IDE SWO Trace Guide>. I attach it for you. Thanks.
BR
Alice