printf() in USB CDC

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

printf() in USB CDC

Jump to solution
1,474 Views
tuowang
Contributor II

Hi,

I am writing MQX 4.1 application code for Kinetis MCU MK64FN1M0VLL12 on a custom board. I have a software task that uses USB CDC driver to communicate with a computer through USB Interface. My question is, how to send data to the PC through USB interface by using printf(). I noticed there is a thread in the forum that asked the same question.

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

Based on the correct answer in the thread, I tried to add this line of code but it didn't work:

CDC_HANDLE   g_usb_handle;

g_usb_handle = USB_Class_CDC_Init(...);

/* Add below code */

_io_set_handle(IO_STDOUT, g_usb_handle);

printf("\r\nTEST");


By calling _io_set_handle I still cannot see the string TEST printed on the TeraTerm Terminal in the PC.


Can anyone please advise what might be the reason for this?


Thanks very much!

Tuo

Labels (1)
Tags (3)
1 Solution
959 Views
soledad
NXP Employee
NXP Employee

Hello,

I believe you are using CDC device, instead of CDC Host, you need to use CDC Host to be able to redirect the output, which it is possible like it mentions the thread.

Unfortunately we don’t have an example to share with you. Could you please confirm if you are using CDC host?

Regards,

Sol

View solution in original post

0 Kudos
3 Replies
960 Views
soledad
NXP Employee
NXP Employee

Hello,

I believe you are using CDC device, instead of CDC Host, you need to use CDC Host to be able to redirect the output, which it is possible like it mentions the thread.

Unfortunately we don’t have an example to share with you. Could you please confirm if you are using CDC host?

Regards,

Sol

0 Kudos
959 Views
tuowang
Contributor II

Hi Sol,

No, I'm not using CDC host. My code is based on USB CDC Device Example in MQX 4.1 directory. Thank you for your information. Can a USB port on PC be a USB device to communicate to MCU with USB CDC host code?

Thank you!

Tuo

0 Kudos
959 Views
soledad
NXP Employee
NXP Employee

Hello Tuo,

You still having problems?

Regards

Soledad

0 Kudos