SAM7X USB write sometimes takes long time

Discussion about SAM7 Series and ARM7TDMI based products.

Moderator: nferre

my_abousamra
Posts: 1
Joined: Tue Aug 22, 2017 2:33 pm

SAM7X USB write sometimes takes long time

Tue Aug 22, 2017 3:09 pm

Hi,

I'm using SAM7X microcontroller and Atmel device drivers, when I try to write data to USB (CDC driver) sometimes it takes relatively long time (1~2 seconds) which affects CPU load of my application, I tried to check the exact step I found 2 steps that It sometimes waits for transmission to complete for a long time (TXCOMP), as shown in code

Code: Select all

//*----------------------------------------------------------------------------
//* \fn    AT91F_CDC_Write
//* \brief Send through endpoint 2
//*----------------------------------------------------------------------------
static uint AT91F_UDP_Write( AT91PS_CDC pCdc, const char *pData, uint length )
{
    AT91PS_UDP pUdp = pCdc->pUdp;
    uint cpt = 0;

    // Send the first packet
    cpt = MIN( length, AT91C_EP_IN_SIZE );
    length -= cpt;
    while( cpt-- ) pUdp->UDP_FDR[AT91C_EP_IN] = *pData++;
    pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;

    while( length )
    {
        // Fill the second bank
        cpt = MIN( length, AT91C_EP_IN_SIZE );
        length -= cpt;
        while( cpt-- ) pUdp->UDP_FDR[AT91C_EP_IN] = *pData++;
        // Wait for the the first bank to be sent

        while( !( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP ) )		// ISSUE: sometimes, it takes a long time to complete transmission
        	if( !AT91F_UDP_IsConfigured( pCdc ) ) return length;

        pUdp->UDP_CSR[AT91C_EP_IN] &= ~( AT91C_UDP_TXCOMP );

        while( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP );

        pUdp->UDP_CSR[AT91C_EP_IN] |= AT91C_UDP_TXPKTRDY;
    }
    // Wait for the end of transfer

    while( !( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP ) )		// ISSUE: sometimes, it takes a long time to complete transmission
    	if( !AT91F_UDP_IsConfigured( pCdc ) ) return length;

    pUdp->UDP_CSR[AT91C_EP_IN] &= ~( AT91C_UDP_TXCOMP );

    while( pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP );

    return length;
}
I don't know why it takes such long time every now and then and how to overcome it.
Notes
- I'm not familiar with USB driver internals.
- I communicate with a windows 7 machine and libusb-win32 (v1.2.6.0) library

Thanks

Return to “SAM7 ARM7TDMI MCU”

Who is online

Users browsing this forum: No registered users and 4 guests