STM32CubdeIDE printing messages to UART only when in DEBUG mode
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-24 9:54 PM
Hello. I would like to print certain messages to UART only in DEBUG mode. These prints will not be necessary in release mode.
I have tried the following:
#ifdef DEBUG
printf("hello from debug \n");
#endif
And then I have built the project for both release and debug but the message is printed in both cases. How can I only get message to print in debug mode and not in release mode?
Solved! Go to Solution.
- Labels:
-
DEBUG
-
STM32CubeIDE
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-25 6:52 AM
@Piranha​ "#ifdef is, of course, the most appropriate here"
Not in this case, where DEBUG is always being defined - as either 0 or 1.
In which case I would still prefer something of the form:
#if DEBUG == 0
// whatever
#elif DEBUG == 1
// whatever else
#else
#error "DEBUG must be either 0 or 1"
#endif
so that there's no ambiguity or unexpected surprises if a value other than 0 or 1 gets used.
I did already note that it's more conventional to only define DEBUG when needed, and test with #ifdef - but OP seems to prefer having it always defined, and checking the value.
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-25 7:47 AM
Yes - for "Debug" configuration, not "Release" as seen on your screen.

- « Previous
- Next »