Hi All,
I use USB composite device to generate 2 virtual COM port.
I met below issue twice during PC communicate with TM4C129.
Test:
1. Prepare one PC and one TM4C129.
2. Config TM4C129's usb driver to be a 2 virtual COM port's USB composite device. One is command port(used to send command) and the other is serial port(used to send debug message).
3. Sometimes, PC send command to TM4C129 and TM4C129 response it. And sometimes TM4C129 send command to PC and PC response it.
4. Continue do step 3 for several days.
Issue:
During my several day's test, the serial port(debug message) works normally but the command port's Tx did not work.
From debug message, the TM4C129 can receive PC's command but can not send response to PC successfully.
I use below function to send out Tx message.
uint32_t
USBBufferWrite(const tUSBBuffer *psBuffer, const uint8_t *pui8Data,
uint32_t ui32Length)
{
uint32_t ui32Space;
tUSBBufferVars *psBufVars;
//
// Check parameter validity.
//
ASSERT(psBuffer && pui8Data);
ASSERT(psBuffer->bTransmitBuffer == true);
//
// Get our workspace variables.
//
psBufVars = psBuffer->pvWorkspace;
//
// How much space is left in the buffer?
//
ui32Space = USBRingBufFree(&psBufVars->sRingBuf);
//
// How many bytes will we write?
//
ui32Length = (ui32Length > ui32Space) ? ui32Space : ui32Length;
//
// Write the data to the buffer.
//
if(ui32Length)
{
USBRingBufWrite(&psBufVars->sRingBuf, pui8Data, ui32Length);
}
//
// Try to transmit the next packet to the host.
//
ScheduleNextTransmission(psBuffer);
//
// Tell the caller how many bytes we wrote to the buffer.
//
return(ui32Length);
}
During my several days' test, the return value of the above function is less than what I expect to send.
And after that all the send commands return 0.
From PC side, before the send command return 0 happen, PC already did not receive anything which send from TM4C129.
My analysis:
It might be that the TM4C129's Tx function fail and the ui32ReadIndex did not increase.
Therefore, after several commands sending, the ring buffer will be full and USBRingBufFree(&psBufVars->sRingBuf) will return 0.
May I know if anyone meet this problem before? or is there any possible reason to cause it?