VirtualSerial - Endpoint_WaitUntilReady() question

54 views
Skip to first unread message

Czigány Dániel

unread,
Oct 8, 2010, 5:23:39 PM10/8/10
to myusb-sup...@googlegroups.com
Hello!

I use usbkey with the latest revision from LUFA. I use AVRDRAGON to debug.
I use the VirtualSerial demo from Demo\Device\ClassDriver

I edited the VirtualSerial demo to constantly send a message:

#define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT))
volatile char CDC_buffer[100];

for (;;)
    {
        CheckJoystickMovement();
         
        /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */
        CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);

        sprintf_P((char *)(CDC_buffer),PSTR("LUFA Freezy Debug\n"));
        CDC_Device_SendString(&VirtualSerial_CDC_Interface, (char *)(CDC_buffer), strlen((char *)(CDC_buffer)));
        FLIPBIT(PORTD,7); //Change led on PORTD.7

        CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
        USB_USBTask();
    }

I start the program. I connect the HyperTerminal the "LUFA Freezy Debug" string is coming and the LED blinking very fast.
Then I disconnect the Hyper terminal. Then the led blink very slow, and it seems, that the program is very slow. Whan I pause then the current position of the program is in uint8_t Endpoint_WaitUntilReady(void) function in Endpoint.c.

When I change USB_STREAM_TIMEOUT_MS to 1 from 100 then it seems, that the program running fast again.

I tryid out with LUFA100807 and with same result.

Is this normal behaviour?
Can I change USB_STREAM_TIMEOUT_MS to 1? Is this correct or it is good when it is 100?
What is your advice?

LUFA is the BEST!

Best Regards!
Daniel Czigany

 

Dean Camera

unread,
Oct 18, 2010, 6:37:10 PM10/18/10
to LUFA (Formerly MyUSB) Support
Daniel,

> Then I disconnect the Hyper terminal. Then the led blink very slow, and it
> seems, that the program is very slow. Whan I pause then the current position
> of the program is in uint8_t Endpoint_WaitUntilReady(void) function in
> Endpoint.c.

This is an unfortunate side effect of the CDC class not having any way
to detect a data sink on the PC side, so that when no terminal is
listening the AVR locks up until the timeout period has elasped, as
you have found. In theory, it should be possible to use the virtual
DCD line of the port to detect an open terminal on the host side, but
the Windows drivers does not handle this correctly (although Linux
does).

Reducing the timeout period is a perfectly acceptable solution, but
keep in mind that it will also affect other code you have running that
uses the Endpoint_WaitUntilReady() function.

- Dean

Karl Palsson

unread,
Jan 27, 2011, 5:24:30 PM1/27/11
to lufa-s...@googlegroups.com, LUFA (Formerly MyUSB) Support
So, is there any other way?

I want to have two "serial" output streams from my usb device, and I don't want the AVR to sit there blocking just because no-one on the host is listening.  I want to just keep pumping data from the device to the host, and the host just joins in when someone starts the listening program on the host.

I've been using the USB HID from pjrc.com, I'm not strictly after the serial/CDC endpoint, just something that lets me have two streams of data, and the easiest one to get started with was the DualVirtualSerial example.  It works, but only when I have a listener on the host to both interfaces.

Cheers,
Karl P
Reply all
Reply to author
Forward
0 new messages