TWRSER - Redirecting printf() to USB CDC (virtual com)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

TWRSER - Redirecting printf() to USB CDC (virtual com)

Jump to solution
3,144 Views
wopi
Contributor I

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:smileyhappy: .

 

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.

0 Kudos
1 Solution
1,360 Views
BielikM
Contributor III

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.

View solution in original post

0 Kudos
11 Replies
1,360 Views
F50SC
Contributor III

Did anyone work out a solution for this???

If so could you please share?

0 Kudos
1,360 Views
keithtang
Contributor IV

I am also looking for the same solution. Anyone has any updates?

0 Kudos
1,361 Views
BielikM
Contributor III

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.

0 Kudos
1,360 Views
kristies1
Contributor II

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>);

0 Kudos
1,360 Views
keithtang
Contributor IV

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?

0 Kudos
1,360 Views
Teckna
Contributor V


Hi Keith,

"DCD" stands for Device Charger Detection; maybe you wanted to write "CDC" (Communication Device Class)?

Teckna

0 Kudos
1,360 Views
keithtang
Contributor IV

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.

0 Kudos
1,360 Views
Martin_
NXP Employee
NXP Employee

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.

0 Kudos
1,360 Views
keithtang
Contributor IV

That is an application level function, it does not handle kernel level xxprintf() functions. I am a bit disappointed, as writing kernel level CDC is a nightmare to me.

0 Kudos
1,360 Views
crezyoz
Contributor IV

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!

0 Kudos
1,360 Views
c0170
Senior Contributor III

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

0 Kudos