How do I make the CDC example (vitrual_com) blocking, and how do I do Formatted IO to it?

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

How do I make the CDC example (vitrual_com) blocking, and how do I do Formatted IO to it?

2,252 Views
Tonkabot
Contributor III
I have the MQX 3.6 CDC example (virtual_com.c) up and running on my custom board (a MCF52259). What I'd really like to do is: 1) be able to open a 'serial port' in my code so I can do formatted IO to the PC over the USB. - if it is a pipe or something instead of a serial port, that is fine, I can do sprintf() instead of printf() 2) have the 'virtual_com' task block when it is not connected, or connected but has nothing to send or receive. It is unclear to me what is the best way to go about getting there. (the Best Way will be the one that involves the fewest hours of labor)
Labels (1)
Tags (1)
0 Kudos
5 Replies

505 Views
JuroV
NXP Employee
NXP Employee

Use standard blocking functions: _taskq_suspend and _taskq_resume.

Use USB_ATTACH and USB_DETACH events.

Do not suspend task, which executes USB_ATTACH and USB_DETACH event handlers.

0 Kudos

505 Views
Tonkabot
Contributor III
Okay, that might answer how to block those tasks, but the bigger question is how can I do formatted IO to the USB CDC port. The virtual_com demo just echos any characters sent from the PC What I really would like to do is be able to do printf and scanf (or fprintf or whatever works) to my end of the CDC link. I think it would be possible for me to write a serial driver for my end of the link. But what I think would be easier is to use, for example, an io_pipe and just use something like the ANSI 'fdopen' to allow me to do formatted IO to it. But the pipe files in mqx/source/io/pipe don't seem to compile. (MQX 3.6 on my 52255 board) Can you tell me what the easiest way to get some kind of useful functionality like this would be?
0 Kudos

505 Views
JuroV
NXP Employee
NXP Employee

It is problem to use fprintf instead of printf?

In the case you want to use printf, you have to assign stdin, stdout and stderr streams to USB virtual UART. This code handles the operation:

 

   KERNEL_DATA_STRUCT_PTR kernel_data;   _GET_KERNEL_DATA(kernel_data);   kernel_data->PROCESSOR_STDIN = usb_cdc_file;   kernel_data->PROCESSOR_STDOUT = usb_cdc_file;   kernel_data->PROCESSOR_STDERR = usb_cdc_file;

 

 

 

jv

0 Kudos

505 Views
Tonkabot
Contributor III
That's exactly what I would like to do. EXCEPT, the crucial fact of knowing what 'usb_cdc_file' is the problem. Sounds like it is a pointer to FILE, but that string appears nowhere in the mqx 3.6 tree. What would be really nice is if the 'virtual_com' demo included the statements you suggest so that I can see it working. In the virtual_com demo right now, there is not anything that resembles a FILE ptr. You also realize I am doing this as a USB device, not host.
0 Kudos

505 Views
JuroV
NXP Employee
NXP Employee

CDC device example and CDC device class does not provide any interface to the file now. So you cannot do it this way unless you code your own wrapper- open / read / write functions over a file for the new wrapper-driver.

0 Kudos