Firmware hangs in task of virtual serial interface

23 views
Skip to first unread message

zocholl

unread,
Apr 9, 2010, 4:27:16 AM4/9/10
to LUFA (Formerly MyUSB) Support
Hi Dean,

I'm developing a board with two CDC-Interfaces, an internal for
controlling the processor and an external used as serial connection.
The project is more or less based on the Demo/Device/LowLevel/
DualVirtualSerial of the LUFA 091226. Most of the time this works
fine, but sometimes the processor hangs, each time at the same
position. I attach the sourcecode of the CDC-Task of the external
serial interface. Maybe you have an idea, whats going wrong here...

void Virtual_Serial_Task(void)
{
if (USB_DeviceState != DEVICE_STATE_Configured)
return;

///////////////////////////////
// PC >>> external interface
// This part seems to be working
///////////////////////////////

///////////////////////////////
// external interface >>> PC
///////////////////////////////

// Is Data available in the ringbuffer
if (UART_Tx_Buff_Ext.Elements)
{
// Select the endpoint
Endpoint_SelectEndpoint(EPNUM_EXT_TX);

// While there is data available
while (UART_Tx_Buff_Ext.Elements)
{
// If the endpoint is full
if (!(Endpoint_IsReadWriteAllowed()))
{
// send the data...
Endpoint_ClearIN();

// and wait for the endpoint to get ready again
//
// !!! The firmware hangs in this function !!!
//
Endpoint_WaitUntilReady();
}
else
{
// stroe the next databyte in the buffer
Endpoint_Write_Byte(Buffer_GetElement(&UART_Tx_Buff_Ext));
}
}

// send the last data
Endpoint_WaitUntilReady();
Endpoint_ClearIN();

// send an empty datablock to prevent the PC from buffering
Endpoint_WaitUntilReady();
Endpoint_ClearIN();

}
}

Thanks in advance, Markus

Dean Camera

unread,
Apr 9, 2010, 11:03:18 PM4/9/10
to LUFA (Formerly MyUSB) Support
Markus,

That would indicate that the IN endpoint is never being read by the
PC, causing the code to loop forever waiting for the bank to become
free. That might happen if the host configures and opens the port, but
doesn't read data from it - what host application and operating system
are you using? One possible solution might be to just cancel the bank
after a given number of timeouts from the Endpoint_WaitUntilReady()
function, which would cause data loss, but if the host application
isn't reading it then no harm done.

- Dean

Reply all
Reply to author
Forward
0 new messages