Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768

Dependencies:   FATFileSystem

Dependents:   F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld

Fork of KL46Z-USBHost by Norimasa Okamoto

簡易USBホストライブラリです。
official-USBHostの下位互換で対応プログラムを僅かな修正で動かすことが出来ます。

Platforms

  • Nucleo F446RE
  • Nucleo F411RE
  • Nucleo F401RE
  • FRDM-K64F
  • FRDM-KL46Z
  • FRDM-KL25Z
  • LPC4088
  • LPC1768

Nucleo F446RE/F411RE/F401REのUSB接続方法

ST morphoUSB
U5V (CN10-8)VBUS (1 RED)
PA11 (CN10-14)DM  (2 WHITE)
PA12 (CN10-12)DP  (3 GREEN)
GND (CN10-20)GND (4 BLACK)

Examples

Import programF446RE-USBHostMouse_HelloWorld

USBHostMouse Hello World for ST-Nucleo-F446RE

Import programF401RE-USBHostMSD_HelloWorld

Simple USBHost MSD(USB flash drive) for Nucleo F401RE/FRDM-KL46Z test program

Import programF401RE-USBHostC270_example

Simple USBHost WebCam test program

Import programK64F_USBHostC270_example

Simple USBHost C270 example

Import programF401RE-BTstack_example

BTstack for Nucleo F401RE/FRDM-KL46Z example program

Import programUSBHostRSSI_example

Bluetooth device discovery example program.

Import programKL46Z-USBHostGPS_HelloWorld

Simple USBHost GPS Dongle Receiver for FRDM-KL46Z test program

Revision:
10:40c7f6788902
Parent:
9:7f9f64cf5ded
--- a/USBHost/USBHost.cpp	Mon Feb 03 13:00:16 2014 +0000
+++ b/USBHost/USBHost.cpp	Wed Feb 05 13:34:37 2014 +0000
@@ -23,11 +23,10 @@
 USBHost::USBHost() {
 }
 
-/* virtual */ bool USBHost::addDevice(int hub, int port, bool lowSpeed) {
+/* virtual */ bool USBHost::addDevice(USBDeviceConnected* parent, int port, bool lowSpeed) {
     USBDeviceConnected* dev = new USBDeviceConnected;
-    USBEndpoint* ep = new USBEndpoint;
-    ep->setDevice(dev);
-    dev->init(hub, port, lowSpeed);
+    USBEndpoint* ep = new USBEndpoint(dev);
+    dev->init(0, port, lowSpeed);
     dev->setAddress(0);
     dev->setEpCtl(ep);
     uint8_t desc[18];
@@ -35,6 +34,9 @@
 
     int rc = controlRead(dev, 0x80, GET_DESCRIPTOR, 1<<8, 0, desc, 8);
     USB_TEST_ASSERT(rc == USB_TYPE_OK);
+    if (rc != USB_TYPE_OK) {
+        USB_ERR("ADD DEVICE FAILD");
+    }
     USB_DBG_HEX(desc, 8);
     DeviceDescriptor* dev_desc = reinterpret_cast<DeviceDescriptor*>(desc);
     ep->setSize(dev_desc->bMaxPacketSize);
@@ -52,11 +54,11 @@
     dev->setVid(dev_desc->idVendor);
     dev->setPid(dev_desc->idProduct);
     dev->setClass(dev_desc->bDeviceClass);
-    USB_INFO("hub: %d port: %d speed: %s vid: %04x pid: %04x class: %02x addr: %d",
-        hub, port, (lowSpeed ? "low " : "full"), dev->getVid(), dev->getPid(), dev->getClass(),
+    USB_INFO("parent:%p port:%d speed:%s VID:%04x PID:%04x class:%02x addr:%d",
+        parent, port, (lowSpeed ? "low " : "full"), dev->getVid(), dev->getPid(), dev->getClass(),
         dev->getAddress());
 
-    DeviceLists.push(dev);
+    DeviceLists.push_back(dev);
 
     if (dev->getClass() == HUB_CLASS) {
         const int config = 1;
@@ -105,7 +107,7 @@
         int config = 1;
         USB_TYPE res = controlWrite(dev, 0x00, SET_CONFIGURATION, config, 0, NULL, 0);
         if (res != USB_TYPE_OK) {
-            USB_DBG("SET CONF FAILED");
+            USB_ERR("SET CONF FAILED");
             return res;
         }
         // Some devices may require this delay
@@ -155,11 +157,8 @@
                     ENDPOINT_TYPE type = (ENDPOINT_TYPE)(ep_desc->bmAttributes & 0x03);
                     ENDPOINT_DIRECTION dir = (ep_desc->bEndpointAddress & 0x80) ? IN : OUT;
                     if(pEnumerator->useEndpoint(current_intf, type, dir)) {
-                        ep = new USBEndpoint;
-                        ep->setDevice(dev);
-                        ep->setType(type);
-                        ep->setAddress(ep_desc->bEndpointAddress);
-                        ep->setSize(ep_desc->wMaxPacketSize);
+                        ep = new USBEndpoint(dev);
+                        ep->init(type, dir, ep_desc->wMaxPacketSize, ep_desc->bEndpointAddress);
                         USB_DBG("ADD USBEndpoint %p, on interf %d on device %p", ep, current_intf, dev);
                         dev->addEndpoint(current_intf, ep);
                     }
@@ -195,7 +194,6 @@
 
 USB_TYPE USBHost::bulkRead(USBDeviceConnected* dev, USBEndpoint* ep, uint8_t* buf, uint32_t len, bool blocking) {
     if (blocking == false) {
-        ep->setType(BULK_ENDPOINT);
         ep->setBuffer(buf, len);
         ep_queue.push(ep);
         return USB_TYPE_PROCESSING;
@@ -220,7 +218,6 @@
 
 USB_TYPE USBHost::interruptRead(USBDeviceConnected* dev, USBEndpoint* ep, uint8_t* buf, uint32_t len, bool blocking) {
     if (blocking == false) {
-        ep->setType(INTERRUPT_ENDPOINT);
         ep->setBuffer(buf, len);
         ep_queue.push(ep);
         return USB_TYPE_PROCESSING;
@@ -237,7 +234,6 @@
 
 USB_TYPE USBHost::isochronousRead(USBDeviceConnected* dev, USBEndpoint* ep, uint8_t* buf, uint32_t len, bool blocking) {
     if (blocking == false) {
-        ep->setType(ISOCHRONOUS_ENDPOINT);
         ep->setBuffer(buf, len);
         ep_queue.push(ep);
         return USB_TYPE_PROCESSING;