USBDevice for STM support

Dependents:   Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more

This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Tue Mar 28 11:00:57 2017 +0200
Branch:
master
Revision:
4:50ec00aa4515
Parent:
1:2a3ae13b45ef
Child:
2:760da2befbf5
update for 5.4.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 2 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 4 * and associated documentation files (the "Software"), to deal in the Software without
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 7 * Software is furnished to do so, subject to the following conditions:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 8 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 9 * The above copyright notice and this permission notice shall be included in all copies or
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 10 * substantial portions of the Software.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 11 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 17 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 18 #if (defined (USB_STM_HAL) && defined(TARGET_STM32F4)) \
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 19 || defined(TARGET_STM32F2) || defined (TARGET_STM32F7) || defined (TARGET_STM32F3) || defined (TARGET_STM32L4)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 20
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 21 #include "USBHAL.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 22 #include "pinmap.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 23 /* mbed endpoint definition to hal definition */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 24 #define EP_ADDR(ep) (((ep) >> 1)|((ep) & 1) << 7)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 25 /* from hal definition to mbed definition */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 26 #define ADDR_EPIN(ep) (((ep) << 1) | 1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 27 #define ADDR_EPOUT(ep) (((ep) << 1))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 28 /* id to detect if rx buffer is used or not */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 29
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 30 #include "USBHAL_STM_TARGET.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 31
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 32
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 33 /* this call at device reception completion on a Out Enpoint */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 34 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 35 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 36 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 37 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 38 uint8_t endpoint = ADDR_EPOUT(epnum);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 39 priv->epComplete[endpoint] = 1;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 40 /* -2 endpoint 0 In out are not in call back list */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 41 if (epnum) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 42 bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 43 (obj->*func)();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 44 } else {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 45 void (USBHAL::*func)(void) = priv->ep0_out;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 46 (obj->*func)();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 47 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 48 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 49
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 50 /* this is call at device transmission completion on In endpoint */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 51 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 52 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 53 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 54 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 55 uint8_t endpoint = ADDR_EPIN(epnum);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 56 priv->epComplete[endpoint] = 1;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 57 /* -2 endpoint 0 In out are not in call back list */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 58 if (epnum) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 59 bool (USBHAL::*func)(void) = priv->epCallback[endpoint-2];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 60 (obj->*func)();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 61 } else {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 62 void (USBHAL::*func)(void) = priv->ep0_in;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 63 (obj->*func)();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 64 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 65 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 66 /* This is call at device set up reception */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 67 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 68 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 69 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 70 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 71 void (USBHAL::*func)(void)=priv->ep0_setup;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 72 void (USBHAL::*func1)(void)=priv->ep0_read;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 73 (obj->*func)();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 74 (obj->*func1)();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 75 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 76
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 77 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 78 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 79 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 80 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 81 void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 82 (obj->*func)(1);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 83 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 84
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 85 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 86 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 87 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 88 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 89 void (USBHAL::*func)(unsigned int suspended) = priv->suspend_change;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 90 (obj->*func)(0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 91 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 92
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 93 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 94 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 95 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 96 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 97 void (USBHAL::*func)(unsigned int suspended) = priv->connect_change;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 98 (obj->*func)(1);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 99 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 100
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 101 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 102 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 103 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 104 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 105 void (USBHAL::*func)(unsigned int suspended) = priv->connect_change;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 106 (obj->*func)(0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 107 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 108
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 109 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 110 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 111 USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 112 USBHAL *obj= priv->inst;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 113 unsigned int i;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 114 for(i=0;i<hpcd->Init.dev_endpoints;i++) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 115 priv->epComplete[2*i]=0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 116 HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 117 HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 118 priv->epComplete[2*i+1]=0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 119 HAL_PCD_EP_Close(hpcd,EP_ADDR(2*i+1));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 120 HAL_PCD_EP_Flush(hpcd,EP_ADDR(2*i+1));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 121
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 122 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 123 void (USBHAL::*func)(void)=priv->bus_reset;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 124 bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) = priv->ep_realise;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 125 (obj->*func)();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 126 (obj->*ep_realise)(EP0IN, MAX_PACKET_SIZE_EP0,0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 127 (obj->*ep_realise)(EP0OUT, MAX_PACKET_SIZE_EP0,0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 128 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 129
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 130
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 131 /* hal pcd handler , used for STM32 HAL PCD Layer */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 132
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 133 uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 134 return 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 135 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 136
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 137 USBHAL::~USBHAL(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 138 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 139 HAL_PCD_DeInit(&hpcd);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140 delete HALPriv;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143 void USBHAL::connect(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144 NVIC_EnableIRQ(USBHAL_IRQn);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147 void USBHAL::disconnect(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148 NVIC_DisableIRQ(USBHAL_IRQn);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 150
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 151 void USBHAL::configureDevice(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 152 // Not needed
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 153 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 154
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 155 void USBHAL::unconfigureDevice(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 156 // Not needed
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 157 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 158
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 159 void USBHAL::setAddress(uint8_t address) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 160 HAL_PCD_SetAddress(&hpcd, address);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 161 EP0write(0, 0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 162 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 163
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 164 bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 165 uint32_t epIndex = EP_ADDR(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 166 uint32_t type;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 167 uint32_t len;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 168 HAL_StatusTypeDef ret;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 169 switch (endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 170 case EP0IN:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 171 case EP0OUT:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 172 type = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174 case EPISO_IN:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175 case EPISO_OUT:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 type = 1;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 177 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 178 case EPBULK_IN:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 179 case EPBULK_OUT:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 180 type = 2;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 181 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 182 case EPINT_IN:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 183 case EPINT_OUT:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 184 type = 3;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 185 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 186 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 187 if (maxPacket > MAXTRANSFER_SIZE) return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 188 if (epIndex & 0x80) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 189 len = HAL_PCDEx_GetTxFiFo(&hpcd,epIndex & 0x7f);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 190 MBED_ASSERT(len >= maxPacket);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 191 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192 ret = HAL_PCD_EP_Open(&hpcd, epIndex, maxPacket, type);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193 MBED_ASSERT(ret!=HAL_BUSY);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 return (ret == HAL_OK) ? true:false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197 // read setup packet
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198 void USBHAL::EP0setup(uint8_t *buffer) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199 memcpy(buffer, hpcd.Setup, MAX_PACKET_SIZE_SETUP);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200 memset(hpcd.Setup,0,MAX_PACKET_SIZE_SETUP);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 void USBHAL::EP0readStage(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206 void USBHAL::EP0read(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208 uint32_t epIndex = EP_ADDR(EP0OUT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 uint8_t *pBuf = (uint8_t *)HALPriv->pBufRx0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210 HAL_StatusTypeDef ret;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211 HALPriv->epComplete[EP0OUT] = 2;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, MAX_PACKET_SIZE_EP0 );
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 213 MBED_ASSERT(ret!=HAL_BUSY);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 214
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 215 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217 uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)hpcd.pData;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219 uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, 0);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 220 HALPriv->epComplete[EP0OUT] = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 221 if (length) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 222 uint8_t *buff = (uint8_t *)HALPriv->pBufRx0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223 memcpy(buffer, buff, length);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225 return length;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 void USBHAL::EP0write(uint8_t *buffer, uint32_t size) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229 /* check that endpoint maximum size is not exceeding TX fifo */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230 MBED_ASSERT(hpcd.IN_ep[0].maxpacket >= size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231 endpointWrite(EP0IN, buffer, size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234 void USBHAL::EP0getWriteResult(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238 void USBHAL::EP0stall(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239 stallEndpoint(EP0IN);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 uint32_t epIndex = EP_ADDR(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 uint8_t* pBuf = (uint8_t *)HALPriv->pBufRx;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246 HAL_StatusTypeDef ret;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247 // clean reception end flag before requesting reception
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248 HALPriv->epComplete[endpoint] = 2;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 ret = HAL_PCD_EP_Receive(&hpcd, epIndex, pBuf, maximumSize);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250 MBED_ASSERT(ret!=HAL_BUSY);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 252 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 253
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 254 EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 255 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 256 if (HALPriv->epComplete[endpoint]==0) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 257 /* no reception possible !!! */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 258 bytesRead = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 259 return EP_COMPLETED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 260 }else if ((HALPriv->epComplete[endpoint]!=1))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 261 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 262 uint32_t epIndex = EP_ADDR(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 263 uint8_t *buff = (uint8_t *)HALPriv->pBufRx;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 264 uint32_t length = (uint32_t) HAL_PCD_EP_GetRxCount(&hpcd, epIndex);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 265 memcpy(buffer, buff, length);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 266 *bytesRead = length;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 267 HALPriv->epComplete[endpoint]= 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 268 return EP_COMPLETED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 269 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 270
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 271 EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 272 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 273 uint32_t epIndex = EP_ADDR(endpoint);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 274 HAL_StatusTypeDef ret;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 275 // clean transmission end flag before requesting transmission
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 276 HALPriv->epComplete[endpoint] = 2;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 277 ret = HAL_PCD_EP_Transmit(&hpcd, epIndex, data, size);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 278 MBED_ASSERT(ret!=HAL_BUSY);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 279 // update the status
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 280 if (ret != HAL_OK) return EP_INVALID;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 281 // fix me return is too simple
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 282 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 283 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 284
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 285 EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 286 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 287 if (HALPriv->epComplete[endpoint] == 1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 288 return EP_COMPLETED;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 289 return EP_PENDING;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 290 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 291
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 292 void USBHAL::stallEndpoint(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 293 USBHAL_Private_t *HALPriv = (USBHAL_Private_t *)(hpcd.pData);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 294 HAL_StatusTypeDef ret;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 295 HALPriv->epComplete[endpoint] = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 296 ret = HAL_PCD_EP_SetStall(&hpcd, EP_ADDR(endpoint));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 297 MBED_ASSERT(ret!=HAL_BUSY);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 298 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 299
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 300 void USBHAL::unstallEndpoint(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 301 HAL_StatusTypeDef ret;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 302 ret = HAL_PCD_EP_ClrStall(&hpcd, EP_ADDR(endpoint));
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 303 MBED_ASSERT(ret!=HAL_BUSY);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 304
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 305 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 306
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 307 bool USBHAL::getEndpointStallState(uint8_t endpoint) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 308 return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 309 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 310
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 311 void USBHAL::remoteWakeup(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 312 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 313
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 314
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 315 void USBHAL::_usbisr(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 316 instance->usbisr();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 317 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 318
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 319
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 320 void USBHAL::usbisr(void) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 321
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 322 HAL_PCD_IRQHandler(&instance->hpcd);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 323 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 324 #endif
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 325