How to send and receive data via usb

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

How to send and receive data via usb

3,363 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sadeghjun on Tue Sep 30 07:38:14 MST 2014
Hi everybody.
I want to send and receive data from PC to My board (MCB1700) and i need about 2Mbps speed, but i have some problem:
[color=#f00]1- I don't know witch class should i use (CDC,HID,...)?
2- don't know witch function send data from LPC1768 & witch function receive data?
3- How can i sed data too fast as 2Mbps(or faster)?[/color]


Thanks
Labels (1)
0 Kudos
10 Replies

2,611 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by r1200gs on Tue Oct 21 10:05:43 MST 2014
Well, I thought I was being as clear as I could be, but then I downloaded LPCOpen v2.10 for the embedded Artists LPC1788 board and guess what; no such example, just as you say. There are 6 'usb_lib_xxx' examples for the 1788, but there are 10 such examples for the LPC4370. And the one I'm talking about isn't in the LPC1788 support package; just the 4370 one.

So then I looked up the MCB1700 board you mention and I see its worth like $500. Way too rich for me.

I don't know what the most important part of your project is, but if getting USB working is your goal,
can I suggest you buy a pair of EA-XPR-200 boards using the LPC4370 at $24 a board from DigiKey
(one for JTAG debugger and the other for a target board; be sure and get the Embedded Artists version
as the NXP version is the same but twice the cost)? I went with the 4370 because it also has the on board
USB 2.0 High speed PHYS, but in addition it has a flash A/D that can sample at 80 megasamples a second.
The 4370 also has a USB stack in on-board ROM, which the LPC1768 doesn't appear to. I'm sure that same stack is
available for use on the MCB1700 board as a library, but I have no clue where. As I think I said before, the NXP USB documentation really sucks.
But then the only other chip I've tried USB with is the STM32 and that documentation sucks even more.

My plan is to build the Link II board (EA-XPR-200) directly into my projects as it is pretty cheap and small and has all the necessary digital
and analog I/O brought out on 50 thou connectors. The 'LabTool' device associated with the Link II is an existence proof of that,
but that software that is kind of too complicated to adapt to other things.

But still, if you get USB running on something where it is relatively simple, like the ROM USB stack, you will be a long way up a steep learning curve.

As I say, I have been having good success with the usbd_rom_libusb example on the LPC4370.
The documentation isn't great, but the code is pretty readable and simple. The ROM based USB stack seems very well written.
I have demonstrated 35 mBytes/sec up and 29 mBytes/second down using the ROM stack. I also have two independent full duplex
read/write 'sockets' operational; one for commands and the other for data. Only a couple of hundred line of code altogether.
0 Kudos

2,611 Views
vxs187
Contributor III

Hi,

I have been trying to implement USB data transfer and haven't been so successful. Could you tell me what to do and how to transfer data? 

I am running the HSADC at 80MSPS (I am not sure how to check this), further, I am transferring the data from the HSADC to the FIFO using the DMA. I want to transfer the data in the FIFO using bulk transfer USB instead of UART that I am using now. 

I do not know how to connect the microcontrollers for data transfer, neither have I worked on this before. 

It would be really helpful if you could assist me a bit on this. 

Thanks! 

Regards, 

Vish

0 Kudos

2,611 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Vish,

I would recommend to check and download LPCOpen software for LPC43xx product from here.

The LPCOpen software provides the ADC and USB example demo.

I think customer could refer [usbd_rom_bwtest] about USB module bandwidth test.

[usbd_rom_cdc_vcom]  example shows how to us USBD ROM stack to creates a virtual comm port.

Wish it helps.


Have a great day,
Mike

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

2,611 Views
vxs187
Contributor III

Hi! 

Thanks for the reply. I have used the example to find that the code does compile but I am not able to get the connection done. If you could refer the example: 

#include "board.h"
#include <stdio.h>
#include <string.h>
#include "libusbdev.h"

/* The size of the packet buffer. */
#define PACKET_BUFFER_SIZE 4096

/* Application defined LUSB interrupt status */
#define LUSB_DATA_PENDING _BIT(0)

/* Packet buffer for processing */
static uint8_t g_rxBuff[PACKET_BUFFER_SIZE];

int main(void)
{
   /* Initialize board and chip */
   SystemCoreClockUpdate();
   Board_Init();

   /* Init USB subsystem and LibUSBDevice */
   libusbdev_init(USB_STACK_MEM_BASE, USB_STACK_MEM_SIZE);

   while (1) {
      /* wait until host is connected */
      while (libusbdev_Connected() == 0) {
         /* Sleep until next IRQ happens */        ----------->  The code keeps staying here. The usb never gets connected. 
         __WFI();
      }

      while (libusbdev_Connected()) {

         if (libusbdev_QueueReadDone() != -1) {

            /* Dummy process read data ......*/
            /* requeue read request */
            libusbdev_QueueReadReq(g_rxBuff, PACKET_BUFFER_SIZE);
         }

         if (libusbdev_QueueSendDone() == 0) {
            /* Queue send request */
            libusbdev_QueueSendReq(g_rxBuff, PACKET_BUFFER_SIZE);
         }
      }
   }
}

If you could give a step by step explanation of what to do, it would be very helpful for a lot of people like me. 

0 Kudos

2,611 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

Could you guide me which LPCOpen software package you are using?

And which USB example you are referring? Thanks.

best regards,

Mike

0 Kudos

2,611 Views
vxs187
Contributor III

I am using the usbd_rom_libusb example, the code I pasted was for the lpc4370 device, from the libusbdev_main.c program. 

-Vish

0 Kudos

2,611 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Vish,

Thank you for the info.

I checked you submitted a new thread about this issue.

Please check our support from here. Thanks.

best regards,

Mike

0 Kudos

2,611 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sadeghjun on Tue Oct 21 06:31:03 MST 2014
thank's a lot for your reply
I can't find that example ,can you upload that?
0 Kudos

2,611 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by r1200gs on Mon Oct 20 17:32:41 MST 2014
Look at the 'usbd_rom_libusb' example in the lpcopen-platform (http://www.lpcware.com/content/nxpfile/lpcopen-platform) and get libusb from http://www.libusb.org. In the example the file 'libusbdev.c' provides and interface to the on-board ROM USB stack. These two pieces are what you need.

You can expect 20-30 mBytes/sec performance (that's with a LPC 4370 on a Link II board). The documentation for the USB stack is largely useless, but knowing that the ROM USB stack is the one to use, that the file libusbdev.c  provides usage examples and that libusb is the right thing to use on the host (Mac, Linux and Windows), reduces the problem substantially.

This approach does not use any of the CDC/HID/... profiles, just direct I/O.

There are 6 endpoints in the ROM USB stack. I have mine set up as a pair of bulk endpoints, a pair of interrupt endpoints and the control connection on endpoint 0. I can type commands through the interrupt endpoints while simultaneously transferring data on the bulk endpoints.
0 Kudos

2,611 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by r1200gs on Mon Oct 20 17:15:57 MST 2014
Find the 'usbd_rom_libusb' example in the  LPCOpen-platform code (http://www.lpcware.com/content/nxpfile/lpcopen-platform). The libusbdev.c file interfaces to the ROM based USB stack (the ROM documentation is largely useless, but the file itself gives useful examples). Get libusb from http://www.libusb.org. A big part of the problem is solved by knowing only to look at these two things. You can expect 20-30 mBytes speed with the example code (that is with an LPC4370 in the Link II board). Be aware that there is a limit of 6 endpoints in the ROM.

The libusbdev.c does not use any of the CDC,HID, etc profiles. It just uses the raw interface.
0 Kudos