cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling SWO for Nucleo-L452RE-P

MB.2
Associate III

I can't seem to get my L452RE-P board outputting on SWO at all in an empty project. The solder bridge is closed by default, so I don't think it is that. I'm using this code here but it doesn't seem to work at all:

void swoInit (uint32_t portMask, uint32_t cpuCoreFreqHz, uint32_t baudrate)
 
{
 
	uint32_t SWOPrescaler = (cpuCoreFreqHz / baudrate) - 1u ; // baudrate in Hz, note that cpuCoreFreqHz is expected to match the CPU core clock
 
 
 
	CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk; // Debug Exception and Monitor Control Register (DEMCR): enable trace in core debug
 
	DBGMCU->CR	= 0x00000027u ; // DBGMCU_CR : TRACE_IOEN DBG_STANDBY DBG_STOP DBG_SLEEP
 
	TPI->SPPR	= 0x00000002u ; // Selected PIN Protocol Register: Select which protocol to use for trace output (2: SWO)
 
	TPI->ACPR	= SWOPrescaler ; // Async Clock Prescaler Register: Scale the baud rate of the asynchronous output
 
	ITM->LAR	= 0xC5ACCE55u ; // ITM Lock Access Register: C5ACCE55 enables more write access to Control Register 0xE00 :: 0xFFC
 
	ITM->TCR	= 0x0001000Du ; // ITM Trace Control Register
 
	ITM->TPR	= ITM_TPR_PRIVMASK_Msk ; // ITM Trace Privilege Register: All stimulus ports
 
	ITM->TER	= portMask ; // ITM Trace Enable Register: Enabled tracing on stimulus ports. One bit per stimulus port.
 
	DWT->CTRL	= 0x400003FEu ; // Data Watchpoint and Trace Register
 
	TPI->FFCR	= 0x00000100u ; // Formatter and Flush Control Register
 
}

Based on the datasheet, this is all I should need to get it working. I'm using the default clock of the board since I haven't gotten past setting up SWO yet. Am I missing something?

2 REPLIES 2
Nikita91
Lead II

Please use the "Code snippet" button to insert code. It's easier to read.

I use this code on L4R5, It would be ok on other L4...

SWO is only available while debugging (when the debugger is connected).

MB.2
Associate III

I made a new project and pasted the same code and it seems to work now. Weird!