Use Cases ¶
1. Application Logging Over UART ¶
This use case illustrates printf-based application logging over UART. It requires:
UART interface configured for TX (baud rate, pins, instance).
Basic STDIO initialized with the selected UART interface.
A UART terminal or viewer connected to the target port.
This is useful for early board bring-up and lightweight runtime logging in the main loop.
2. Conditional Prints ¶
This use case illustrates build-time conditional prints that keep or remove messages without modifying the application code. It requires:
A wrapper macro
PRINTF(...)defined as below.Build flag
USE_TRACE=1to enable, orUSE_TRACE=0to disable (calls are removed at preprocessing time and arguments are not evaluated).Output interface configured and
Basic STDIOinitialized when enabled.
Example:
/* Conditional print macro.
* Enable with USE_TRACE=1.
* When disabled (USE_TRACE undefined or 0), no code is generated.
*/
#if defined(USE_TRACE) && (USE_TRACE != 0)
#define PRINTF(...) printf(__VA_ARGS__)
#else
#define PRINTF(...)
#endif
This use case helps remove all runtime prints in production builds, skip argument evaluation (for better performance), reduce the flash footprint, and keep the original source readable without modifications.