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:
DieterGraef
Date:
Fri Jun 17 09:00:35 2016 +0000
Revision:
25:7d6d9fc471bf
Parent:
24:5396b6a93262
USB Host now works with both Interfaces even in parallel. Some changes in the USB MSD driver to make it operable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DieterGraef 24:5396b6a93262 1 #pragma once
DieterGraef 24:5396b6a93262 2 #include "mbed.h"
DieterGraef 24:5396b6a93262 3 #include "USBHostTypes.h"
DieterGraef 24:5396b6a93262 4 #include "USBEndpoint.h"
DieterGraef 24:5396b6a93262 5 #define USB_FastSpeed 0
DieterGraef 24:5396b6a93262 6 #define USB_HighSpeed 1
DieterGraef 24:5396b6a93262 7
DieterGraef 25:7d6d9fc471bf 8 class HC_FS {
DieterGraef 24:5396b6a93262 9 static const uint8_t DIR_IN = 1;
DieterGraef 24:5396b6a93262 10 static const uint8_t DIR_OUT = 0;
DieterGraef 24:5396b6a93262 11
DieterGraef 24:5396b6a93262 12 public:
DieterGraef 25:7d6d9fc471bf 13 HC_FS();
DieterGraef 25:7d6d9fc471bf 14 HC_FS(int ch);
DieterGraef 25:7d6d9fc471bf 15 ~HC_FS();
DieterGraef 25:7d6d9fc471bf 16 HAL_StatusTypeDef Init(uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps);
DieterGraef 25:7d6d9fc471bf 17 HAL_StatusTypeDef SubmitRequest(uint8_t* pbuff, uint16_t length, bool setup = false);
DieterGraef 24:5396b6a93262 18 HCD_URBStateTypeDef GetURBState();
DieterGraef 24:5396b6a93262 19 HCD_HCStateTypeDef GetState();
DieterGraef 24:5396b6a93262 20 uint32_t GetXferCount();
DieterGraef 24:5396b6a93262 21 void SetToggle(uint8_t toggle);
DieterGraef 24:5396b6a93262 22
DieterGraef 24:5396b6a93262 23 static uint8_t slot;
DieterGraef 25:7d6d9fc471bf 24
DieterGraef 24:5396b6a93262 25 private:
DieterGraef 24:5396b6a93262 26 int _ch;
DieterGraef 24:5396b6a93262 27 uint8_t _ep_addr;
DieterGraef 24:5396b6a93262 28 uint8_t _ep_type;
DieterGraef 24:5396b6a93262 29 };
DieterGraef 24:5396b6a93262 30
DieterGraef 25:7d6d9fc471bf 31 class HC_HS {
DieterGraef 25:7d6d9fc471bf 32 static const uint8_t DIR_IN = 1;
DieterGraef 25:7d6d9fc471bf 33 static const uint8_t DIR_OUT = 0;
DieterGraef 25:7d6d9fc471bf 34
DieterGraef 25:7d6d9fc471bf 35 public:
DieterGraef 25:7d6d9fc471bf 36 HC_HS();
DieterGraef 25:7d6d9fc471bf 37 HC_HS(int ch);
DieterGraef 25:7d6d9fc471bf 38 ~HC_HS();
DieterGraef 25:7d6d9fc471bf 39 HAL_StatusTypeDef Init(uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps);
DieterGraef 25:7d6d9fc471bf 40 HAL_StatusTypeDef SubmitRequest(uint8_t* pbuff, uint16_t length, bool setup = false);
DieterGraef 25:7d6d9fc471bf 41 HCD_URBStateTypeDef GetURBState();
DieterGraef 25:7d6d9fc471bf 42 HCD_HCStateTypeDef GetState();
DieterGraef 25:7d6d9fc471bf 43 uint32_t GetXferCount();
DieterGraef 25:7d6d9fc471bf 44 void SetToggle(uint8_t toggle);
DieterGraef 25:7d6d9fc471bf 45
DieterGraef 25:7d6d9fc471bf 46 static uint8_t slot;
DieterGraef 25:7d6d9fc471bf 47
DieterGraef 25:7d6d9fc471bf 48 private:
DieterGraef 25:7d6d9fc471bf 49 int _ch;
DieterGraef 25:7d6d9fc471bf 50 uint8_t _ep_addr;
DieterGraef 25:7d6d9fc471bf 51 uint8_t _ep_type;
DieterGraef 25:7d6d9fc471bf 52 };
DieterGraef 25:7d6d9fc471bf 53
DieterGraef 25:7d6d9fc471bf 54
DieterGraef 24:5396b6a93262 55 class USBHALHost {
DieterGraef 24:5396b6a93262 56 public:
DieterGraef 24:5396b6a93262 57 uint8_t LastStatus;
DieterGraef 24:5396b6a93262 58 uint8_t prev_LastStatus;
DieterGraef 24:5396b6a93262 59 int IF_N;
DieterGraef 24:5396b6a93262 60 HCD_HandleTypeDef hhcd_USB;
DieterGraef 24:5396b6a93262 61
DieterGraef 24:5396b6a93262 62 protected:
DieterGraef 24:5396b6a93262 63 USBHALHost(int InterfaceNumber);
DieterGraef 24:5396b6a93262 64 void init();
DieterGraef 24:5396b6a93262 65 virtual bool addDevice(USBDeviceConnected* parent, int port, bool lowSpeed) = 0;
DieterGraef 24:5396b6a93262 66 int token_setup(USBEndpoint* ep, SETUP_PACKET* setup, uint16_t wLength = 0);
DieterGraef 24:5396b6a93262 67 int token_iso_in(USBEndpoint* ep, uint8_t* data, int size);
DieterGraef 24:5396b6a93262 68 int multi_token_in(USBEndpoint* ep, uint8_t* data = NULL, size_t total = 0, bool block = true);
DieterGraef 24:5396b6a93262 69 int multi_token_out(USBEndpoint* ep, const uint8_t* data = NULL, size_t total = 0);
DieterGraef 24:5396b6a93262 70 void multi_token_inNB(USBEndpoint* ep, uint8_t* data, int size);
DieterGraef 24:5396b6a93262 71 USB_TYPE multi_token_inNB_result(USBEndpoint* ep);
DieterGraef 24:5396b6a93262 72 void setToggle(USBEndpoint* ep, uint8_t toggle);
DieterGraef 24:5396b6a93262 73 int epint_setup(USBEndpoint* ep);
DieterGraef 24:5396b6a93262 74
DieterGraef 24:5396b6a93262 75
DieterGraef 24:5396b6a93262 76 private:
DieterGraef 24:5396b6a93262 77
DieterGraef 24:5396b6a93262 78 int token_in(USBEndpoint* ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10);
DieterGraef 24:5396b6a93262 79 int token_out(USBEndpoint* ep, const uint8_t* data = NULL, int size = 0, int retryLimit = 10);
DieterGraef 24:5396b6a93262 80 int token_ctl_in(USBEndpoint* ep, uint8_t* data, int size, int retryLimit);
DieterGraef 24:5396b6a93262 81 int token_int_in(USBEndpoint* ep, uint8_t* data, int size);
DieterGraef 24:5396b6a93262 82 int token_blk_in(USBEndpoint* ep, uint8_t* data, int size, int retryLimit);
DieterGraef 24:5396b6a93262 83 int token_ctl_out(USBEndpoint* ep, const uint8_t* data, int size, int retryLimit);
DieterGraef 24:5396b6a93262 84 int token_int_out(USBEndpoint* ep, const uint8_t* data, int size);
DieterGraef 24:5396b6a93262 85 int token_blk_out(USBEndpoint* ep, const uint8_t* data, int size, int retryLimit);
DieterGraef 24:5396b6a93262 86 bool wait_attach();
DieterGraef 24:5396b6a93262 87 static USBHALHost * instHost;
DieterGraef 24:5396b6a93262 88 HCD_HandleTypeDef* hhcd;
DieterGraef 25:7d6d9fc471bf 89 void usbisr_FS(void);
DieterGraef 25:7d6d9fc471bf 90 static void _usbisr_FS(void);
DieterGraef 25:7d6d9fc471bf 91 void usbisr_HS(void);
DieterGraef 25:7d6d9fc471bf 92 static void _usbisr_HS(void);
DieterGraef 24:5396b6a93262 93 };
DieterGraef 24:5396b6a93262 94