USB, how do I start

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

USB, how do I start

2,711 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ckrame on Sat Nov 23 07:53:14 MST 2013
Greetings,

I have a problem in using the nxpUSBlib. So before I'm going to torture you all with my, certainly stupid questions, I'd like to know, if there is a tutorial or a how to for this usb library. Of course I've gone through a lot of examples, but honestly, I didn't understand that much of how I have to set up my software to use usb correctly. So what I am looking for are documentations, book, homepages etc. to look my fundamental questions up. Of course a VERY got commented source code would be pretty cool, but that's not exactly what I am looking for. These documentations have not to be explicitly for this lib, if it's a common guide on how to use usb correctly, that would already be great.
So i know its a common asked question, but I didn't found much that I could use. If any of you know a good book or things like that, I would be very thankful.

As reference for what I'm looking for:
http://www.usbmadesimple.co.uk/

I am working with the LPCXpresso and it's baseboard (rev B). My goal is to get data out of a GPS-Mouse to track the route, velocity and all that stuff.

Christian
Labels (1)
0 Kudos
Reply
12 Replies

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ckrame on Sat Oct 25 14:22:55 MST 2014
Hi terrype,

like I said in my last post, I never did get the USB-Port working the way I wanted. I may be doing another update of my software, but I do not know when and even if I will make another attempt on using the USB-controller.
I never got to the point where the USB-Device did send me anything. I was not able to get any kind of descriptor out of that thing, so I am sorry, but I cannot help you in this regard.

I want to do an update, but I do not know yet if i am willing to do this as a Master-Project, so it could take some time until I do an update, because I am at the moment pretty busy with my Master as it is.

I do know of a few pretty good examples on how to use USB-Devices with the LPC-Xpresso and a corresponding evaluation board, but none of them worked for our problem. Maybe you will have more luck than I did.

Christian
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by terrype on Thu Oct 16 19:40:34 MST 2014
Dear Christian & Tsuneo.
I am working with LPC1769 expresso board with LPCOpen2.0.,  MY usb host msc is working fine but i cannot hot swap the external usb flash.
1. I insert a USB key and LPC1769 epresso board read text file from key
2. I remove the USB key it detect the that usb key is removed but not de_enumerated
3. Insert a new key(or same key) it detect that usb key is inserted but never enumerat
4. It ail to read text file
Any help will be apricaite

0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ckrame on Wed Dec 04 15:30:53 MST 2013
Ok, so I am going to upload the USBTrace log, but unfortunately the trace buffer overflows at line 981, because it is an unregistered version. But I thing that the control sequences should be in it, as far as I understood the log. If this is still not in there in am going to prepare the USBlyzer without the Control Read (in) transfer. As far as I know USBlyzer stops at 3323, I am not sure if that is really the end or if that the maximum log size as well. But if all that doesn't work, how do I find the URB panel manually. Do I simply select every line of the control transfer and write the values down or isn't' that enough?

Edit:
Ok I have got the two logs. However it wasn't possible to just deselect Control Read (in) in USBlyzer, I could just deselect the whole Control Read transfer. I think that this is not exactly what you wanted, but I am going to upload it anyway :D.

Christian

Edit:
Ok, my problems got solved in a different way. First thing, this problem was part of my Bachelor thesis, so I told my Prof, that the USB driver would take a fair amount of time to implement. I think that I would have been able to do that in another two or three weeks, but my Prof told me, that this problem should have been a solved in a day or two(!). A pretty serious misjudgment on his side :D (honestly I didn't believe him at first, but he meant it that way for real). So with that in mind, we are going to communicate with the GPS mouse per RS232. And that is working just fine now :D.
Still I wanted to thank you, tsuneo, for the brilliant explanations and the help.


Christian
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Fri Nov 29 14:24:09 MST 2013
I would expect USBlyzer a list of successful completion of Control transfer, in this format.
Seq        Setup packet
0027-0026  C0 01 008D 0000 0002
0029-0028  C0 01 008E 0000 0002
0031-0030  C0 01 008F 0000 0002
...


But USBlyzer shows Setup packet in URB panel, just for selected line.
No such a list comes from. We have to pick them up manualy.

Try USBTrace.

Or, we may ignore Control Read (in) transfer.
And then, the target Control transfers reduce into 20-30 lines.

In our code, these Setup packets are held in an array of Setup_packet structure.
Each Setup_packet in this array is fed to Host_CtrlSend() or Host_CtrlRecv(), one by one.
It reproduce the Control transfer sequence.

Tsuneo
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ckrame on Fri Nov 29 10:32:38 MST 2013
Thank you very much, this last post helped me A LOT. You can find the original USBlyzer-log attached to this post.
I was able to read the vendor specific interface (FFh), that means host_init und host_enumDev are working. What's missing is the control transfers, I hope that you can read more out of that.
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Fri Nov 29 05:29:34 MST 2013

Quote:
is the functions Host_init() (usbhost_lpc17xx.c) as it is compatible.



If you would customize Host_init(), these PINSELs should be.
/* P1[18] = USB_UP_LED, 01 */
/* P1[19] = /USB_PPWR, 10 */
/* P1[22] = USB_PWRD, 10 */
/* P1[27] = /USB_OVRCR, 10 */
    LPC_PINCON->PINSEL3 &= ~((3<<4) | (3<<6) | (3<<12) | (3<<22));
    LPC_PINCON->PINSEL3 |=  ((1<<4)|(2<<6) | (2<<12) | (2<<22));   // 0x00802080

USB_UP_LED supposes a LED at P1.18, which indicates USB plug-in.
The rest three mean connection to a power switch chip, like LM3526M-L
For example, refer to this schematic of Keil MCB17xx board (P4, left bottom)
http://www.keil.com/mcb1700/mcb1700-schematics.pdf

The LED and power switch are optional. If you wouldn't connect these parts, don't assign PINSEL to these functions.
But I recommend you the power switch, at least, if would often plug in/off the USB connector.


Quote:
do I have all the needed information to enumerate the gps-device correctly, because you said that you couldn't read all the information out of the first log


As I wrote in above post, enumeration sequence has a valid framework.
Host_EnumDev() does the job at all. I believe you don't need to change this routine, unless PL2303 would run out of standard.
Just the exception is this lines, which check the configuration set of the device.
    rc = MS_ParseConfiguration();    /* Parse the configuration */
    if (rc != OK) {
        PRINT_Err(rc);
        return (rc);
    }

If you don't connect any other USB device, you may do without this call.


Unfortunately, the text log also doesn't show the contents of the Control transfers..
Please post the original USBlyzer log file.


Quote:
The Linux driver was indeed helpful, because now I know what I have to do to at least initialize that thing.


The Linux driver is helpful, to decipher the control transfers. But it is just for fun, not necessarily
We can reproduce the control transfer sequence using LPC, without knowing their meaning.

The outline of your LPC code is as follows,

1) Initialization of clock, peripherals including USB host (Host_init())
2) enumeration using Host_EnumDev()
3) Put the Control transfer sequence, recorded on an array (Host_CtrlSend() / Host_CtrlRecv())
4) Poll and receive bulk IN endpoint, for each character from the GPS mouse (Host_ProcessTD())
5) Process the received characters into data.

Tsuneo
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ckrame on Thu Nov 28 06:26:57 MST 2013

Ok I'm here again. I have a few questions regarding the UsbHostLite. I looked into it and I think that I understand most of it, now, that are my questions:
    - is the functions Host_init() (usbhost_lpc17xx.c) as it is compatible.
    - do I have all the needed information to enumerate the gps-device correctly, because you said that you couldn't read all the information out of the first log

After I edited these two functions, I'm able to use the functions of usbhost_lpc17xx.c to communicate with the gps-mouse, correct?

I think that's all for now. Sorry that I have to bother you, but all the experience that I have in this regard is that I once wrote a simple kernel module for Linux. You see that I'm completely new to this. So in short: Thank you, again :d

Christian
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ckrame on Tue Nov 26 08:31:13 MST 2013
Ok, I've done another log, it's attached to this post. But first I have to thank you for all this. This usb-driver is a pretty complex topic and was really lost in all the information that I got. So I will start looking into the UsbHostLite-Project and I'm sure, that I run into new questions. The Linux driver was indeed helpful, because now I know what I have to do to at least initialize that thing. I think that I need at leat one or one and a half days to go through the sources, but I will have you updated, if I got anything new.

0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Mon Nov 25 09:46:23 MST 2013
Ah, it's a Prolific USB-serial chip, PL2303 (VID/PID = 0x067B/2303),
known by idVendor / idProduct field of Device Descriptor.

Here is a brief analysis of the log.

1) Descriptors
Looking in the config descriptor set,
This device has three endpoints (EPs),
- interrupt IN EP - address 0x81
- bulk OUT EP - 0x02
- bulk IN EP - 0x83

2) Enumeration
As of the sniffer log,
the sequence up to this line is called enumeration.
0016 Select Configuration (Set_Configuration)

But the log doesn't show all of the traffic.
The framework of enumeration is,
- bus reset
- Get_Descriptor( Device ) - for max packet size of EP0
- Set_Address
- Get_Descriptor( Device ) - full
- Get_Descriptor( Config )
- Set_Configuration
Also, host may puts many Get_Descriptor( Device/Conifig/String ).

3) Chip set up
After enumeration, many Control Transfers follow.
The host sets up the USB-serial chip for baudrate/data bits/parity/flow-control, etc.
Unfortunately, the contents of these Requests are not displayed in the HTML report.
Please post a text format of the log of this range, 0024 - 0276

4) Working
4-1) Bulk IN EP
At this line, the bulk IN EP receives 1 byte data
0254-0252 Bulk or Interrupt Transfer 01:00:83  Z
The second reception is,
0262-0255 Bulk or Interrupt Transfer 01:00:83  m

In this way, the device sends one byte by one,
Zm.1%j.41K{858Hr.

4-2) Interrupt IN EP
At this line, the first packet comes to the interrupt IN endpoint
0190-0182 Bulk or Interrupt Transfer 01:00:81
A1 20 00 00 00 00 02 00 20 06     - parity error

The next packet of this endpoint is,
0266-0193 Bulk or Interrupt Transfer 01:00:81
A1 20 00 00 00 00 02 00 10 06     - frame error

Maybe, this data could be ignored...

4-3) Bulk OUT EP
No traffic is seen on this EP


To write a host driver for this chip, this Linux code is helpfull.
http://lxr.free-electrons.com/source/drivers/usb/serial/pl2303.c

If you are working on LPCXpresso IDE, I recommend you USB Host Lite project for the start-up code,
because it's simple and easy to understand.

C:\nxp\LPCXpresso_6.1.0_164\lpcxpresso\Examples\NXP\LPC1000\LPC17xx\RDB1768cmsis2.zip
- NXP_LPC17xx_UsbHostLiteCMSIS2

Tsuneo
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ckrame on Mon Nov 25 03:27:36 MST 2013

Quote:


The nxpUSBlib has been replaced with LPCOpen.

I would strongly recommend you look at using the LPCOpen library for your device - it works much better. {I would direct you straight to the download, but you don't mention which part you are using - they are all different...)



I am truly not sure what to use :D I need the usb-lib, FreeRTOS and the cmsis (if included). I am able to use the both later ones, I am now working at the usb stuff.


Quote:
For this purpose, you should start with deciphering USB traffic between a PC and the GPS-Mouse. After all, you'll emulate this traffic using LPC. Unless you know the target well, blind approach doesn't take you anywhere.



Ok good to know :D I will do that and post the results later.


Quote:
You need USB host to drive the GPS-Mouse.
LPC1769 is the only LPCXpresso Board with USB host.



For testing purposes I have the Baseboard with the LPC1769, but later on I have to use just the LPC1769 with a custom made circuit board. It would be a little problem, if the On-Board-USB-Controller doesn't support host-mode.

Edit:
I've attached the log and the descriptor as a zip file.
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Sat Nov 23 11:03:33 MST 2013

Quote:
My goal is to get data out of a GPS-Mouse to track the route, velocity and all that stuff.


For this purpose, you should start with deciphering USB traffic between a PC and the GPS-Mouse. After all, you'll emulate this traffic using LPC. Unless you know the target well, blind approach doesn't take you anywhere.

To peek USB traffic, these USB sniffers are available,

USBlyzer (33days free trial) http://www.usblyzer.com/
USBTrace (15days free trial) http://www.sysnucleus.com/

To capture enumeration at plug in,
- Run USBlyzer, enable "Capture->Capture Hot-plugged" menu, and plug in your device.
OR
- After starting USBTrace, click the "Capture Hot Plugged Devices" menu or toolbar button and "start capture". And then, plug in your device.

After a while, when no more line appears on the log, stop capture and save the capture in a file of HTML format. The sniffer also displays Descriptors in readable format. Save the Descriptors into a file, too.
Post these files in zip, attaching to your post, so that we can discuss on the traffic.

In the interpretion of this sniffer log, you'll learn USB protocol of real device.
As the protocol reference, "USB Made Simple" on your post is a good site.
Also, refer to this "USB Nutshell" site.
Get_Descriptor, etc  http://www.beyondlogic.org/usbnutshell/usb6.shtml
Descriptors  http://www.beyondlogic.org/usbnutshell/usb5.shtml


Quote:
I am working with the LPCXpresso and it's baseboard (rev B).


You need USB host to drive the GPS-Mouse.
LPC1769 is the only LPCXpresso Board with USB host.

Tsuneo
0 Kudos
Reply

2,302 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Sat Nov 23 09:21:25 MST 2013
The nxpUSBlib has been replaced with LPCOpen.

I would strongly recommend you look at using the LPCOpen library for your device - it works much better. {I would direct you straight to the download, but you don't mention which part you are using - they are all different...)
0 Kudos
Reply