Code detection when SAMD21 is debugging

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have some code that is very specific to using the swd and sdio pins as inputs. When doing debugging I am looking for a way to disable this section of code and put it "test code" so I don't get error states. I know with the avr I can read the debug mode fuse, but I cannot find anything similar in the datasheet to know when the processor is debugging from a code point of view.

 

I am looking for something that would suit this use case:

if (!Register1234.Debugging) {
    //force debug pins sdio and swclk to PORT inputs when inactive
    PORTA.PMUX[15].reg = (1 << 4 | 1);
    PORTA.PINCFG[30].bit.INEN = 1;
    PORTA.PINCFG[31].bit.INEN = 1;
    PORTA.DIRCLR.reg = (1<< 30) | (1<< 31);
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would check out the DHCSR.C_DEBUGEN bit... It should be set if a debug session is active.

The bit is described in the ARM v6m techref manual...

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You put an idea into my head, I did a bit more reading now that I knew what I was looking for in the datasheet. Turns out the SAMD21 datasheet recommends looking at the Armv5 debug interface specs. Regardless section 13.6.3.2 states that the debug presence bit is set when it is detected.

 

Thanks again!

 

if (DSU->STATUSB.bit.DBGPRES) {
	//debugging active
	Debug_SendString("Debugged detected\n");
}
else {
	Debug_SendString("No Debugger\n");
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah yes... Just remember that the DSU is a Atmel/Microchip peripheral, so it will only work on the devices that has it. All Cortex-M devices has the DHCSR as it is part of the CoreSight implementation for Cortex.

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)