4 years, 9 months ago.

Can I redirect stdout and stderr to USBSerial?

Can I make data sent to stdout and stderr (e.g. the printf(...) function) directed to a USBSerial port?

I already know how to send data explicitly to USBSerial, e.g. by my_usb_serial.printf(...), my question is regarding the stdout and stderr.

(my specific MCU is NXP LPC11U35/501 in case it matters).

Thanks,

Zapta

Question relating to:

1 Answer

4 years, 9 months ago.

No you can't. But yes should be easy to add that option. For redirecting it it needs to have a name, and the constructor does not have a name argument currently. If you want to modify it yourself, you need to add in the USBSerial constructor which inherits Stream, a Stream constructor with name, now it uses the default one (so something like :Stream("USBSerial") needs to be added).

I (and you or anyone else) can add it to the official library too. There are two options: Either add it as argument that can be supplied to USBSerial, or set a standard, default name. Advantage of first option is that it allows to user more choice. However if you look at the complete list of optional USBSerial arguments it is already very long. Since you can't make more than one USBSerial anyway I am in favor of simply hardcoding it to "USBSerial".

Accepted Answer

Thanks Erik. It would be great if you will make it a standard feature.

posted by Zapta Z. 04 Mar 2015

Hi,

I am having trouble now when I use Serial pc and USBSerial because of the inherited stream in USBSerial. When I create a USBSerial with connect_blocking=false it blocks the use of pc.printf. When I remove the dependency on stream in USBSerial it seems to work fine.

posted by mina kamel 18 Jul 2015