-1
\$\begingroup\$

We have a project with STM32F051 and now we need to use UART2 and the only unused pins are the pins 37 (SWCLK) and 38. I know there is another post with this topic. STM32 Using SWCLK and USART on the same PCB.

In this post Ben Voigt wrote

But you can put the pin configuration code in a conditional (if) and skip switching the pin to UART some of the time.

Now my question:

Is there any possibility to know if the device is in DEBUG mode?

I'd use this as condition to configure the UART or not. For me it's not needed to have this UART pin during debugging, it's only used in normal operation.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Have you checked the reference manual on that? \$\endgroup\$
    – Justme
    Commented Sep 22, 2022 at 6:16
  • 1
    \$\begingroup\$ if you have a debug and release build of the code, have it so the debug build does not enable the uart. \$\endgroup\$
    – Kartman
    Commented Sep 22, 2022 at 8:27

1 Answer 1

0
\$\begingroup\$

Those detection methods won't be reliable IMHO. There is quite a bit of debug registers that are not accessible from the MCU inside.

I recommend to wait a significant amount of time - at least 5-10 seconds - before switching the debug pin functions.

That allows a debugger to reliably connect to the chip after reset. Then you can set a variable in the debugger that tells your code to not switch pin functions.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks. Please can you give me an example how to do this: "Then you can set a variable in the debugger" \$\endgroup\$
    – C.ing
    Commented Sep 22, 2022 at 8:06
  • \$\begingroup\$ "I recommend to wait a significant amount of time - at least 5-10 seconds" It is a obvious nonsense. Debug mode is active from instruction the first instruction. If you want to make sure - simply connect under reset \$\endgroup\$ Commented Sep 23, 2022 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.