Hi LPC group,
I have an unnice problem regarding the LPC 214x USB communication:
I've built a project based on the Keil MassStorage example.
The only difference: I changed the descriptor to a non-class device,
setup 7in/7out pipes (I only use 2 BULK_IN and 1 BULK_OUT, needed
this amount of declared pipes for descriptor compatibility reasons).
I've also added 1 timer interrupt, and 2 UART interrupts.
1 BULK_IN and 1 BULK_OUT are used as command bulk pipes which are
used handshaked (means every command written is answered).
In application level (non-interrupt driven, called by main loop) I
check if I received some data e.g. over UART. The UART is buffered by
a ringbuffer (ISR -> ringbuffer) and the application sends the
received data from ringbuffer->USB (calling USB_WriteEP()).
Now the problem: This works OK for several hours, but then mostly in
WrCmd() after writing CMD_CODE the while-loop waiting for CCEMTY_INT
doesn't leave, resulting in a hanging USB communication.
I've seen a hanging situation also in the USB ISR after setting
EP_INT_CLR and waiting for CDFULL_INT.
I tried to disable the USB interrupt while calling USB_WriteEP() -
same result (may be a bit better, but can't say exactly).
I also tried to send only within an USB interrupt (SOF irq), same
result too.
So my questions:
- Does anybody else have this problem ?
- What can be the reason for a non-accepted CMD_CODE or a
non-accepted write to EP_INT_CLR ?
- What to I need to take care of before calling USB_WriteEP() ?
- Is it forbidden to send by application level ?
- Is there a patch for the Keil USB stack ?
- Is there some errata about this ?
- What can I do to prevent this or what to resolve this situation ?
Thank you for your help
Gregor
LPC214x: USB hangs after some hours
Started by ●January 13, 2006
Reply by ●January 13, 20062006-01-13
Hello Gregor,
this sounds familiar to me. First of all, you should check, if the
problem is on the host or on the client side. I haven't worked with the
LPC USB, yet, but with other USB to serial converters (namely CP2102
from SiLabs and FT232 from FTDI), always with the same result. In my
case, it seems to be a problem with the OS (Win2K and WinXP), but I
haven't found any solution up to now. I have the theory, that the USB
framework driver of the OS is disabling the device due to communication
errors (the reason for them might be EMV problems). It depends on the
implementation on the host side USB driver of your device, if it handles
this correctly. I was able to reduce this disabling by filtering the USB
data lines of my device properly (putting two small caps of 47p between
D+ and GND resp. D- and GND directly at the USB connector on my board).
Karsten
gcopoix schrieb:
>Hi LPC group,
>
>I have an unnice problem regarding the LPC 214x USB communication:
>
>I've built a project based on the Keil MassStorage example.
>The only difference: I changed the descriptor to a non-class device,
>setup 7in/7out pipes (I only use 2 BULK_IN and 1 BULK_OUT, needed
>this amount of declared pipes for descriptor compatibility reasons).
>I've also added 1 timer interrupt, and 2 UART interrupts.
>
>1 BULK_IN and 1 BULK_OUT are used as command bulk pipes which are
>used handshaked (means every command written is answered).
>
>In application level (non-interrupt driven, called by main loop) I
>check if I received some data e.g. over UART. The UART is buffered by
>a ringbuffer (ISR -> ringbuffer) and the application sends the
>received data from ringbuffer->USB (calling USB_WriteEP()).
>
>Now the problem: This works OK for several hours, but then mostly in
>WrCmd() after writing CMD_CODE the while-loop waiting for CCEMTY_INT
>doesn't leave, resulting in a hanging USB communication.
>
>I've seen a hanging situation also in the USB ISR after setting
>EP_INT_CLR and waiting for CDFULL_INT.
>
>I tried to disable the USB interrupt while calling USB_WriteEP() -
>same result (may be a bit better, but can't say exactly).
>I also tried to send only within an USB interrupt (SOF irq), same
>result too.
>
>So my questions:
>- Does anybody else have this problem ?
>- What can be the reason for a non-accepted CMD_CODE or a
> non-accepted write to EP_INT_CLR ?
>- What to I need to take care of before calling USB_WriteEP() ?
>- Is it forbidden to send by application level ?
>- Is there a patch for the Keil USB stack ?
>- Is there some errata about this ?
>- What can I do to prevent this or what to resolve this situation ?
>
>Thank you for your help
>
>Gregor >
>
>Yahoo! Groups Links >
>
this sounds familiar to me. First of all, you should check, if the
problem is on the host or on the client side. I haven't worked with the
LPC USB, yet, but with other USB to serial converters (namely CP2102
from SiLabs and FT232 from FTDI), always with the same result. In my
case, it seems to be a problem with the OS (Win2K and WinXP), but I
haven't found any solution up to now. I have the theory, that the USB
framework driver of the OS is disabling the device due to communication
errors (the reason for them might be EMV problems). It depends on the
implementation on the host side USB driver of your device, if it handles
this correctly. I was able to reduce this disabling by filtering the USB
data lines of my device properly (putting two small caps of 47p between
D+ and GND resp. D- and GND directly at the USB connector on my board).
Karsten
gcopoix schrieb:
>Hi LPC group,
>
>I have an unnice problem regarding the LPC 214x USB communication:
>
>I've built a project based on the Keil MassStorage example.
>The only difference: I changed the descriptor to a non-class device,
>setup 7in/7out pipes (I only use 2 BULK_IN and 1 BULK_OUT, needed
>this amount of declared pipes for descriptor compatibility reasons).
>I've also added 1 timer interrupt, and 2 UART interrupts.
>
>1 BULK_IN and 1 BULK_OUT are used as command bulk pipes which are
>used handshaked (means every command written is answered).
>
>In application level (non-interrupt driven, called by main loop) I
>check if I received some data e.g. over UART. The UART is buffered by
>a ringbuffer (ISR -> ringbuffer) and the application sends the
>received data from ringbuffer->USB (calling USB_WriteEP()).
>
>Now the problem: This works OK for several hours, but then mostly in
>WrCmd() after writing CMD_CODE the while-loop waiting for CCEMTY_INT
>doesn't leave, resulting in a hanging USB communication.
>
>I've seen a hanging situation also in the USB ISR after setting
>EP_INT_CLR and waiting for CDFULL_INT.
>
>I tried to disable the USB interrupt while calling USB_WriteEP() -
>same result (may be a bit better, but can't say exactly).
>I also tried to send only within an USB interrupt (SOF irq), same
>result too.
>
>So my questions:
>- Does anybody else have this problem ?
>- What can be the reason for a non-accepted CMD_CODE or a
> non-accepted write to EP_INT_CLR ?
>- What to I need to take care of before calling USB_WriteEP() ?
>- Is it forbidden to send by application level ?
>- Is there a patch for the Keil USB stack ?
>- Is there some errata about this ?
>- What can I do to prevent this or what to resolve this situation ?
>
>Thank you for your help
>
>Gregor >
>
>Yahoo! Groups Links >
>
Reply by ●January 13, 20062006-01-13
Karsten Weiss ha scritto:
>Hello Gregor,
>this sounds familiar to me. First of all, you should check, if the
>problem is on the host or on the client side. I haven't worked with the
>LPC USB, yet, but with other USB to serial converters (namely CP2102
>from SiLabs and FT232 from FTDI), always with the same result. In my
>case, it seems to be a problem with the OS (Win2K and WinXP), but I
>haven't found any solution up to now. I have the theory, that the USB
>framework driver of the OS is disabling the device due to communication
>errors (the reason for them might be EMV problems). It depends on the
>implementation on the host side USB driver of your device, if it handles
>this correctly. I was able to reduce this disabling by filtering the USB
>data lines of my device properly (putting two small caps of 47p between
>D+ and GND resp. D- and GND directly at the USB connector on my board).
>
>Karsten
>
>gcopoix schrieb: A good idea when dealing with communications is to deal with
disconnection/reconnection problem. This seems to be a very old lesson
implemented also in tcp
that has a FSM to manage all communications phases.
Massimo Manca, Micron Engineering
>
>
>>Hi LPC group,
>>
>>I have an unnice problem regarding the LPC 214x USB communication:
>>
>>I've built a project based on the Keil MassStorage example.
>>The only difference: I changed the descriptor to a non-class device,
>>setup 7in/7out pipes (I only use 2 BULK_IN and 1 BULK_OUT, needed
>>this amount of declared pipes for descriptor compatibility reasons).
>>I've also added 1 timer interrupt, and 2 UART interrupts.
>>
>>1 BULK_IN and 1 BULK_OUT are used as command bulk pipes which are
>>used handshaked (means every command written is answered).
>>
>>In application level (non-interrupt driven, called by main loop) I
>>check if I received some data e.g. over UART. The UART is buffered by
>>a ringbuffer (ISR -> ringbuffer) and the application sends the
>>received data from ringbuffer->USB (calling USB_WriteEP()).
>>
>>Now the problem: This works OK for several hours, but then mostly in
>>WrCmd() after writing CMD_CODE the while-loop waiting for CCEMTY_INT
>>doesn't leave, resulting in a hanging USB communication.
>>
>>I've seen a hanging situation also in the USB ISR after setting
>>EP_INT_CLR and waiting for CDFULL_INT.
>>
>>I tried to disable the USB interrupt while calling USB_WriteEP() -
>>same result (may be a bit better, but can't say exactly).
>>I also tried to send only within an USB interrupt (SOF irq), same
>>result too.
>>
>>So my questions:
>>- Does anybody else have this problem ?
>>- What can be the reason for a non-accepted CMD_CODE or a
>> non-accepted write to EP_INT_CLR ?
>>- What to I need to take care of before calling USB_WriteEP() ?
>>- Is it forbidden to send by application level ?
>>- Is there a patch for the Keil USB stack ?
>>- Is there some errata about this ?
>>- What can I do to prevent this or what to resolve this situation ?
>>
>>Thank you for your help
>>
>>Gregor
>>
>>
>>
>>
>>
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
> >
>
>Yahoo! Groups Links >
>
----------
>Hello Gregor,
>this sounds familiar to me. First of all, you should check, if the
>problem is on the host or on the client side. I haven't worked with the
>LPC USB, yet, but with other USB to serial converters (namely CP2102
>from SiLabs and FT232 from FTDI), always with the same result. In my
>case, it seems to be a problem with the OS (Win2K and WinXP), but I
>haven't found any solution up to now. I have the theory, that the USB
>framework driver of the OS is disabling the device due to communication
>errors (the reason for them might be EMV problems). It depends on the
>implementation on the host side USB driver of your device, if it handles
>this correctly. I was able to reduce this disabling by filtering the USB
>data lines of my device properly (putting two small caps of 47p between
>D+ and GND resp. D- and GND directly at the USB connector on my board).
>
>Karsten
>
>gcopoix schrieb: A good idea when dealing with communications is to deal with
disconnection/reconnection problem. This seems to be a very old lesson
implemented also in tcp
that has a FSM to manage all communications phases.
Massimo Manca, Micron Engineering
>
>
>>Hi LPC group,
>>
>>I have an unnice problem regarding the LPC 214x USB communication:
>>
>>I've built a project based on the Keil MassStorage example.
>>The only difference: I changed the descriptor to a non-class device,
>>setup 7in/7out pipes (I only use 2 BULK_IN and 1 BULK_OUT, needed
>>this amount of declared pipes for descriptor compatibility reasons).
>>I've also added 1 timer interrupt, and 2 UART interrupts.
>>
>>1 BULK_IN and 1 BULK_OUT are used as command bulk pipes which are
>>used handshaked (means every command written is answered).
>>
>>In application level (non-interrupt driven, called by main loop) I
>>check if I received some data e.g. over UART. The UART is buffered by
>>a ringbuffer (ISR -> ringbuffer) and the application sends the
>>received data from ringbuffer->USB (calling USB_WriteEP()).
>>
>>Now the problem: This works OK for several hours, but then mostly in
>>WrCmd() after writing CMD_CODE the while-loop waiting for CCEMTY_INT
>>doesn't leave, resulting in a hanging USB communication.
>>
>>I've seen a hanging situation also in the USB ISR after setting
>>EP_INT_CLR and waiting for CDFULL_INT.
>>
>>I tried to disable the USB interrupt while calling USB_WriteEP() -
>>same result (may be a bit better, but can't say exactly).
>>I also tried to send only within an USB interrupt (SOF irq), same
>>result too.
>>
>>So my questions:
>>- Does anybody else have this problem ?
>>- What can be the reason for a non-accepted CMD_CODE or a
>> non-accepted write to EP_INT_CLR ?
>>- What to I need to take care of before calling USB_WriteEP() ?
>>- Is it forbidden to send by application level ?
>>- Is there a patch for the Keil USB stack ?
>>- Is there some errata about this ?
>>- What can I do to prevent this or what to resolve this situation ?
>>
>>Thank you for your help
>>
>>Gregor
>>
>>
>>
>>
>>
>>
>>
>>Yahoo! Groups Links
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
> >
>
>Yahoo! Groups Links >
>
----------
Reply by ●January 16, 20062006-01-16
Update to "LPC214x: USB hangs after some hours":
I went back to the original KEIL USBMEM example
(http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
it with some simple stream-io code to exclude my driver/application
(not very nice, but does the job, call this code with the USBMEM
device letter as parameter):
int main(int argc, char* argv[])
{
int iResult = 0;
char cFile[] = "C:\\Testfile.txt";
unsigned char data[1024];
if (1 == argc)
{
char dev;
printf("Device-Letter: ");
scanf("%c", &dev);
// patch device letter
cFile[0] = dev;
}
else if (2 == argc)
{
// patch device letter
cFile[0] = argv[1][0];
}
else
{
printf("USAGE: TestUSBMasStorage [C|D|E|...]\n");
iResult = 1;
}
if (0 == iResult)
{
FILE* f;
int i;
// fill buffer
for (i = 0 ; i < sizeof(data) ; i++)
data[i] = (unsigned char)(i & 0xFF);
for (i = 0 ; 0 == iResult ; i++)
{
printf("%d\r", i);
if (NULL != (f = fopen(cFile, "wb")))
{
fwrite(data, sizeof(data), 1, f);
fflush(f);
fclose(f);
_flushall();
// read/compare data
if (NULL != (f = fopen(cFile, "rb")))
{
unsigned char cmp[sizeof(data)];
if (1 != fread(cmp, sizeof(cmp), 1, f))
iResult = 2;
else if (0 != memcmp(data, cmp, sizeof(data)))
{
iResult = 6;
}
fclose(f);
_flushall();
}
else
iResult = 4;
}
else
iResult = 3;
}
}
if (0 == iResult)
printf("\nSuccess!");
else
printf("\nError: %d\n", iResult);
return iResult;
} With this stress the USBMEM device will hang within seconds.
The error looks the same I have in my own firmware, I reported the
problem (http://groups.yahoo.com/group/lpc2000/message/12316).
Has anybody solved this problem ?
Gregor
I went back to the original KEIL USBMEM example
(http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
it with some simple stream-io code to exclude my driver/application
(not very nice, but does the job, call this code with the USBMEM
device letter as parameter):
int main(int argc, char* argv[])
{
int iResult = 0;
char cFile[] = "C:\\Testfile.txt";
unsigned char data[1024];
if (1 == argc)
{
char dev;
printf("Device-Letter: ");
scanf("%c", &dev);
// patch device letter
cFile[0] = dev;
}
else if (2 == argc)
{
// patch device letter
cFile[0] = argv[1][0];
}
else
{
printf("USAGE: TestUSBMasStorage [C|D|E|...]\n");
iResult = 1;
}
if (0 == iResult)
{
FILE* f;
int i;
// fill buffer
for (i = 0 ; i < sizeof(data) ; i++)
data[i] = (unsigned char)(i & 0xFF);
for (i = 0 ; 0 == iResult ; i++)
{
printf("%d\r", i);
if (NULL != (f = fopen(cFile, "wb")))
{
fwrite(data, sizeof(data), 1, f);
fflush(f);
fclose(f);
_flushall();
// read/compare data
if (NULL != (f = fopen(cFile, "rb")))
{
unsigned char cmp[sizeof(data)];
if (1 != fread(cmp, sizeof(cmp), 1, f))
iResult = 2;
else if (0 != memcmp(data, cmp, sizeof(data)))
{
iResult = 6;
}
fclose(f);
_flushall();
}
else
iResult = 4;
}
else
iResult = 3;
}
}
if (0 == iResult)
printf("\nSuccess!");
else
printf("\nError: %d\n", iResult);
return iResult;
} With this stress the USBMEM device will hang within seconds.
The error looks the same I have in my own firmware, I reported the
problem (http://groups.yahoo.com/group/lpc2000/message/12316).
Has anybody solved this problem ?
Gregor
Reply by ●January 16, 20062006-01-16
Do you have access to a USB hardware analyzer? Have you sniffed the
traffic
for improper traffic?
Keep in mind IAR recently released a Mass Storage example. If I have time
I'll try your test code with it. Joel
for improper traffic?
Keep in mind IAR recently released a Mass Storage example. If I have time
I'll try your test code with it. Joel
Reply by ●January 16, 20062006-01-16
> I went back to the original KEIL USBMEM example
> (http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
> it with some simple stream-io code to exclude my driver/application
> (not very nice, but does the job, call this code with the USBMEM
> device letter as parameter):
I just ran your test code on IAR LPC2148 KickStart board, against the IAR
USB MassStorage example code. No problem. The refresh time of the SD card
contents is good too.
I'll let RAM disk run a while. So far it's past 20k and counting.
The Keil examples need work. Joel
> (http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
> it with some simple stream-io code to exclude my driver/application
> (not very nice, but does the job, call this code with the USBMEM
> device letter as parameter):
I just ran your test code on IAR LPC2148 KickStart board, against the IAR
USB MassStorage example code. No problem. The refresh time of the SD card
contents is good too.
I'll let RAM disk run a while. So far it's past 20k and counting.
The Keil examples need work. Joel
Reply by ●January 17, 20062006-01-17
> > I went back to the original KEIL USBMEM example
> > (http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
> > it with some simple stream-io code to exclude my driver/application
> > (not very nice, but does the job, call this code with the USBMEM
> > device letter as parameter):
>
> I just ran your test code on IAR LPC2148 KickStart board, against the IAR
> USB MassStorage example code. No problem. The refresh time of the SD
> card
> contents is good too.
>
> I'll let RAM disk run a while. So far it's past 20k and counting.
It's up to 131k and still counting, even when pasting the Keil c51v801.exe
eval software to the SD card... All 26Meg of it.
You might want to take a look at the IAR code. Joel
> > (http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
> > it with some simple stream-io code to exclude my driver/application
> > (not very nice, but does the job, call this code with the USBMEM
> > device letter as parameter):
>
> I just ran your test code on IAR LPC2148 KickStart board, against the IAR
> USB MassStorage example code. No problem. The refresh time of the SD
> card
> contents is good too.
>
> I'll let RAM disk run a while. So far it's past 20k and counting.
It's up to 131k and still counting, even when pasting the Keil c51v801.exe
eval software to the SD card... All 26Meg of it.
You might want to take a look at the IAR code. Joel
Reply by ●January 17, 20062006-01-17
--- In lpc2000@lpc2..., "Joel Winarske" <joelw@i...>
wrote:
>
> > > I went back to the original KEIL USBMEM example
> > > (http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
> > > it with some simple stream-io code to exclude my driver/application
> > > (not very nice, but does the job, call this code with the USBMEM
> > > device letter as parameter):
> >
> > I just ran your test code on IAR LPC2148 KickStart board, against
the IAR
> > USB MassStorage example code. No problem. The refresh time of the SD
> > card
> > contents is good too.
> >
> > I'll let RAM disk run a while. So far it's past 20k and counting.
>
> It's up to 131k and still counting, even when pasting the Keil
c51v801.exe
> eval software to the SD card... All 26Meg of it.
>
> You might want to take a look at the IAR code.
I just downloaded the IAR KickStart software for LPC2148 (but not the
entire KickStart package) but the only USB samples I saw there were
for the mouse function. Is there somewhere else I need to look for the
MassStorage example?
Dave >
>
> Joel
>
>
> > > I went back to the original KEIL USBMEM example
> > > (http://www.keil.com/download/files/lpc2148_usbmem.zip) and stressed
> > > it with some simple stream-io code to exclude my driver/application
> > > (not very nice, but does the job, call this code with the USBMEM
> > > device letter as parameter):
> >
> > I just ran your test code on IAR LPC2148 KickStart board, against
the IAR
> > USB MassStorage example code. No problem. The refresh time of the SD
> > card
> > contents is good too.
> >
> > I'll let RAM disk run a while. So far it's past 20k and counting.
>
> It's up to 131k and still counting, even when pasting the Keil
c51v801.exe
> eval software to the SD card... All 26Meg of it.
>
> You might want to take a look at the IAR code.
I just downloaded the IAR KickStart software for LPC2148 (but not the
entire KickStart package) but the only USB samples I saw there were
for the mouse function. Is there somewhere else I need to look for the
MassStorage example?
Dave >
>
> Joel
>
Reply by ●January 17, 20062006-01-17
Hi Dave,
I just downloaded the IAR KickStart software for LPC2148 (but not the
> entire KickStart package) but the only USB samples I saw there were
> for the mouse function. Is there somewhere else I need to look for the
> MassStorage example?
Then it must not be included in the current KickStart version. It's in the
current maintenance release for licensees.
You might want to contact your local IAR office to ask about it.. Joel
I just downloaded the IAR KickStart software for LPC2148 (but not the
> entire KickStart package) but the only USB samples I saw there were
> for the mouse function. Is there somewhere else I need to look for the
> MassStorage example?
Then it must not be included in the current KickStart version. It's in the
current maintenance release for licensees.
You might want to contact your local IAR office to ask about it.. Joel
Reply by ●January 31, 20062006-01-31
Lately, I have been scratching my head to get the LPC2148 USB device pass the USBCV test downloaded from "http://www.usb.org". Using latest Keil's USB MSC sample, v1.04, the enumeration test will fail from time to time, and program would spin in the WrCmd() or WrCmdDat() routine forever. While I was looking into the WrCmd(), WrCmdDat() and RdCmdDat() routine and ISR carefully, Keil just found one problem that could screw up the USB protocol engine. In the USB device block, the registers are located in the VPB clock domain, which requires minimum 18Mhz PCLK. in the original MSC example, PCLK uses the default value 1/4 of CCLK = 15Mhz in the startup.s. That has probably caused most of the intermitten problems in these Wr/RdCmdDat() modules. The PCLK should be set to >= 18Mhz. I think that Keil will release a new version of these example based on the fixes soon. I am just glad that I am finally able to use the latest fixes to pass all the compliance test. So, I pass around to those who had problems with the LPC2148 USB driver: Do the following steps: (1) in startup.s, set: VPBDIV_SETUP EQU 1 VPBDIV_Val EQU 0x00000001 ; PCLK is set to CCLK 60Mhz (2) In usbhw.c, modify these modules, WrCmd(), WrCmdDat(), and RdCmdDat() as below: /* * Write Command * Parameters: cmd: Command * Return Value: None */ void WrCmd (DWORD cmd) { DEV_INT_CLR = CCEMTY_INT; CMD_CODE = cmd; while ((DEV_INT_STAT & CCEMTY_INT) == 0); } /* * Write Command Data * Parameters: cmd: Command * val: Data * Return Value: None */ void WrCmdDat (DWORD cmd, DWORD val) { DEV_INT_CLR = CCEMTY_INT; CMD_CODE = cmd; while ((DEV_INT_STAT & CCEMTY_INT) == 0); DEV_INT_CLR = CCEMTY_INT; CMD_CODE = val; while ((DEV_INT_STAT & CCEMTY_INT) == 0); } /* * Read Command Data * Parameters: cmd: Command * Return Value: Data Value */ DWORD RdCmdDat (DWORD cmd) { DEV_INT_CLR = CCEMTY_INT | CDFULL_INT; CMD_CODE = cmd; while ((DEV_INT_STAT & CDFULL_INT) == 0); return (CMD_DATA); } (3) in usbhw.c, in the interrupt handler, USB_ISR(), comment out "DEV_INT_CLR = CDFULL_INT;" as seen below: ... EP_INT_CLR = 1 << n; while ((DEV_INT_STAT & CDFULL_INT) == 0); val = CMD_DATA; // DEV_INT_CLR = CDFULL_INT; if ((n & 1) == 0) { /* OUT Endpoint */ if (n == 0) { /* Control OUT Endpoint */ if (val & EP_SEL_STP) { /* Setup Packet */ if (USB_P_EP[0]) { USB_P_EP[0](USB_EVT_SETUP); continue; } } } That will probably address many intermitten problems seen in the past. Meanwhile, we are working hard to improve our documentation in the USB chapter. Regards, Tom --- In lpc2000@lpc2..., "gcopoix" <GCopoix@g...> wrote: > > Hi LPC group, > > I have an unnice problem regarding the LPC 214x USB communication: > > I've built a project based on the Keil MassStorage example. > The only difference: I changed the descriptor to a non-class device, > setup 7in/7out pipes (I only use 2 BULK_IN and 1 BULK_OUT, needed > this amount of declared pipes for descriptor compatibility reasons). > I've also added 1 timer interrupt, and 2 UART interrupts. > > 1 BULK_IN and 1 BULK_OUT are used as command bulk pipes which are > used handshaked (means every command written is answered). > > In application level (non-interrupt driven, called by main loop) I > check if I received some data e.g. over UART. The UART is buffered by > a ringbuffer (ISR -> ringbuffer) and the application sends the > received data from ringbuffer->USB (calling USB_WriteEP()). > > Now the problem: This works OK for several hours, but then mostly in > WrCmd() after writing CMD_CODE the while-loop waiting for CCEMTY_INT > doesn't leave, resulting in a hanging USB communication. > > I've seen a hanging situation also in the USB ISR after setting > EP_INT_CLR and waiting for CDFULL_INT. > > I tried to disable the USB interrupt while calling USB_WriteEP() - > same result (may be a bit better, but can't say exactly). > I also tried to send only within an USB interrupt (SOF irq), same > result too. > > So my questions: > - Does anybody else have this problem ? > - What can be the reason for a non-accepted CMD_CODE or a > non-accepted write to EP_INT_CLR ? > - What to I need to take care of before calling USB_WriteEP() ? > - Is it forbidden to send by application level ? > - Is there a patch for the Keil USB stack ? > - Is there some errata about this ? > - What can I do to prevent this or what to resolve this situation ? > > Thank you for your help > > Gregor >