USB Host

20 Jan 2010

I've seen some people going at NXP's USBHostLite example (Igor:, but nobody reported success.

I also took a stab at it on my mbed LPC1768. So far I got pretty far - I can mount a flash drive and run the Main_Copy() successfully. However, the resulting file cannot be read by Windows, though it shows up in the directory with appropriate length.

I think there's something wrong with the FAT implementation in usbhost_fat.c from NXP example. I have two options: 1) fix NXP code, and 2) use mbed's FAT implementation (

I wanted to get others's opinion / experience...

  • Did anyone have NXP code work properly?
  • What would it take to hook FATFileSystem to UsbHostLite code?
21 Jan 2010 . Edited: 21 Jan 2010

Hmm, have you used my code or something else? How did you set things up circuit-wise?

21 Jan 2010

It should be fairly easy to plumb it in to the mbed FATFileSystem to get something working (that was the idea anyway!); you just need to implement the block access commands for your target storage (in your case USBHost).

If you take a look at, the code there is doing the same for an SD card block access; you just want to do the analogous thing for USB (i.e. derive from FATFileSystem and implement disk_initialize(), disk_write() etc; the blocks are assumed to be 512 bytes).

Hope that helps give you one option,


21 Jan 2010 . Edited: 21 Jan 2010


Thanks for the pointer, I will take a look at "sdcards" program. I played with it before, and got HTTP server reading HTML files from micro-SD card. I like FATFileSystem approach more than NXP's. Looks like FATFileSystem provides nice glue for posix file functions, while NXP's has weird file read and write functions. Hope to have enough time to get to it soon.


Igor Skochinsky wrote:

Hmm, have you used my code or something else? How did you set things up circuit-wise?

Hi Igor,

I made a margarita from your code and NXP's LPC1768 example. Here's my program in its current state: pub_UsbHost (FAT is not writing properly).

Wiring is straightforward: I wired a 4-pin type-A connector, 1=VCC - to VU pin, 2=D- to D- pin, 3=D+ to D+ pin, and 4=GND to GND pin. I run MBED connected to mini-USB, which gives it 5V that gets through to the VU pin.

I hope that helps. Are you panning to attack the FATFileSystem if the code works for you? I won't have time to work on that in the next few days.

21 Jan 2010

Thanks, I'll try and see tomorrow. If it works, I'll try to integrate it with FATFileSystem.

28 Jan 2010

This looks great, I have this compiled here and will test it out with a mass storage device tomorrow (forgot my USB device today).

Would it be possible to use this same method to hook up a USB keyboard to the mbed?

29 Jan 2010

Well, the same program won't work, since it only implements functionality necessary for mass storage devices. In particular, I think it only handles bulk transfers, and keyboard class will need interrupts, not speaking about all the rest of code to handle parsing descriptors, etc.

I'm planning to try adding support for other USB devices, we'll see how it goes.

27 Jun 2011

Igor, does your program work through a USB hub? Thanks.