2012-06-11 04:10 AM
STM32F103RE
I'm using the 2 wire serial debug pins as GPIO under normal operating conditions, the JTAG/SW functionality gets disabled early in the main function. Obviously this would prevent debugging as the debugger disconnects as soon as the SW lines as reconfigured, so I currently check the status of another I/O pin to see whether I should reconfigure the SW pins or not. Is it possible to test (from user code) whether the STM is running under the debugger so I can automatically reconfigure these pins as required without having to set a value on another pin? #debugger #stm32 #sw #jtag2012-06-11 05:49 AM
It seems I can read the IDCODE register and it will return zero if not running under the debugger. Is this behavior reliable and/or liable to change in future silicon revisions?
2012-06-13 01:33 AM
In my test IDCODE register sometimes gets read even when no jtag is connected.
You could try checking TRCENA bit of DEMCR. I'm not sure if that is exactly what you want.2012-06-13 07:56 AM
One could always pull BOOT0 high, let the JTAG break into the system loader, a safe harbour, and then debug into the FLASH based code.
Generally putting code early in the reset path runs the risk of not being breakable before the JTAG wrestles control.2012-06-15 07:37 AM
I tried your suggestion and it didn't work but you pointed me in the right direction, so thanks! The bit that needs to be tested is the C_DEBUGEN bit in the DHCSR register. This seems to be a ''official'' way to test if running under the debugger as it is described on the ARM website:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka14536.html