nxpUSBlib with windows WinUSB driver custom class

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

nxpUSBlib with windows WinUSB driver custom class

1,163 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wlamers on Wed Mar 06 04:20:21 MST 2013
Hello All,

There are several good examples provided with nxpUSBlib but I am curious if there is an example for a custom class when using the WInUSB drivers on a Windows PC?
Labels (1)
0 Kudos
7 Replies

1,012 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wlamers on Wed Mar 13 03:23:16 MST 2013
Hello Vitah,

Thank for your reply.

After several, quite frustating, hours of searching (USB Trace is helping...) I found out that the LPC1769 has a fixed endpoint configuration for the logical endpoints. And off course this can be read in the manual (table 185).... I assumed that every arbritrary endpoint could be used for interrupt transfers. Well the table indicates otherwise. I used EP 3 an IN and EP 2 as OUT... Stupid me. Changing the endpoint to ones that can have interrupt transfers solves everthing. All working perfect right now! BTW max packet size is limited to 64.
0 Kudos

1,011 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vitah on Tue Mar 12 21:26:43 MST 2013
Hi wlamers,

Pls try these approachs:
1 - Change Endpoint Type to Bulk and/or PollingIntervalMS to 1 for Both IN and OUT direction.

2 - Debug and set breakpoint at line ErrorCodeOut = Endpoint_Read_Stream_LE(DataStream, receivedBytes, NULL). Check the receivedBytes whether it is 4 or other number. Then change Endpoint Size to 4 for Both IN and OUT direction.

3 - instead of use
   "receivedBytes = Endpoint_BytesInEndpoint();
   if (receivedBytes >= 1){"
-> try check if all necessary bytes have been received by
   "if(Endpoint_BytesInEndpoint() >= 4){
    //also clear out inside this block
    Endpoint_ClearOUT();
   }"

0 Kudos

1,012 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wlamers on Tue Mar 12 06:29:26 MST 2013
Hello Vitah,

This is working well! Thanks!

I am still struggling with the data flow. This is what I use now:

void USBForegroundTask(void)
{
uint8_t DataStream[512];
uint8_t ErrorCodeOut;
uint8_t ErrorCodeIn;
uint16_t receivedBytes;

Endpoint_SelectEndpoint(DATA_OUT_EPNUM);
receivedBytes = Endpoint_BytesInEndpoint();
if (receivedBytes >= 1)
{
ErrorCodeOut = Endpoint_Read_Stream_LE(DataStream, receivedBytes, NULL);
if (ErrorCodeOut  != ENDPOINT_RWSTREAM_NoError)
{
                     // toggle LED
}

Endpoint_ClearOUT();


Endpoint_SelectEndpoint(DATA_IN_EPNUM);
if (Endpoint_IsINReady())
{
ErrorCodeIn = Endpoint_Write_Stream_LE(DataStream, 4, NULL);
if (ErrorCodeIn  != ENDPOINT_RWSTREAM_NoError)
{
                             // toggle LED
}

Endpoint_ClearIN();
}
}

USB_USBTask();
}

On the host side (PC with WinUSB driver and c# .NET wrapper) is have a button that sends 4 bytes to the LPC. The LPC receives those and according tot he above code should also send these same 4 bytes back to the host. Although the host only receives the data each other time (50%). The other times I get a 'The semaphore timeout period has expired' exception. Increasing the timeout period does not help. Any clue?
0 Kudos

1,012 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vitah on Tue Mar 12 01:15:11 MST 2013
wlamers,

Let try Project Device Bandwidth Test located at "applications\projects\Project_DeviceBandwidthTest".

According to your idea, the descriptor in project should be modified a little as below:
-------------------------------------
...
.VS_DataInEndpoint =
{
...
.Attributes             = (EP_TYPE_INTERRUPT  | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize           = VENDOR_SPECIFIC_IO_EPSIZE,
.PollingIntervalMS      = 0x8
},

.VS_DataOutEndpoint =
{
...
.Attributes             = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize           = VENDOR_SPECIFIC_IO_EPSIZE,
.PollingIntervalMS      = 0x8
},
...
---------------------------------------------

- Take a look at DeviceBandwidthTest.c, function USBForegroundTask(). This function will be called by SysTick_Handler every 1ms, this period can be adjusted in main. This function is created to check there is any data available in EP buffer and processes it.

- Place your communication protocol inside this function.
- To check that data is available in OUT EP buffer, use these steps:
  + Select OUT EP
    Endpoint_SelectEndpoint(VENDOR_SPECIFIC_OUT_EPNUM);
  + Get number of bytes are in buffer
    if (Endpoint_BytesInEndpoint()== USB_DATA_BUFFER_TEM_LENGTH){
  + Read and process your data
    Endpoint_Read_Stream_LE();
  + Close transfer
    Endpoint_ClearOUT();

- To transfer data to host, use these steps:
  + Select IN EP
   Endpoint_SelectEndpoint(VENDOR_SPECIFIC_IN_EPNUM);
  + Check whether there is a room for inserting new data into IN EP buffer
   if (Endpoint_IsINReady())
{
  + Push your data into FIFO
    Endpoint_Write_Stream_LE
  + Make the data ready for sending
    Endpoint_ClearIN();

Let try!
0 Kudos

1,012 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wlamers on Mon Mar 11 07:43:31 MST 2013
Hello Vitah,

No I mean adding a custom class to nxpUSBlib itself. E.g. defining the device descriptor, configuration descriptor, interface descriptor and endpoint descriptors. As well as all useful events. This shouldn't be too hard, but there is no well written (e.g. thoroughly tested and robust) example available.

The idea is to have a custom two endpoint configuration running in interrupt mode to transfer data to the host (PC) and receiving commands and data from the host.

The WinUSB drivers are quite useful for this on the host side. But this is no requirements off course. There is also a .net library that is useful too (http://winusbnet.codeplex.com)

Maybe someone has a good example available?
0 Kudos

1,012 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vitah on Mon Mar 11 03:55:22 MST 2013
Hi wlamers,

What do you mean, a tutorial for adding custom class into nxpUSBLib or starting point for writing a WinUSB driver to work with nxpUSBLib?

maybe project "Project_DeviceBandwidthTest" is what you need. Pls take a look at and if you meet any problem in installing pls post here. I'll help you.
0 Kudos

1,012 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by h11angel on Fri Mar 08 04:20:03 MST 2013
Hello,

Maybe if someone answers to this (misplaced) post, you could have an answer too.
http://www.lpcware.com/content/forum/usb-inf-requiered-projectdevicebandwidthtest-098

Regards!
0 Kudos