I'm using a tower kit with K60 MCU and configured the hw to use the USB port on TWR-SER to power the system and use as IO for MQX's 3.7.0 USB CDC example. Everything works fine with the demo code. I'd now like to redirect all printf()/stdio communication to the USB_CDC (virtual com) instead of UART (ttyf .
Checking mqx\source\bsp\twrk60n512\twrk60n512.h, the default entry BSP_DEFAULT_IO_CHANNEL defined as "ttyf:" would be my first choice to modify and redirect stdio but I have not found a valid entry to redirect to USB CDC.
Do I have to write a new BSP driver (AN3902) in order to redirect printf() to USB instead of UART or am I trying to reinvent the wheel and there is a simple solution that I overlooked? I'd prefer to keep as much portable and compatible with MQX libraries to avoid having to adapt my code with every minor MQX library release.
W.
已解决! 转到解答。
Hi,
There is the function for redirecting STDOUT, STDIN, STDERR to your driver handle _io_set_handle(...).
Usage:
<old driver handle> = _io_set_handle(IO_STDOUT, <new driver handle>);
Return value of this function is previous driver handle. You can use it latter to redirect STDOUT back.
Hi,
There is the function for redirecting STDOUT, STDIN, STDERR to your driver handle _io_set_handle(...).
Usage:
<old driver handle> = _io_set_handle(IO_STDOUT, <new driver handle>);
Return value of this function is previous driver handle. You can use it latter to redirect STDOUT back.
Where does this <new driver handle> come from in the virtual_com example?
It has a g_app_handle, but io_sethandle wants a FILE_PTR??I
<old driver handle> = _io_set_handle(IO_STDOUT, <new driver handle>);
Hello Martin,
I notice the USB DCD driver is not available in MAX3.8? The two functions in usb_dcd_poll_kn.c
_kusb_dcd_polled_read
_kusb_dcd_polled_write
are basically empty. Do you have a more complete codes?
Arrrr... thanks for pointing out the mistake, Teckna.
OK CDC is the correct term I intended to use. Do you have a driver that mimicking the UART? Virtual Comm uses application layer for the demo, but I am looking for the kernel level driver.
Please point me to the right direction, thanks.
In Freescale MQX, there is \usb\host\examples\cdc\cdc_serial example.
usb_class_cdc_install_driver() function installs USB serial device driver to the MQX I/O subsystem ("tty0:" in the example). Then from a user task, you can fopen, fread and fwrite to it.
Can you tell me how to implement io_sethandle when using a Processor Expert project?
I have been able to send serial data back throug the USB port to my workstation by selecting UART2 on the K70 TOWER.
Now I would like to redirect stdio from this project.
Can you tell me if io_sethandle() is still the proper method to achieve this?
thanks!
Hi crezyoz,
I am not familiar with Processor expert t, can't help you in that area.
io_sethandle is the function you need and the one which redirects the output as stated by BielikM.
Regards,
MartinK