Is possible in program detect connection Debug Probes on SWD, for examples J-Link or ULINK2? Why?
If Debug Probes is connected stdout on SWOUT pin If Debug Probes is not connected stdout on USART1
Check the CoreDebug_DHCSR_C_DEBUGEN_Msk bit in CoreDebug->DHCSR
stm32.kosyak.info/.../group___c_m_s_i_s___c_m3___core_debug.html
infocenter.arm.com/.../index.jsp