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


Potentional BUG inside USBSample.c

Posted by Jaroslav Fojtik on April 8, 2008

__arm void vUSB_ISR( void )


/* If there are bytes in the FIFO then we have to retrieve them here.
Ideally this would be done at the task level. However we need to clear the
RXSETUP interrupt before leaving the ISR, and this may cause the data in
the FIFO to be overwritten. Also the DIR bit has to be changed before the
RXSETUP bit is cleared (as per the SAM7 manual). */

I have found that it is a total nonsense and very dangerous to flip DIR bit inside USB_ISR.
Please never do this.
The problem occurs when data stage follows a control stage. Data stage has a same direction
and when a DIR bit is flipped, it causes total blocking of USB transfer.

The correct place for setting DIR is here:

static void prvProcessEndPoint0Interrupt( xISRStatus *pxMessage )
xRequest.usLength = pxMessage->ucFifoData[usbLENGTH_HIGH_BYTE];
xRequest.usLength <<= 8;
xRequest.usLength |= pxMessage->ucFifoData[usbLENGTH_LOW_BYTE];

/* Clear direction when neccessary. */
if (xRequest.ucReqType & 0x80)
while ( !(AT91C_BASE_UDP->UDP_CSR[0] & AT91C_UDP_DIR) );

/* Manipulate the ucRequestType and the ucRequest parameters to
generate a zero based request selection. This is just done to
break up the requests into subsections for clarity. The
alternative would be to have more huge switch statement that would
be difficult to optimise. */
switch(xRequest.ucReqType & 0x7F)

It took me a week of hard debugging. If you have further questions, please feel free to contact me.
The problem occurs only when PC emits a data stage packet on point0.

good luck

[ 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