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

Committer:
va009039
Date:
Tue Jan 28 06:50:12 2014 +0000
Revision:
7:9a20482c9a7a
Child:
8:6463cd1964c0
Control transfer status stage must set DATA1.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 7:9a20482c9a7a 1 // Simple USBHost for FRDM-KL46Z
va009039 7:9a20482c9a7a 2 #pragma once
va009039 7:9a20482c9a7a 3 #include "mbed.h"
va009039 7:9a20482c9a7a 4 #include "USBHALHost.h"
va009039 7:9a20482c9a7a 5 #include "USBDeviceConnected.h"
va009039 7:9a20482c9a7a 6 #include "USBEndpoint.h"
va009039 7:9a20482c9a7a 7
va009039 7:9a20482c9a7a 8 class IUSBEnumerator {}; // dummy
va009039 7:9a20482c9a7a 9
va009039 7:9a20482c9a7a 10 class USBHost : public USBHALHost {
va009039 7:9a20482c9a7a 11 public:
va009039 7:9a20482c9a7a 12 /**
va009039 7:9a20482c9a7a 13 * Static method to create or retrieve the single USBHost instance
va009039 7:9a20482c9a7a 14 */
va009039 7:9a20482c9a7a 15 static USBHost* getHostInst();
va009039 7:9a20482c9a7a 16
va009039 7:9a20482c9a7a 17 /**
va009039 7:9a20482c9a7a 18 * Control read: setup stage, data stage and status stage
va009039 7:9a20482c9a7a 19 *
va009039 7:9a20482c9a7a 20 * @param dev the control read will be done for this device
va009039 7:9a20482c9a7a 21 * @param requestType request type
va009039 7:9a20482c9a7a 22 * @param request request
va009039 7:9a20482c9a7a 23 * @param value value
va009039 7:9a20482c9a7a 24 * @param index index
va009039 7:9a20482c9a7a 25 * @param buf pointer on a buffer where will be store the data received
va009039 7:9a20482c9a7a 26 * @param len length of the transfer
va009039 7:9a20482c9a7a 27 *
va009039 7:9a20482c9a7a 28 * @returns status of the control read
va009039 7:9a20482c9a7a 29 */
va009039 7:9a20482c9a7a 30 USB_TYPE controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len);
va009039 7:9a20482c9a7a 31
va009039 7:9a20482c9a7a 32 /**
va009039 7:9a20482c9a7a 33 * Control write: setup stage, data stage and status stage
va009039 7:9a20482c9a7a 34 *
va009039 7:9a20482c9a7a 35 * @param dev the control write will be done for this device
va009039 7:9a20482c9a7a 36 * @param requestType request type
va009039 7:9a20482c9a7a 37 * @param request request
va009039 7:9a20482c9a7a 38 * @param value value
va009039 7:9a20482c9a7a 39 * @param index index
va009039 7:9a20482c9a7a 40 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 41 * @param len length of the transfer
va009039 7:9a20482c9a7a 42 *
va009039 7:9a20482c9a7a 43 * @returns status of the control write
va009039 7:9a20482c9a7a 44 */
va009039 7:9a20482c9a7a 45 USB_TYPE controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len);
va009039 7:9a20482c9a7a 46 /**
va009039 7:9a20482c9a7a 47 * Bulk read
va009039 7:9a20482c9a7a 48 *
va009039 7:9a20482c9a7a 49 * @param dev the bulk transfer will be done for this device
va009039 7:9a20482c9a7a 50 * @param ep USBEndpoint which will be used to read a packet
va009039 7:9a20482c9a7a 51 * @param buf pointer on a buffer where will be store the data received
va009039 7:9a20482c9a7a 52 * @param len length of the transfer
va009039 7:9a20482c9a7a 53 * @param blocking if true, the read is blocking (wait for completion)
va009039 7:9a20482c9a7a 54 *
va009039 7:9a20482c9a7a 55 * @returns status of the bulk read
va009039 7:9a20482c9a7a 56 */
va009039 7:9a20482c9a7a 57 USB_TYPE bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 58
va009039 7:9a20482c9a7a 59 /**
va009039 7:9a20482c9a7a 60 * Bulk write
va009039 7:9a20482c9a7a 61 *
va009039 7:9a20482c9a7a 62 * @param dev the bulk transfer will be done for this device
va009039 7:9a20482c9a7a 63 * @param ep USBEndpoint which will be used to write a packet
va009039 7:9a20482c9a7a 64 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 65 * @param len length of the transfer
va009039 7:9a20482c9a7a 66 * @param blocking if true, the write is blocking (wait for completion)
va009039 7:9a20482c9a7a 67 *
va009039 7:9a20482c9a7a 68 * @returns status of the bulk write
va009039 7:9a20482c9a7a 69 */
va009039 7:9a20482c9a7a 70 USB_TYPE bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 71
va009039 7:9a20482c9a7a 72 /**
va009039 7:9a20482c9a7a 73 * Interrupt read
va009039 7:9a20482c9a7a 74 *
va009039 7:9a20482c9a7a 75 * @param dev the interrupt transfer will be done for this device
va009039 7:9a20482c9a7a 76 * @param ep USBEndpoint which will be used to write a packet
va009039 7:9a20482c9a7a 77 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 78 * @param len length of the transfer
va009039 7:9a20482c9a7a 79 * @param blocking if true, the read is blocking (wait for completion)
va009039 7:9a20482c9a7a 80 *
va009039 7:9a20482c9a7a 81 * @returns status of the interrupt read
va009039 7:9a20482c9a7a 82 */
va009039 7:9a20482c9a7a 83 USB_TYPE interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 84
va009039 7:9a20482c9a7a 85 /**
va009039 7:9a20482c9a7a 86 * Interrupt write
va009039 7:9a20482c9a7a 87 *
va009039 7:9a20482c9a7a 88 * @param dev the interrupt transfer will be done for this device
va009039 7:9a20482c9a7a 89 * @param ep USBEndpoint which will be used to write a packet
va009039 7:9a20482c9a7a 90 * @param buf pointer on a buffer which will be written
va009039 7:9a20482c9a7a 91 * @param len length of the transfer
va009039 7:9a20482c9a7a 92 * @param blocking if true, the write is blocking (wait for completion)
va009039 7:9a20482c9a7a 93 *
va009039 7:9a20482c9a7a 94 * @returns status of the interrupt write
va009039 7:9a20482c9a7a 95 */
va009039 7:9a20482c9a7a 96 USB_TYPE interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true);
va009039 7:9a20482c9a7a 97
va009039 7:9a20482c9a7a 98 int ControlRead(SETUP_PACKET* setup, uint8_t* data, int size);
va009039 7:9a20482c9a7a 99 int ControlWrite(SETUP_PACKET* setup, uint8_t* data = NULL, int size = 0);
va009039 7:9a20482c9a7a 100 int BulkRead(uint8_t* data, int size, int timeout_ms = -1);
va009039 7:9a20482c9a7a 101 int BulkWrite(const uint8_t* data, int size);
va009039 7:9a20482c9a7a 102 int InterruptRead(uint8_t* data, int size);
va009039 7:9a20482c9a7a 103 int IsochronousRead(USBEndpoint*ep, uint8_t* data, int size);
va009039 7:9a20482c9a7a 104
va009039 7:9a20482c9a7a 105 USBDeviceConnected dev;
va009039 7:9a20482c9a7a 106
va009039 7:9a20482c9a7a 107 private:
va009039 7:9a20482c9a7a 108 USBHost();
va009039 7:9a20482c9a7a 109 static USBHost* inst;
va009039 7:9a20482c9a7a 110 virtual bool enumeration();
va009039 7:9a20482c9a7a 111 USBEndpoint ep_ctl_in_out;
va009039 7:9a20482c9a7a 112 USBEndpoint ep_int_in;
va009039 7:9a20482c9a7a 113 USBEndpoint ep_bulk_in;
va009039 7:9a20482c9a7a 114 USBEndpoint ep_bulk_out;
va009039 7:9a20482c9a7a 115 };
va009039 7:9a20482c9a7a 116