About printf (Debugging, Serial Output)
printf
(debugging, serial output).About printf (Debugging, Serial Output)
printf Library
This is the printf()
process used within the TWENET library. For more details, please refer to TWENETmuc/printf.
PRINTF for Debugging
The PRINTF()
macro in the fsl library provided by NXP is used for debug output and is excluded from compilation during release. The TWENET library has also been adjusted to use PRINTF()
, but it doesn’t have all the features of the fsl library.
- The
PRINTF()
macro callsprintf_()
mentioned above. - Input macros like
GETCHAR()
are not supported.
With JN518x SDK 2.6.3 and 2.6.4, NewLib and NewLibNano show garbled or missing data in output and do not behave as expected (this is likely a buffering issue. RedLib does not show this problem, but it cannot be used in a mixed C/C++ project). For this reason, the PRINTF()
macro has been changed to use the printf_()
function within libTWENETmcu/printf.
SDK_DEBUGCONSOLE Definition
The behavior of the PRINTF()
in your application will change based on the value of SDK_DEBUGCONSOLE
.
Value | Description |
---|---|
0 | Output is sent to the debug console (Semihosting). This process is very slow. * To enable this output, you must set SDK_DEBUGCONSOLE=0 in the libTWENETmcu (Debug build), rebuild the library, and periodically call _putchar(-1) (approximately every 16ms) in your application code. (See SysTick_Handler() defined in the sample Samp_bare_MMAC ) |
1 | This is the setting for a Debug build. PRINTF uses the printf_ function (libTWENETmcu). If _putchar() is not redefined, SERIAL_bTxChar(0, c); is called. This is also the default setting for Debug builds of TWENETxxx libraries. |
2 | This is the setting for a Release build. PRINTF is excluded from compilation, and printf_() outputs nothing. If you want to use printf_() , you must redefine _putchar(int) . This is also the default setting for Release builds of TWENETxxx libraries. |
- The
_putchar()
in the libTWENETmcu library has a weak link specification. The_putchar()
you define in your application code will take precedence. - To enable
PRINTF()
within the TWENETxxx library, you must set the sameSDK_DEBUGCOSOLE
definition in your application and rebuild the library.
About SWO
TWENETmcu/source includes code for SWO output. While we don’t officially support this feature, here’s a breakdown of its code and functionality:
- Code related to SWO is defined with
-DDEBUG
and-DSERIAL_PORT_TYPE=1
. When these are set, thePRINTF()
output is adjusted to be sent to the SWO ITM (main/retarget_itm.c
,main/retarget_putchar.c
). - The SWO port is set to PIO14.
- Debugging often fails to start when SWO is enabled. Keeping the ISP pin (PIO5) in a LOW state until just before the debugger starts can sometimes resolve this.