Simple USBHost library for STM32F746NG Discovery board. Only either the Fastspeed or the Highspeed port can be used( not both together)

Dependents:   DISCO-F746NG_USB_Host

Fork of KL46Z-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Wed Feb 05 13:34:37 2014 +0000
Revision:
10:40c7f6788902
Parent:
8:6463cd1964c0
Child:
11:61843badd06e
fix endpoint callback.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 5:10bfc10afcc8 1 // Simple USBHost for FRDM-KL46Z
va009039 5:10bfc10afcc8 2 #pragma once
va009039 5:10bfc10afcc8 3 #include "mbed.h"
va009039 5:10bfc10afcc8 4 #include "USBHostTypes.h"
va009039 5:10bfc10afcc8 5 #include "USBEndpoint.h"
va009039 5:10bfc10afcc8 6
va009039 5:10bfc10afcc8 7 struct SETUP_PACKET {
va009039 5:10bfc10afcc8 8 uint8_t bmRequestType;
va009039 5:10bfc10afcc8 9 uint8_t bRequest;
va009039 5:10bfc10afcc8 10 uint16_t wValue;
va009039 5:10bfc10afcc8 11 uint16_t wIndex;
va009039 5:10bfc10afcc8 12 uint16_t wLength;
va009039 5:10bfc10afcc8 13 };
va009039 5:10bfc10afcc8 14
va009039 5:10bfc10afcc8 15 #define GET_CONFIGURATION 8
va009039 5:10bfc10afcc8 16
va009039 5:10bfc10afcc8 17 // TOK_PID[5:2]
va009039 5:10bfc10afcc8 18 #define Bus_Timeout 0x00
va009039 5:10bfc10afcc8 19 #define Data_Error 0x0f
va009039 5:10bfc10afcc8 20
va009039 5:10bfc10afcc8 21 enum ODD_EVEN {
va009039 5:10bfc10afcc8 22 ODD = 0,
va009039 5:10bfc10afcc8 23 EVEN = 1,
va009039 5:10bfc10afcc8 24 };
va009039 5:10bfc10afcc8 25
va009039 5:10bfc10afcc8 26 class Report {
va009039 5:10bfc10afcc8 27 public:
va009039 5:10bfc10afcc8 28 void clear();
va009039 5:10bfc10afcc8 29 void print_errstat();
va009039 5:10bfc10afcc8 30 // error count
va009039 5:10bfc10afcc8 31 uint32_t errstat_piderr; // USBx_ERRSTAT[PIDERR]
va009039 5:10bfc10afcc8 32 uint32_t errstat_crc5eof;// USBx_ERRSTAT[CRC5EOF]
va009039 5:10bfc10afcc8 33 uint32_t errstat_crc16; // USBx_ERRSTAT[CRC16]
va009039 5:10bfc10afcc8 34 uint32_t errstat_dfn8; // USBx_ERRSTAT[DFN8]
va009039 5:10bfc10afcc8 35 uint32_t errstat_btoerr; // USBx_ERRSTAT[BTOERR]
va009039 5:10bfc10afcc8 36 uint32_t errstat_dmaerr; // USBx_ERRSTAT[DMAERR]
va009039 5:10bfc10afcc8 37 uint32_t errstat_bsterr; // USBx_ERRSTAT[BTSERR]
va009039 5:10bfc10afcc8 38 //
va009039 5:10bfc10afcc8 39 uint32_t nak;
va009039 5:10bfc10afcc8 40 uint32_t stall;
va009039 5:10bfc10afcc8 41 };
va009039 5:10bfc10afcc8 42
va009039 5:10bfc10afcc8 43 class USBHALHost {
va009039 5:10bfc10afcc8 44 public:
va009039 5:10bfc10afcc8 45 uint8_t LastStatus;
va009039 5:10bfc10afcc8 46 uint8_t prev_LastStatus;
va009039 5:10bfc10afcc8 47 Report report;
va009039 5:10bfc10afcc8 48
va009039 5:10bfc10afcc8 49 protected:
va009039 5:10bfc10afcc8 50 USBHALHost();
va009039 5:10bfc10afcc8 51 void init();
va009039 10:40c7f6788902 52 virtual bool addDevice(USBDeviceConnected* parent, int port, bool lowSpeed) = 0;
va009039 8:6463cd1964c0 53 void setAddr(int addr, bool lowSpeed = false);
va009039 8:6463cd1964c0 54 void setEndpoint();
va009039 5:10bfc10afcc8 55 void token_transfer_init();
va009039 5:10bfc10afcc8 56 int token_setup(USBEndpoint* ep, SETUP_PACKET* setup, uint16_t wLength = 0);
va009039 5:10bfc10afcc8 57 int token_in(USBEndpoint* ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10);
va009039 5:10bfc10afcc8 58 int token_out(USBEndpoint* ep, const uint8_t* data = NULL, int size = 0, int retryLimit = 10);
va009039 5:10bfc10afcc8 59 int token_iso_in(USBEndpoint* ep, uint8_t* data, int size);
va009039 5:10bfc10afcc8 60 void token_ready();
va009039 5:10bfc10afcc8 61 private:
va009039 5:10bfc10afcc8 62 static void _usbisr(void);
va009039 5:10bfc10afcc8 63 void UsbIrqhandler();
va009039 5:10bfc10afcc8 64 __IO bool attach_done;
va009039 5:10bfc10afcc8 65 __IO bool token_done;
va009039 8:6463cd1964c0 66 bool wait_attach();
va009039 8:6463cd1964c0 67 bool root_lowSpeed;
va009039 5:10bfc10afcc8 68 ODD_EVEN tx_ptr;
va009039 5:10bfc10afcc8 69 ODD_EVEN rx_ptr;
va009039 5:10bfc10afcc8 70 static USBHALHost * instHost;
va009039 5:10bfc10afcc8 71 };