AnsweredAssumed Answered

Why is "printf" not working when configuring STDIO with IO_SERIAL_NON_BLOCKING flag?

Question asked by Manuel Malagon on May 30, 2019
Latest reply on Jun 17, 2019 by Daniel Chen

I'm trying to configure STDIO with the "IO_SERIAL_NON_BLOCKING" flag because I need the reception not to block waiting for X amount of characters. I have added the IO_SERIAL_NON_BLOCKING flag in the BSP_DEFAULT_IO_OPEN_MODE in the "twrk64f120m.h" file to have the configuration like this:




But if I do that printf stops working. I single stepped through the code to see what is going on and I noticed that when the line:


result = _io_doprint(stdout, _io_fputc, -1, (char *)fmt_ptr, ap);


is executed in "printf" (function "_io_printf" in file "io_pntf.c"), the function call in the macro stdout (function "_io_get_handle" in file "io_ghand.c") is returning NULL instead of _io_serial_polled_write and therefore the 1st argument of _io_doprint is NULL. And because it is null, then when the _io_fputc function is called to print one character it returns prematurely with IO_EOF instead of continuing and eventually calling _io_serial_polled_write to send the character to the UART.


Why is this happening?