cancel
Showing results for 
Search instead for 
Did you mean: 

ITM_SendChar blocks when no debugger attached?

infoinfo991
Associate III
Posted on August 23, 2013 at 09:39

I think ITM_SendChar is freezing my code when I don't have a debugger attached

When I do have an debugger attached, it works, and I can see my messages

But when I don't, then the code doesn't get past the printing

But the comments for this function says ''It just returns when no debugger is connected that has booked the output.''

Is the comment wrong? Is there any way I can detect whether or not a debugger is attached? I don't see any obvious bitflags under the DBG register.

#debug #swd #itm #itm
4 REPLIES 4
Posted on August 23, 2013 at 15:43

I'd be looking at Bit 0 of both SCB_DHCSR and ITM_TER to determine if the interface was up.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jpeacock2399
Associate II
Posted on August 23, 2013 at 15:52

This is how I check the ITM before sending data:

// make sure debugger attached and ITM enabled 
if( (CoreDebug->DHCSR & 1) != 1 ) return IOB_ERR_BUS; // C_DEBUGEN, debugger not attached? 
if( (CoreDebug->DEMCR & (1 << 
24
)) == 0 ) return IOB_ERR_BUSERR; // TRCENA, trace not enabled 
if( (ITM->TCR & 0x0001) == 0 ) return IOB_ERR_ALERT; // ITMENA, ITM not enabled 
port = addr & 0x1f; // extract port number 0-31 
if( (ITM->TER & (0x01 << port)) == 0 ) return IOB_ERR_RANGE; // ITM port not enabled

A JTAG has to be attached, ITM enabled and the specific port enabled. I use ITM with the SWO Viewer for execution tracing, much faster than dumping to a serial port. Jack Peacock
infoinfo991
Associate III
Posted on August 23, 2013 at 19:28

Checking C_DEBUGEN worked

I'm using a J-Link EDU with J-Link SWO Viewer

I think somebody should patch the ITM_SendChar function that's distributed with the standard library to include this check

Thanks!

Posted on August 23, 2013 at 19:52

I think somebody should patch the ITM_SendChar function that's distributed with the standard library to include this check

 

Perhaps, but I've got a more elegant solution which filters/redirects debug output on a character, string, and retargeting level depending on how I'm attached to the system.

You should probably be looking at the debugger attachment at a higher level.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..