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:
Sat Jan 25 12:51:44 2014 +0000
Revision:
3:a3872f7593e2
fix max packet size

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 3:a3872f7593e2 1 // Simple USBHost for FRDM-KL46Z
va009039 3:a3872f7593e2 2 #pragma once
va009039 3:a3872f7593e2 3 #include "mbed.h"
va009039 3:a3872f7593e2 4 #include "USBHostTypes.h"
va009039 3:a3872f7593e2 5 #include "USBEndpoint.h"
va009039 3:a3872f7593e2 6
va009039 3:a3872f7593e2 7 struct SETUP_PACKET {
va009039 3:a3872f7593e2 8 uint8_t bmRequestType;
va009039 3:a3872f7593e2 9 uint8_t bRequest;
va009039 3:a3872f7593e2 10 uint16_t wValue;
va009039 3:a3872f7593e2 11 uint16_t wIndex;
va009039 3:a3872f7593e2 12 uint16_t wLength;
va009039 3:a3872f7593e2 13 };
va009039 3:a3872f7593e2 14
va009039 3:a3872f7593e2 15 #define GET_CONFIGURATION 8
va009039 3:a3872f7593e2 16
va009039 3:a3872f7593e2 17 // TOK_PID[5:2]
va009039 3:a3872f7593e2 18 #define DATA0 0x03
va009039 3:a3872f7593e2 19 #define DATA1 0x0b
va009039 3:a3872f7593e2 20 #define ACK 0x02
va009039 3:a3872f7593e2 21 #define STALL 0x0e
va009039 3:a3872f7593e2 22 #define NAK 0x0a
va009039 3:a3872f7593e2 23 #define Bus_Timeout 0x00
va009039 3:a3872f7593e2 24 #define Data_Error 0x0f
va009039 3:a3872f7593e2 25
va009039 3:a3872f7593e2 26 enum ODD_EVEN {
va009039 3:a3872f7593e2 27 ODD = 0,
va009039 3:a3872f7593e2 28 EVEN = 1,
va009039 3:a3872f7593e2 29 };
va009039 3:a3872f7593e2 30
va009039 3:a3872f7593e2 31 class Report {
va009039 3:a3872f7593e2 32 public:
va009039 3:a3872f7593e2 33 void clear();
va009039 3:a3872f7593e2 34 void print_errstat();
va009039 3:a3872f7593e2 35 // error count
va009039 3:a3872f7593e2 36 uint32_t errstat_piderr; // USBx_ERRSTAT[PIDERR]
va009039 3:a3872f7593e2 37 uint32_t errstat_crc5eof;// USBx_ERRSTAT[CRC5EOF]
va009039 3:a3872f7593e2 38 uint32_t errstat_crc16; // USBx_ERRSTAT[CRC16]
va009039 3:a3872f7593e2 39 uint32_t errstat_dfn8; // USBx_ERRSTAT[DFN8]
va009039 3:a3872f7593e2 40 uint32_t errstat_btoerr; // USBx_ERRSTAT[BTOERR]
va009039 3:a3872f7593e2 41 uint32_t errstat_dmaerr; // USBx_ERRSTAT[DMAERR]
va009039 3:a3872f7593e2 42 uint32_t errstat_bsterr; // USBx_ERRSTAT[BTSERR]
va009039 3:a3872f7593e2 43 //
va009039 3:a3872f7593e2 44 uint32_t nak;
va009039 3:a3872f7593e2 45 };
va009039 3:a3872f7593e2 46
va009039 3:a3872f7593e2 47 class Data01 {
va009039 3:a3872f7593e2 48 public:
va009039 3:a3872f7593e2 49 void init();
va009039 3:a3872f7593e2 50 void set(int txrx, int ep, uint8_t _data01);
va009039 3:a3872f7593e2 51 void toggle(int txrx, int ep);
va009039 3:a3872f7593e2 52 uint8_t get(int txrx, int ep);
va009039 3:a3872f7593e2 53 private:
va009039 3:a3872f7593e2 54 uint8_t txrx_data01[2][16];
va009039 3:a3872f7593e2 55 };
va009039 3:a3872f7593e2 56
va009039 3:a3872f7593e2 57 class USBHALHost {
va009039 3:a3872f7593e2 58 public:
va009039 3:a3872f7593e2 59 uint8_t LastStatus;
va009039 3:a3872f7593e2 60 uint8_t prev_LastStatus;
va009039 3:a3872f7593e2 61 Report report;
va009039 3:a3872f7593e2 62
va009039 3:a3872f7593e2 63 protected:
va009039 3:a3872f7593e2 64 USBHALHost();
va009039 3:a3872f7593e2 65 void init();
va009039 3:a3872f7593e2 66 virtual bool enumeration() = 0;
va009039 3:a3872f7593e2 67 bool lowSpeed;
va009039 3:a3872f7593e2 68 int MaxPacketSize0;
va009039 3:a3872f7593e2 69 void setAddr(int addr);
va009039 3:a3872f7593e2 70 void setEndpoint(bool use_retry = false);
va009039 3:a3872f7593e2 71 void token_transfer_init();
va009039 3:a3872f7593e2 72 int token_setup(SETUP_PACKET* setup, uint16_t wLength = 0);
va009039 3:a3872f7593e2 73 int token_in(uint8_t ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10);
va009039 3:a3872f7593e2 74 int token_out(uint8_t ep, const uint8_t* data = NULL, int size = 0);
va009039 3:a3872f7593e2 75 void token_ready();
va009039 3:a3872f7593e2 76 private:
va009039 3:a3872f7593e2 77 static void _usbisr(void);
va009039 3:a3872f7593e2 78 void UsbIrqhandler();
va009039 3:a3872f7593e2 79 __IO bool attach_done;
va009039 3:a3872f7593e2 80 __IO bool token_done;
va009039 3:a3872f7593e2 81 void wait_attach();
va009039 3:a3872f7593e2 82 Data01 data01;
va009039 3:a3872f7593e2 83 ODD_EVEN tx_ptr;
va009039 3:a3872f7593e2 84 ODD_EVEN rx_ptr;
va009039 3:a3872f7593e2 85 static USBHALHost * instHost;
va009039 3:a3872f7593e2 86 };