Content originally posted in LPCWare by Vladimir Khusainov on Wed Jan 18 02:21:08 MST 2012 In continuation of the topic created by Kevin Wells on 2011-12-22 (see "Thoughts on the LPC1788 uCLinux port on the Embedded Artists board"), here is how uClinux can be used to provide support for USB devices with LPC1788.
The LPC1788 MCU shares the OHCI USB Host controller IP with the LPC2478 device. There is a Linux distribution available for LPC2478 device that already has a device driver for the specific USB Host controller interface.
Port of the device driver to the LPC1788 required setting up some clocks and assigning some MCU pin functions appropriatelly but other than that the device driver just worked on the LPC1788.
Of course the Linux (uClinux) kernel provides ample driver support for various USB device so this all is available out-of-box. The Linux kernel needs to be configured with appropriate build-time options in support of required USB devices but this is a standard thing for Linux.
Here is a sample session that shows how to use a USB Flash stick with LPC1788. I ran this session on the Embedded Artists LPC1788 board with a USB Flash device preformatted on a Windows PC inserted into the USB host port of the board.
CPU : LPC178x/7x series (Cortex-M3) Freqs: SYSTICK=108MHz,EMCCLK=54MHz,PCLK=54MHz Board: EA-LPC1788 rev 1 DRAM: 32 MB Flash: 4 MB In: serial Out: serial Err: serial Net: LPC178X_MAC Hit any key to stop autoboot: 0 EA-LPC1788> </code>
I load a bootable Linux image from TFTP and run it:
<code> EA-LPC1788> ru netboot Auto-negotiation...completed. LPC178X_MAC: link UP (100/Full) Using LPC178X_MAC device TFTP from server 172.17.0.1; our IP address is 172.17.3.109 Filename 'vlad/v'. Load address: 0xa0000000 Loading: ################################################################# #################################################### done Bytes transferred = 1704032 (1a0060 hex) ## Booting kernel from Legacy Image at a0000000 ... Image Name: Linux-2.6.33-arm1 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 1703968 Bytes = 1.6 MB Load Address: a0008000 Entry Point: a0008001 Verifying Checksum ... OK Loading Kernel Image ... OK OK
Starting kernel ... </code>
Linux comes on the board showing the following messages relevant to USB:
<code> Linux version 2.6.33-arm1 (vlad@ocean.emcraft.com) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-188) ) #121 Wed Jan 18 12:19:04 MSK 2012 ... usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb ... ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver lpc178x-ohci lpc178x-ohci: LPC178x OHCI lpc178x-ohci lpc178x-ohci: new USB bus registered, assigned bus number 1 lpc178x-ohci lpc178x-ohci: irq 24, io mem 0x2008c000 usb usb1: New USB device found, idVendor=1d6b, idProduct=0001 usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1 usb usb1: Product: LPC178x OHCI usb usb1: Manufacturer: Linux 2.6.33-arm1 ohci_hcd usb usb1: SerialNumber: lpc178x-ohci hub 1-0:1.0: USB hub found hub 1-0:1.0: 2 ports detected Initializing USB Mass Storage driver... usbcore: registered new interface driver usb-storage USB Mass Storage support registered. usbcore: registered new interface driver hiddev usbcore: registered new interface driver usbhid usbhid: USB HID core driver ... usb 1-2: new full speed USB device using lpc178x-ohci and address 2 usb 1-2: New USB device found, idVendor=0dd8, idProduct=173c usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3 usb 1-2: Product: Flash Drive usb 1-2: Manufacturer: USB usb 1-2: SerialNumber: ff0aEC981700FFFF05D1 scsi0 : usb-storage 1-2:1.0 ... init started: BusyBox v1.17.0 (2012-01-18 12:15:11 MSK) ~ # scsi 0:0:0:0: Direct-Access USB Flash Drive PMAP PQ: 0 ANSI: 0 CCS sd 0:0:0:0: [sda] 3919872 512-byte logical blocks: (2.00 GB/1.86 GiB) sd 0:0:0:0: [sda] Write Protect is off sd 0:0:0:0: [sda] Assuming drive cache: write through sd 0:0:0:0: [sda] Assuming drive cache: write through sda: sda1 sd 0:0:0:0: [sda] Assuming drive cache: write through sd 0:0:0:0: [sda] Attached SCSI removable disk </code>
At this point, I create a device node for the USB Flash stick and mount it on a local directory:
<code> ~ # mknod /dev/usb b 8 1 ~ # mount /dev/usb /mnt ~ # </code>
I have some files and directories already on the disk:
<code> /mnt # ls -lt drwxr-xr-x 2 root root 32768 Jul 12 2011 Images drwxr-xr-x 2 root root 32768 Jul 12 2011 Audio /mnt # ls -lt Audio/ -rwxr-xr-x 1 root root 25099820 Nov 5 2010 Art of gardenss.wav /mnt # </code>
As a stress test of sorts, let's copy the busybox multi-tool binary to the USB disk and then run it from there:
<code> /mnt # cp /bin/busybox . /mnt # ls -lt drwxr-xr-x 2 root root 32768 Jul 12 2011 Images drwxr-xr-x 2 root root 32768 Jul 12 2011 Audio -rwxr-xr-x 1 root root 235664 Jan 1 00:09 busybox /mnt # ./busybox echo "Hello from USB disk" Hello from USB disk /mnt # </code>