Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

lwIPDemo_Rowley_ARM7 - USB CDC send problem

Posted by h-mike on January 9, 2011
Hello there,

I'm working on a project based on the lwIPDemo_Rowley_ARM7 project. I needed to implement a CDC device which receives commands via USB and sends responses corresponding to the received commands. The basic functionality of the usbCDCTask() is still the same as in the original demo and basically data transfer works.

But I noticed some strange behaviour recently: After a few incoming requests (the EP1 FDR is read 30 times, most requests are somewhere between 64 and 128 bytes in length) and sending responses (the EP2 FDR is written 34 times), the next IN transfer does not take place. The 35th time the EP2 FDR is written and TXPTREADY is set, the data seems not to arrive at the host, although later the TXPKTREADY bit is cleared (which indicates, that the device received an IN token and all data was sent to the host). But in the usbSniff-Logs the package was nowhere to be found and the communication software on the host did not receive any response at all. Since the application on the microcontroller should only really send anything if a request was made, the communication between host and device hangs there.

After a bit of experimenting I found out, that if I set TXPKTREADY in every iteration of the task loop after it was reset, the data will be sent eventually, but this seems like an ugly hack. Does anyone have an idea what the problem could be? The relevant part of the code from the USB task is the following:

if (eDriverState == eREADY_TO_SEND && ucControlLineState && eApplicationMode != eEMAC) {
// All EPs have been set up and the ControlLineState is active.
if (!(AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] & AT91C_UDP_TXPKTRDY)) {
if (xSendQueueData.ulByteCount || xQueuePeek(xParserSendQueue, &xSendQueueData, 0)) {
/* There is no unsent buffered data & Got some bytes to transmit. */
vUsartPrintf("(send %p) ==============>>\n", xSendQueueData.sBuffer);
for (ulByte = 0; ulByte < usbDATA_ENDPOINT_SIZE && xSendQueueData.ulByteCount; ulByte++) {
AT91C_BASE_UDP->UDP_FDR[usbEND_POINT_2] = *(xSendQueueData.sBuffer);
//if (xSendQueueData.xAddress != eAddrBinary) {
//vUsartPutChar(*(xSendQueueData.sBuffer));
//}
xSendQueueData.sBuffer++;
xSendQueueData.ulByteCount--;
}
//vUsartPutChar('\n');

if (!xSendQueueData.ulByteCount) {
/* Packet completely transferred, remove item from queue and clear QueueData */
vUsartPuts("Packet completely transferred\n");
xQueueReceive(xParserSendQueue, &xSendQueueData, 0);
xSendQueueData.sBuffer = 0;
xSendQueueData.ulByteCount = 0;
}
}
// For some reason the endpoint has to be marked ready anyway, if not a packet may not be transferred
// at some point...
AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] |= AT91C_UDP_TXPKTRDY;
}

RE: lwIPDemo_Rowley_ARM7 - USB CDC send problem

Posted by h-mike on January 9, 2011
Sorry for the malformed code, here it is again, this time hopefully a bit more readable...

if (eDriverState == eREADY_TO_SEND && ucControlLineState && eApplicationMode != eEMAC) {
// All EPs have been set up and the ControlLineState is active.
if (!(AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] & AT91C_UDP_TXPKTRDY)) {
if (xSendQueueData.ulByteCount || xQueuePeek(xParserSendQueue, &xSendQueueData, 0)) {
/* There is no unsent buffered data & Got some bytes to transmit. */
vUsartPrintf("(send %p) ==============>>\n", xSendQueueData.sBuffer);
for (ulByte = 0; ulByte < usbDATA_ENDPOINT_SIZE && xSendQueueData.ulByteCount; ulByte++) {
AT91C_BASE_UDP->UDP_FDR[usbEND_POINT_2] = *(xSendQueueData.sBuffer);
//if (xSendQueueData.xAddress != eAddrBinary) {
//vUsartPutChar(*(xSendQueueData.sBuffer));
//}
xSendQueueData.sBuffer++;
xSendQueueData.ulByteCount--;
}
//vUsartPutChar('\n');

if (!xSendQueueData.ulByteCount) {
/* Packet completely transferred, remove item from queue and clear QueueData */
vUsartPuts("Packet completely transferred\n");
xQueueReceive(xParserSendQueue, &xSendQueueData, 0);
xSendQueueData.sBuffer = 0;
xSendQueueData.ulByteCount = 0;
}
}
// For some reason the endpoint has to be marked ready anyway, if not a packet may not be transferred
// at some point...
AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] |= AT91C_UDP_TXPKTRDY;
}
...
}

RE: lwIPDemo_Rowley_ARM7 - USB CDC send problem

Posted by h-mike on January 9, 2011
Just to clarify: the problem I described occurs when the last instruction
AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] |= AT91C_UDP_TXPKTRDY; 

is inside the if clause right before the last curly bracket. Like this:
                xSendQueueData.ulByteCount = 0;
}
AT91C_BASE_UDP->UDP_CSR[usbEND_POINT_2] |= AT91C_UDP_TXPKTRDY;
}
}
...
}

The snipped I posted first actually works, but indicates available data even if there actually should be no data available because it should already have been transferred to the host...


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists