c - LPC1788 microcontroller intermittently not sending USB messages -


i'm developing code nxp lpc1788 microcontroller, , part of work making product based on usb-compatible. of legwork done , in general communication on usb works on can.

however, 1 of issues i've been encountering that, when producing constant output of usb messages microcontroller sent pretty close together, of these messages dropped.

i'm using custom driver wrote based on winusb receive messages on pc side, , suspected problem on receiving end of things. however, using usblyzer i'm confident problem on sending side - usblyzer logs match logs produced out of winusb_readpipe().

the lpc1788 uses usb 2.0 full speed protocol , i've confirmed information being sent , received @ around 12 mhz using probe, should be.

the device configured make use of 2 endpoints: logical endpoint 2 in , logical endpoint 2 out. both of these configured bulk transfer maximum packet size of 64 bytes.

i think messages being sent around 500-600 microseconds apart @ least (i've introduced artificial 500 delay in thread , message transmission should take lot less time that). got last week; can't check debugging tools acting up.

this usb initialisation code microcontroller:

void usbinit() {     // configure usb pins.   pinsel_configpin(0, 29, 1); // usb_d+1   pinsel_configpin(0, 30, 1); // usb_d-1   pinsel_configpin(1, 18, 1); // usb_up_led1   pinsel_configpin(2,  9, 1); // usb_connect1   pinsel_configpin(1, 30, 2); // usb_vbus     // turn on power , clock   clkpwr_configppwr(clkpwr_pconp_pcusb, enable);    pinsel_setpinmode(1, 30, pinsel_basicmode_plainout);    // set dev_clk_en , ahb_clk_en.   lpc_usb->usbclkctrl |= 0x12;    // wait until change reflected in clock status register.   while((lpc_usb->usbclkst & 0x12) != 0x12);    // enable nvic usb interrupts.   nvic_enableirq(usb_irqn);    // reset usb.   usbreset();    // set device address 0x0 , enable device & connection.   usbsetaddress(0); } 

this code used microcontroller send messages via usb:

uint32_t usb_send(uint32_t endpoint, uint8_t *pdata, uint32_t count) {   // convert form can sent using usb.     uint8_t data[usb_max_packet_size];    for(int i=0; < count; i++)   {     data[i*2] = hex[(pdata[i] >> 4)];     data[(i*2)+1] = hex[(pdata[i] & 0xf)];   }    return usbwriteendpoint(endpoint, data, count*2); }  uint32_t usbwriteendpoint(uint32_t endpoint, uint8_t *pdata, uint32_t count) {   uint32_t i;    lpc_usb->ctrl = ((endpoint & 0xf) << 2) | ctrl_wr_en;    lpc_usb->txplen = count;    for(i=0; < (count+3)/4; i++)   {     lpc_usb->txdata = *((__packed uint32_t *)pdata);     pdata += 4;   }    lpc_usb->ctrl = 0;   usbvalidateendpoint(endpoint);   return count; }  void usbvalidateendpoint(uint32_t endpoint) {   writesieendpointcommand(endpoint, cmd_valid_buf); }  void writesiecommanddata(uint32_t cmd, uint32_t data) {   lpc_usb->devintclr = ccemty_int;   lpc_usb->cmdcode = cmd;   while((lpc_usb->devintst & ccemty_int) == 0);   lpc_usb->devintclr = ccemty_int;   lpc_usb->cmdcode = data;   while((lpc_usb->devintst & ccemty_int) == 0); } 

edit

to give idea of what's happening, log file produced usb driver's receive function (the 1 usblyzer practically identical):

0000030d000d 0000010d002d0004001b0024 0000000d0fff001600310016 0000010d002d0004001f0028 0000020d00280028001b002d 0000030d0009 0000000d0fff001600310016 0000010d002d0004001f0028 0000020d00280028001b002d 0000030d0009 0000010d002d0004001f0028 0000020d00280028001b002d 0000030d0009 0000010d002d0004001f0028 0000020d00280028001b002d 0000030d0009 0000010d002d0004001f0028 0000020d00280028001b002d 0000030d0009 0000000d0fff001600310016 0000010d002d0004001f0028 0000020d00280028001b002d 0000030d0009 0000010d002d0004001f0028 

i should receiving messages in following cycle:

0000000d...    0000010d... 0000020d... 0000030d... 

you can see log of messages in cycle getting skipped.

edit 2

included below excerpts raw , filtered capture logs produced usblyzer. raw logs consist of cancelled requests because driver poll-driven , uses timeout.

raw logs:

usblyzer report  capture list  type    seq time    elapsed duration    request request details raw data    i/o c:i:e   device object   device name driver name irp status start   0001    11:09:15.413                                                 urb 0002    11:09:18.484    3.071197 s      bulk or interrupt transfer  10 bytes data   30 30 30 30 30 30 31 46...  out 01:00:02    fffffa800fc98440h   usbpdo-11   usbhub  fffffa801142fab0h    00000000  30 30 30 30 30 30 31 46 30 31                    0000001f01       urb 0003    11:09:18.484    3.071212 s      bulk or interrupt transfer  64 bytes buffer     in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h    urb 0004-0002   11:09:18.484    3.071371 s  174  bulk or interrupt transfer  10 bytes buffer     out 01:00:02    fffffa800fc98440h   usbpdo-11   usbhub  fffffa801142fab0h   success (success) urb 0005-0003   11:09:18.485    3.071586 s  374  bulk or interrupt transfer          in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   cancelled (canceled) urb 0006    11:09:18.485    3.071608 s      bulk or interrupt transfer  64 bytes buffer     in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h    urb 0007-0006   11:09:18.486    3.072582 s  974  bulk or interrupt transfer          in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   cancelled (canceled) urb 0008    11:09:18.486    3.072603 s      bulk or interrupt transfer  64 bytes buffer     in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h    urb 0009-0008   11:09:18.487    3.073598 s  996  bulk or interrupt transfer          in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   cancelled (canceled) urb 0010    11:09:18.487    3.073630 s      bulk or interrupt transfer  64 bytes buffer     in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h    urb 0011-0010   11:09:18.488    3.074601 s  970  bulk or interrupt transfer          in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   cancelled (canceled) [...] urb 2504-2501   11:09:19.734    4.320666 s  161  bulk or interrupt transfer  14 bytes buffer     out 01:00:02    fffffa800fc98440h   usbpdo-11   usbhub  fffffa800cf662d0h   success (success) urb 2505-2503   11:09:19.734    4.320785 s  192  bulk or interrupt transfer  24 bytes data   30 30 30 30 30 30 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 30 30 44 30 46 46 46 30 30 31 36  0000000d0fff0016 00000010  30 30 33 31 30 30 31 42                          0031001b         

filtered logs:

usblyzer report  capture list  type    seq time    elapsed duration    request request details raw data    i/o c:i:e   device object   device name driver name irp status urb 0004-0002   11:09:18.484    3.071371 s  174  bulk or interrupt transfer  10 bytes buffer     out 01:00:02    fffffa800fc98440h   usbpdo-11   usbhub  fffffa801142fab0h   success (success) urb 2504-2501   11:09:19.734    4.320666 s  161  bulk or interrupt transfer  14 bytes buffer     out 01:00:02    fffffa800fc98440h   usbpdo-11   usbhub  fffffa800cf662d0h   success (success) urb 2505-2503   11:09:19.734    4.320785 s  192  bulk or interrupt transfer  24 bytes data   30 30 30 30 30 30 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 30 30 44 30 46 46 46 30 30 31 36  0000000d0fff0016 00000010  30 30 33 31 30 30 31 42                          0031001b         urb 2507-2506   11:09:19.734    4.321309 s  459  bulk or interrupt transfer  24 bytes data   30 30 30 30 30 31 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 31 30 44 30 30 32 44 30 30 30 34  0000010d002d0004 00000010  30 30 31 46 30 30 32 44                          001f002d         urb 2511-2510   11:09:19.735    4.321931 s  311  bulk or interrupt transfer  24 bytes data   30 30 30 30 30 32 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 32 30 44 30 30 32 38 30 30 32 38  0000020d00280028 00000010  30 30 31 42 30 30 33 31                          001b0031         urb 2513-2512   11:09:19.735    4.322306 s  332  bulk or interrupt transfer  12 bytes data   30 30 30 30 30 33 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 33 30 44 30 30 30 44              0000030d000d     urb 2725-2724   11:09:19.840    4.426662 s  89   bulk or interrupt transfer  24 bytes data   30 30 30 30 30 30 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 30 30 44 30 46 46 46 30 30 31 36  0000000d0fff0016 00000010  30 30 33 31 30 30 31 42                          0031001b         urb 2727-2726   11:09:19.840    4.427183 s  471  bulk or interrupt transfer  24 bytes data   30 30 30 30 30 31 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 31 30 44 30 30 32 44 30 30 30 34  0000010d002d0004 00000010  30 30 31 46 30 30 32 44                          001f002d         urb 2731-2730   11:09:19.841    4.427803 s  209  bulk or interrupt transfer  24 bytes data   30 30 30 30 30 32 30 44...  in  01:00:82    fffffa800fc98440h   usbpdo-11   usbhub  fffffa8010e965a0h   success (success) 00000000  30 30 30 30 30 32 30 44 30 30 32 38 30 30 32 38  0000020d00280028 00000010  30 30 31 42 30 30 33 31                          001b0031         

do have hardware usb analyzer available? i'm not sure how usblyzer works presume still using windows usb subsystem @ lowest levels. experience windows usb subsystem has been extremely bug-riddled - 1 particular example when transferring data exact multiple of max frame size, doesn't work. i'm not saying exact problem - had different symptoms reporting - in shoes @ a) changing max amount of data transmitting end send in 1 frame it's not exact multiple of frame size, , b) getting hardware usb analyzer see on wire.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -