AnsweredAssumed Answered

How do I get C++ iostream (std::cout) to USB serial port (UART)

Question asked by rshipman on Dec 6, 2019
Latest reply on Dec 10, 2019 by Victor Jimenez

IDE: MCUXpresso IDE v11.0.1 [Build 2563] [2019-09-01]
Platform: MIMXRT1020-evk eval board

 

What do I need to do to get std::cout and printf output to go down the USB serial UART connection please (instead of to the semihost MCUXpresso console tab)?

 

I created a fresh new C++ project (zipped and attached):

 

MCUXpresso
   File
      New
         Project...
            C/C++
               New C/C++ Project
                  evkmimxrt1020
                     Select C++ Project
                     Select UART
                     Leave everything else default.

 

Then in the main() function in source/MIMXRT1021xxxxx_Project.cpp:

 

Replace line:

 

    PRINTF("Hello World\n");

 

with:

 

    // In UART mode, PRINTF output is seen on the USB serial port (TeraTerm)
    // In semihost mode, PRINTF output is seen in the MCUXpresso Telnet Console tab.
    PRINTF("Hello World from PRINTF\r\n");

    // PROBLEM: In UART mode, printf and cout output is _not_ seen on the USB serial port (TeraTerm) or the MCUXpresso Telnet Console tab.
    // In semihost mode, printf and cout output is seen in the MCUXpresso Telnet Console tab.
    printf("Hello word from printf\r\n");
    std::cout << "Hello world from std::cout\r" << std::endl;

 

Then build and debug as normal, but:

 

MCUXpresso

   Quickstart Panel

      Quick Settings
         SDK Debug Console

            Try both Semihost console or UART console, which seem to just set SDK_DEBUGCONSOLE to 0 or 1 respectively.

 

I cannot see any output on the USB port for the printf/cout calls when in UART mode.

In semihost mode PRINTF/printf/cout output is seen in the MCUXpresso console tab.

 

FYI:
In fsl_debug_console.h:
* if SDK_DEBUGCONSOLE defined to 0,it represents select toolchain printf, scanf. <-- In this case PRINTF = printf
* if SDK_DEBUGCONSOLE defined to 1,it represents select SDK version printf, scanf. <-- In this case PRINTF = DbgConsole_Printf
* if SDK_DEBUGCONSOLE defined to 2,it represents disable debugconsole function.

 

So how do we get std::cout/printf calls to go out through the USB/UART please?
I am especially interested in std::cout although I suspect either both work or both don't.


Thanks!

Attachments

Outcomes