partly working USB Device lib for STM32F746NG Discovery both Interface are working
Dependents: DISCO-F746NG-USB_Device McLighTT project_Keyboard_to_the_Keyboard MIDIInstrumentPADProject ... more
USBDevice/USBHAL_STM32F7.cpp@0:0a2eaa300982, 2016-07-31 (annotated)
- Committer:
- DieterGraef
- Date:
- Sun Jul 31 17:47:35 2016 +0000
- Revision:
- 0:0a2eaa300982
partly working USB Device library - serial and MIDI is working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 0:0a2eaa300982 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
DieterGraef | 0:0a2eaa300982 | 2 | * |
DieterGraef | 0:0a2eaa300982 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
DieterGraef | 0:0a2eaa300982 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
DieterGraef | 0:0a2eaa300982 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
DieterGraef | 0:0a2eaa300982 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
DieterGraef | 0:0a2eaa300982 | 7 | * Software is furnished to do so, subject to the following conditions: |
DieterGraef | 0:0a2eaa300982 | 8 | * |
DieterGraef | 0:0a2eaa300982 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
DieterGraef | 0:0a2eaa300982 | 10 | * substantial portions of the Software. |
DieterGraef | 0:0a2eaa300982 | 11 | * |
DieterGraef | 0:0a2eaa300982 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
DieterGraef | 0:0a2eaa300982 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
DieterGraef | 0:0a2eaa300982 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
DieterGraef | 0:0a2eaa300982 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
DieterGraef | 0:0a2eaa300982 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
DieterGraef | 0:0a2eaa300982 | 17 | */ |
DieterGraef | 0:0a2eaa300982 | 18 | |
DieterGraef | 0:0a2eaa300982 | 19 | #if defined (TARGET_DISCO_F746NG) |
DieterGraef | 0:0a2eaa300982 | 20 | #include "USBDevice.h" |
DieterGraef | 0:0a2eaa300982 | 21 | static PCD_HandleTypeDef hpcd_USB_FS; |
DieterGraef | 0:0a2eaa300982 | 22 | static PCD_HandleTypeDef hpcd_USB_HS; |
DieterGraef | 0:0a2eaa300982 | 23 | static volatile int epCompleteFS = 0; |
DieterGraef | 0:0a2eaa300982 | 24 | static volatile int epCompleteHS = 0; |
DieterGraef | 0:0a2eaa300982 | 25 | USBHAL * USBHAL::instance; |
DieterGraef | 0:0a2eaa300982 | 26 | uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) |
DieterGraef | 0:0a2eaa300982 | 27 | { |
DieterGraef | 0:0a2eaa300982 | 28 | return 0; |
DieterGraef | 0:0a2eaa300982 | 29 | } |
DieterGraef | 0:0a2eaa300982 | 30 | |
DieterGraef | 0:0a2eaa300982 | 31 | void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) |
DieterGraef | 0:0a2eaa300982 | 32 | { |
DieterGraef | 0:0a2eaa300982 | 33 | GPIO_InitTypeDef GPIO_InitStruct; |
DieterGraef | 0:0a2eaa300982 | 34 | |
DieterGraef | 0:0a2eaa300982 | 35 | if(hpcd->Instance == USB_OTG_FS) |
DieterGraef | 0:0a2eaa300982 | 36 | { |
DieterGraef | 0:0a2eaa300982 | 37 | /* Configure USB FS GPIOs */ |
DieterGraef | 0:0a2eaa300982 | 38 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 39 | |
DieterGraef | 0:0a2eaa300982 | 40 | /* Configure DM DP Pins */ |
DieterGraef | 0:0a2eaa300982 | 41 | GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12); |
DieterGraef | 0:0a2eaa300982 | 42 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
DieterGraef | 0:0a2eaa300982 | 43 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
DieterGraef | 0:0a2eaa300982 | 44 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
DieterGraef | 0:0a2eaa300982 | 45 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS; |
DieterGraef | 0:0a2eaa300982 | 46 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
DieterGraef | 0:0a2eaa300982 | 47 | |
DieterGraef | 0:0a2eaa300982 | 48 | /* Enable USB FS Clock */ |
DieterGraef | 0:0a2eaa300982 | 49 | __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 50 | |
DieterGraef | 0:0a2eaa300982 | 51 | |
DieterGraef | 0:0a2eaa300982 | 52 | } |
DieterGraef | 0:0a2eaa300982 | 53 | else if(hpcd->Instance == USB_OTG_HS) |
DieterGraef | 0:0a2eaa300982 | 54 | { |
DieterGraef | 0:0a2eaa300982 | 55 | /* Configure USB FS GPIOs */ |
DieterGraef | 0:0a2eaa300982 | 56 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 57 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 58 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 59 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 60 | |
DieterGraef | 0:0a2eaa300982 | 61 | /* CLK */ |
DieterGraef | 0:0a2eaa300982 | 62 | GPIO_InitStruct.Pin = GPIO_PIN_5; |
DieterGraef | 0:0a2eaa300982 | 63 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
DieterGraef | 0:0a2eaa300982 | 64 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
DieterGraef | 0:0a2eaa300982 | 65 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
DieterGraef | 0:0a2eaa300982 | 66 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
DieterGraef | 0:0a2eaa300982 | 67 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
DieterGraef | 0:0a2eaa300982 | 68 | |
DieterGraef | 0:0a2eaa300982 | 69 | /* D0 */ |
DieterGraef | 0:0a2eaa300982 | 70 | GPIO_InitStruct.Pin = GPIO_PIN_3; |
DieterGraef | 0:0a2eaa300982 | 71 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
DieterGraef | 0:0a2eaa300982 | 72 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
DieterGraef | 0:0a2eaa300982 | 73 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
DieterGraef | 0:0a2eaa300982 | 74 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
DieterGraef | 0:0a2eaa300982 | 75 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
DieterGraef | 0:0a2eaa300982 | 76 | |
DieterGraef | 0:0a2eaa300982 | 77 | /* D1 D2 D3 D4 D5 D6 D7 */ |
DieterGraef | 0:0a2eaa300982 | 78 | GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |\ |
DieterGraef | 0:0a2eaa300982 | 79 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13; |
DieterGraef | 0:0a2eaa300982 | 80 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
DieterGraef | 0:0a2eaa300982 | 81 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
DieterGraef | 0:0a2eaa300982 | 82 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
DieterGraef | 0:0a2eaa300982 | 83 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
DieterGraef | 0:0a2eaa300982 | 84 | |
DieterGraef | 0:0a2eaa300982 | 85 | /* STP */ |
DieterGraef | 0:0a2eaa300982 | 86 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
DieterGraef | 0:0a2eaa300982 | 87 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
DieterGraef | 0:0a2eaa300982 | 88 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
DieterGraef | 0:0a2eaa300982 | 89 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
DieterGraef | 0:0a2eaa300982 | 90 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
DieterGraef | 0:0a2eaa300982 | 91 | |
DieterGraef | 0:0a2eaa300982 | 92 | /* NXT */ |
DieterGraef | 0:0a2eaa300982 | 93 | GPIO_InitStruct.Pin = GPIO_PIN_4; |
DieterGraef | 0:0a2eaa300982 | 94 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
DieterGraef | 0:0a2eaa300982 | 95 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
DieterGraef | 0:0a2eaa300982 | 96 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
DieterGraef | 0:0a2eaa300982 | 97 | HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); |
DieterGraef | 0:0a2eaa300982 | 98 | |
DieterGraef | 0:0a2eaa300982 | 99 | /* DIR */ |
DieterGraef | 0:0a2eaa300982 | 100 | GPIO_InitStruct.Pin = GPIO_PIN_2; |
DieterGraef | 0:0a2eaa300982 | 101 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
DieterGraef | 0:0a2eaa300982 | 102 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
DieterGraef | 0:0a2eaa300982 | 103 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; |
DieterGraef | 0:0a2eaa300982 | 104 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
DieterGraef | 0:0a2eaa300982 | 105 | |
DieterGraef | 0:0a2eaa300982 | 106 | __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 107 | |
DieterGraef | 0:0a2eaa300982 | 108 | /* Enable USB HS Clocks */ |
DieterGraef | 0:0a2eaa300982 | 109 | __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); |
DieterGraef | 0:0a2eaa300982 | 110 | |
DieterGraef | 0:0a2eaa300982 | 111 | |
DieterGraef | 0:0a2eaa300982 | 112 | } |
DieterGraef | 0:0a2eaa300982 | 113 | } |
DieterGraef | 0:0a2eaa300982 | 114 | |
DieterGraef | 0:0a2eaa300982 | 115 | void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) |
DieterGraef | 0:0a2eaa300982 | 116 | { |
DieterGraef | 0:0a2eaa300982 | 117 | if(hpcd->Instance == USB_OTG_FS) |
DieterGraef | 0:0a2eaa300982 | 118 | { |
DieterGraef | 0:0a2eaa300982 | 119 | /* Disable USB FS Clock */ |
DieterGraef | 0:0a2eaa300982 | 120 | __HAL_RCC_USB_OTG_FS_CLK_DISABLE(); |
DieterGraef | 0:0a2eaa300982 | 121 | __HAL_RCC_SYSCFG_CLK_DISABLE(); |
DieterGraef | 0:0a2eaa300982 | 122 | } |
DieterGraef | 0:0a2eaa300982 | 123 | else if(hpcd->Instance == USB_OTG_HS) |
DieterGraef | 0:0a2eaa300982 | 124 | { |
DieterGraef | 0:0a2eaa300982 | 125 | /* Disable USB HS Clocks */ |
DieterGraef | 0:0a2eaa300982 | 126 | __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); |
DieterGraef | 0:0a2eaa300982 | 127 | __HAL_RCC_SYSCFG_CLK_DISABLE(); |
DieterGraef | 0:0a2eaa300982 | 128 | } |
DieterGraef | 0:0a2eaa300982 | 129 | } |
DieterGraef | 0:0a2eaa300982 | 130 | |
DieterGraef | 0:0a2eaa300982 | 131 | |
DieterGraef | 0:0a2eaa300982 | 132 | USBHAL::USBHAL(uint16_t HW_Interface) |
DieterGraef | 0:0a2eaa300982 | 133 | { |
DieterGraef | 0:0a2eaa300982 | 134 | HW_Interfaces=HW_Interface; |
DieterGraef | 0:0a2eaa300982 | 135 | if(HW_Interface==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 136 | { |
DieterGraef | 0:0a2eaa300982 | 137 | hpcd_USB_FS.pData = this; |
DieterGraef | 0:0a2eaa300982 | 138 | hpcd_USB_FS.Instance = USB_OTG_FS; |
DieterGraef | 0:0a2eaa300982 | 139 | hpcd_USB_FS.Init.dev_endpoints = 8; |
DieterGraef | 0:0a2eaa300982 | 140 | hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; |
DieterGraef | 0:0a2eaa300982 | 141 | hpcd_USB_FS.Init.ep0_mps = 0x40; |
DieterGraef | 0:0a2eaa300982 | 142 | hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; |
DieterGraef | 0:0a2eaa300982 | 143 | hpcd_USB_FS.Init.Sof_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 144 | hpcd_USB_FS.Init.dma_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 145 | hpcd_USB_FS.Init.vbus_sensing_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 146 | hpcd_USB_FS.Init.lpm_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 147 | hpcd_USB_FS.Init.low_power_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 148 | //hpcd_USB_FS.Init.battery_charging_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 149 | |
DieterGraef | 0:0a2eaa300982 | 150 | |
DieterGraef | 0:0a2eaa300982 | 151 | NVIC_SetVector(OTG_FS_IRQn, (uint32_t)&_usbisrFS); |
DieterGraef | 0:0a2eaa300982 | 152 | /* Set USBFS Interrupt priority */ |
DieterGraef | 0:0a2eaa300982 | 153 | HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); |
DieterGraef | 0:0a2eaa300982 | 154 | /* Enable USBFS Interrupt */ |
DieterGraef | 0:0a2eaa300982 | 155 | HAL_NVIC_EnableIRQ(OTG_FS_IRQn); |
DieterGraef | 0:0a2eaa300982 | 156 | HAL_PCD_Init(&hpcd_USB_FS); |
DieterGraef | 0:0a2eaa300982 | 157 | HAL_PCDEx_SetRxFiFo(&hpcd_USB_FS, 0x80); |
DieterGraef | 0:0a2eaa300982 | 158 | HAL_PCD_Start(&hpcd_USB_FS); |
DieterGraef | 0:0a2eaa300982 | 159 | } |
DieterGraef | 0:0a2eaa300982 | 160 | else |
DieterGraef | 0:0a2eaa300982 | 161 | { |
DieterGraef | 0:0a2eaa300982 | 162 | hpcd_USB_HS.pData = this; |
DieterGraef | 0:0a2eaa300982 | 163 | hpcd_USB_HS.Instance = USB_OTG_HS; |
DieterGraef | 0:0a2eaa300982 | 164 | hpcd_USB_HS.Init.dev_endpoints = 8; |
DieterGraef | 0:0a2eaa300982 | 165 | hpcd_USB_HS.Init.speed = PCD_SPEED_HIGH; |
DieterGraef | 0:0a2eaa300982 | 166 | hpcd_USB_HS.Init.ep0_mps = 0x40; |
DieterGraef | 0:0a2eaa300982 | 167 | hpcd_USB_HS.Init.phy_itface = PCD_PHY_ULPI; |
DieterGraef | 0:0a2eaa300982 | 168 | hpcd_USB_HS.Init.Sof_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 169 | hpcd_USB_HS.Init.dma_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 170 | hpcd_USB_HS.Init.vbus_sensing_enable = ENABLE; |
DieterGraef | 0:0a2eaa300982 | 171 | hpcd_USB_HS.Init.lpm_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 172 | hpcd_USB_HS.Init.low_power_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 173 | //hpcd_USB_HS.Init.battery_charging_enable = DISABLE; |
DieterGraef | 0:0a2eaa300982 | 174 | |
DieterGraef | 0:0a2eaa300982 | 175 | NVIC_SetVector(OTG_HS_IRQn, (uint32_t)&_usbisrHS); |
DieterGraef | 0:0a2eaa300982 | 176 | /* Set USBHS Interrupt to the lowest priority */ |
DieterGraef | 0:0a2eaa300982 | 177 | HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0); |
DieterGraef | 0:0a2eaa300982 | 178 | /* Enable USBHS Interrupt */ |
DieterGraef | 0:0a2eaa300982 | 179 | HAL_NVIC_EnableIRQ(OTG_HS_IRQn); |
DieterGraef | 0:0a2eaa300982 | 180 | HAL_PCD_Init(&hpcd_USB_HS); |
DieterGraef | 0:0a2eaa300982 | 181 | HAL_PCDEx_SetRxFiFo(&hpcd_USB_HS, 0x200); |
DieterGraef | 0:0a2eaa300982 | 182 | HAL_PCD_Start(&hpcd_USB_HS); |
DieterGraef | 0:0a2eaa300982 | 183 | } |
DieterGraef | 0:0a2eaa300982 | 184 | } |
DieterGraef | 0:0a2eaa300982 | 185 | |
DieterGraef | 0:0a2eaa300982 | 186 | USBHAL::~USBHAL(void) |
DieterGraef | 0:0a2eaa300982 | 187 | { |
DieterGraef | 0:0a2eaa300982 | 188 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 189 | { |
DieterGraef | 0:0a2eaa300982 | 190 | HAL_PCD_DeInit(&hpcd_USB_FS); |
DieterGraef | 0:0a2eaa300982 | 191 | } |
DieterGraef | 0:0a2eaa300982 | 192 | else |
DieterGraef | 0:0a2eaa300982 | 193 | { |
DieterGraef | 0:0a2eaa300982 | 194 | HAL_PCD_DeInit(&hpcd_USB_HS); |
DieterGraef | 0:0a2eaa300982 | 195 | } |
DieterGraef | 0:0a2eaa300982 | 196 | } |
DieterGraef | 0:0a2eaa300982 | 197 | |
DieterGraef | 0:0a2eaa300982 | 198 | |
DieterGraef | 0:0a2eaa300982 | 199 | void USBHAL::connect(void) |
DieterGraef | 0:0a2eaa300982 | 200 | { |
DieterGraef | 0:0a2eaa300982 | 201 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 202 | { |
DieterGraef | 0:0a2eaa300982 | 203 | HAL_PCD_DevConnect(&hpcd_USB_FS); |
DieterGraef | 0:0a2eaa300982 | 204 | } |
DieterGraef | 0:0a2eaa300982 | 205 | else |
DieterGraef | 0:0a2eaa300982 | 206 | { |
DieterGraef | 0:0a2eaa300982 | 207 | HAL_PCD_DevConnect(&hpcd_USB_HS); |
DieterGraef | 0:0a2eaa300982 | 208 | } |
DieterGraef | 0:0a2eaa300982 | 209 | } |
DieterGraef | 0:0a2eaa300982 | 210 | |
DieterGraef | 0:0a2eaa300982 | 211 | void USBHAL::disconnect(void) |
DieterGraef | 0:0a2eaa300982 | 212 | { |
DieterGraef | 0:0a2eaa300982 | 213 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 214 | { |
DieterGraef | 0:0a2eaa300982 | 215 | HAL_PCD_DevDisconnect(&hpcd_USB_FS); |
DieterGraef | 0:0a2eaa300982 | 216 | } |
DieterGraef | 0:0a2eaa300982 | 217 | else |
DieterGraef | 0:0a2eaa300982 | 218 | { |
DieterGraef | 0:0a2eaa300982 | 219 | HAL_PCD_DevDisconnect(&hpcd_USB_HS); |
DieterGraef | 0:0a2eaa300982 | 220 | } |
DieterGraef | 0:0a2eaa300982 | 221 | } |
DieterGraef | 0:0a2eaa300982 | 222 | |
DieterGraef | 0:0a2eaa300982 | 223 | void USBHAL::configureDevice(void) |
DieterGraef | 0:0a2eaa300982 | 224 | { |
DieterGraef | 0:0a2eaa300982 | 225 | // Not needed |
DieterGraef | 0:0a2eaa300982 | 226 | } |
DieterGraef | 0:0a2eaa300982 | 227 | void USBHAL::unconfigureDevice(void) |
DieterGraef | 0:0a2eaa300982 | 228 | { |
DieterGraef | 0:0a2eaa300982 | 229 | // Not needed |
DieterGraef | 0:0a2eaa300982 | 230 | } |
DieterGraef | 0:0a2eaa300982 | 231 | |
DieterGraef | 0:0a2eaa300982 | 232 | void USBHAL::setAddress(uint8_t address) |
DieterGraef | 0:0a2eaa300982 | 233 | { |
DieterGraef | 0:0a2eaa300982 | 234 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 235 | { |
DieterGraef | 0:0a2eaa300982 | 236 | HAL_PCD_SetAddress(&hpcd_USB_FS, address); |
DieterGraef | 0:0a2eaa300982 | 237 | } |
DieterGraef | 0:0a2eaa300982 | 238 | else |
DieterGraef | 0:0a2eaa300982 | 239 | { |
DieterGraef | 0:0a2eaa300982 | 240 | HAL_PCD_SetAddress(&hpcd_USB_HS, address); |
DieterGraef | 0:0a2eaa300982 | 241 | } |
DieterGraef | 0:0a2eaa300982 | 242 | } |
DieterGraef | 0:0a2eaa300982 | 243 | |
DieterGraef | 0:0a2eaa300982 | 244 | |
DieterGraef | 0:0a2eaa300982 | 245 | class PacketBufferAreaManager |
DieterGraef | 0:0a2eaa300982 | 246 | { |
DieterGraef | 0:0a2eaa300982 | 247 | public: |
DieterGraef | 0:0a2eaa300982 | 248 | PacketBufferAreaManager(int bufsize_):bufsize(bufsize_) |
DieterGraef | 0:0a2eaa300982 | 249 | { |
DieterGraef | 0:0a2eaa300982 | 250 | reset(); |
DieterGraef | 0:0a2eaa300982 | 251 | } |
DieterGraef | 0:0a2eaa300982 | 252 | void reset() |
DieterGraef | 0:0a2eaa300982 | 253 | { |
DieterGraef | 0:0a2eaa300982 | 254 | head = 0; |
DieterGraef | 0:0a2eaa300982 | 255 | tail = bufsize; |
DieterGraef | 0:0a2eaa300982 | 256 | } |
DieterGraef | 0:0a2eaa300982 | 257 | int allocBuf(int maxPacketSize) |
DieterGraef | 0:0a2eaa300982 | 258 | { |
DieterGraef | 0:0a2eaa300982 | 259 | head += 4; |
DieterGraef | 0:0a2eaa300982 | 260 | tail -= maxPacketSize; |
DieterGraef | 0:0a2eaa300982 | 261 | if (tail < head) |
DieterGraef | 0:0a2eaa300982 | 262 | { |
DieterGraef | 0:0a2eaa300982 | 263 | return 0; |
DieterGraef | 0:0a2eaa300982 | 264 | } |
DieterGraef | 0:0a2eaa300982 | 265 | return tail; |
DieterGraef | 0:0a2eaa300982 | 266 | } |
DieterGraef | 0:0a2eaa300982 | 267 | private: |
DieterGraef | 0:0a2eaa300982 | 268 | int head,tail; |
DieterGraef | 0:0a2eaa300982 | 269 | int bufsize; |
DieterGraef | 0:0a2eaa300982 | 270 | } PktBufArea(512); |
DieterGraef | 0:0a2eaa300982 | 271 | |
DieterGraef | 0:0a2eaa300982 | 272 | |
DieterGraef | 0:0a2eaa300982 | 273 | bool USBHAL::realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t flags) |
DieterGraef | 0:0a2eaa300982 | 274 | { |
DieterGraef | 0:0a2eaa300982 | 275 | |
DieterGraef | 0:0a2eaa300982 | 276 | PCD_HandleTypeDef *hpcd; |
DieterGraef | 0:0a2eaa300982 | 277 | |
DieterGraef | 0:0a2eaa300982 | 278 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 279 | { |
DieterGraef | 0:0a2eaa300982 | 280 | hpcd = &hpcd_USB_FS; |
DieterGraef | 0:0a2eaa300982 | 281 | } |
DieterGraef | 0:0a2eaa300982 | 282 | else |
DieterGraef | 0:0a2eaa300982 | 283 | { |
DieterGraef | 0:0a2eaa300982 | 284 | hpcd = &hpcd_USB_HS; |
DieterGraef | 0:0a2eaa300982 | 285 | } |
DieterGraef | 0:0a2eaa300982 | 286 | uint8_t ep_type; |
DieterGraef | 0:0a2eaa300982 | 287 | switch(endpoint) |
DieterGraef | 0:0a2eaa300982 | 288 | { |
DieterGraef | 0:0a2eaa300982 | 289 | case EP0OUT: |
DieterGraef | 0:0a2eaa300982 | 290 | HAL_PCD_EP_Open(hpcd, 0x00, maxPacket, EP_TYPE_CTRL); |
DieterGraef | 0:0a2eaa300982 | 291 | break; |
DieterGraef | 0:0a2eaa300982 | 292 | case EP0IN: |
DieterGraef | 0:0a2eaa300982 | 293 | HAL_PCDEx_SetTxFiFo(hpcd,0,maxPacket); |
DieterGraef | 0:0a2eaa300982 | 294 | HAL_PCD_EP_Open(hpcd, 0x80, maxPacket, EP_TYPE_CTRL); |
DieterGraef | 0:0a2eaa300982 | 295 | break; |
DieterGraef | 0:0a2eaa300982 | 296 | case EPINT_OUT: |
DieterGraef | 0:0a2eaa300982 | 297 | HAL_PCD_EP_Open(hpcd, 0x01, maxPacket, EP_TYPE_INTR); |
DieterGraef | 0:0a2eaa300982 | 298 | break; |
DieterGraef | 0:0a2eaa300982 | 299 | case EPINT_IN: |
DieterGraef | 0:0a2eaa300982 | 300 | HAL_PCDEx_SetTxFiFo(hpcd,1,maxPacket); |
DieterGraef | 0:0a2eaa300982 | 301 | HAL_PCD_EP_Open(hpcd, 0x81, maxPacket, EP_TYPE_INTR); |
DieterGraef | 0:0a2eaa300982 | 302 | break; |
DieterGraef | 0:0a2eaa300982 | 303 | case EPBULK_OUT: |
DieterGraef | 0:0a2eaa300982 | 304 | HAL_PCD_EP_Open(hpcd, 0x02, maxPacket, EP_TYPE_BULK); |
DieterGraef | 0:0a2eaa300982 | 305 | break; |
DieterGraef | 0:0a2eaa300982 | 306 | case EPBULK_IN: |
DieterGraef | 0:0a2eaa300982 | 307 | HAL_PCDEx_SetTxFiFo(hpcd,2,maxPacket); |
DieterGraef | 0:0a2eaa300982 | 308 | HAL_PCD_EP_Open(hpcd, 0x82, maxPacket, EP_TYPE_BULK); |
DieterGraef | 0:0a2eaa300982 | 309 | break; |
DieterGraef | 0:0a2eaa300982 | 310 | case EP3OUT: |
DieterGraef | 0:0a2eaa300982 | 311 | ep_type = (flags & ISOCHRONOUS) ? EP_TYPE_ISOC : EP_TYPE_BULK; |
DieterGraef | 0:0a2eaa300982 | 312 | HAL_PCD_EP_Open(hpcd, 0x03, maxPacket, ep_type); |
DieterGraef | 0:0a2eaa300982 | 313 | break; |
DieterGraef | 0:0a2eaa300982 | 314 | case EP3IN: |
DieterGraef | 0:0a2eaa300982 | 315 | HAL_PCDEx_SetTxFiFo(hpcd,3,maxPacket); |
DieterGraef | 0:0a2eaa300982 | 316 | ep_type = (flags & ISOCHRONOUS) ? EP_TYPE_ISOC : EP_TYPE_BULK; |
DieterGraef | 0:0a2eaa300982 | 317 | HAL_PCD_EP_Open(hpcd, 0x83, maxPacket, ep_type); |
DieterGraef | 0:0a2eaa300982 | 318 | break; |
DieterGraef | 0:0a2eaa300982 | 319 | default: |
DieterGraef | 0:0a2eaa300982 | 320 | MBED_ASSERT(0); |
DieterGraef | 0:0a2eaa300982 | 321 | return false; |
DieterGraef | 0:0a2eaa300982 | 322 | } |
DieterGraef | 0:0a2eaa300982 | 323 | return true; |
DieterGraef | 0:0a2eaa300982 | 324 | } |
DieterGraef | 0:0a2eaa300982 | 325 | |
DieterGraef | 0:0a2eaa300982 | 326 | |
DieterGraef | 0:0a2eaa300982 | 327 | // read setup packet |
DieterGraef | 0:0a2eaa300982 | 328 | void USBHAL::EP0setup(uint8_t *buffer) |
DieterGraef | 0:0a2eaa300982 | 329 | { |
DieterGraef | 0:0a2eaa300982 | 330 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 331 | { |
DieterGraef | 0:0a2eaa300982 | 332 | memcpy(buffer, hpcd_USB_FS.Setup, 8); |
DieterGraef | 0:0a2eaa300982 | 333 | } |
DieterGraef | 0:0a2eaa300982 | 334 | else |
DieterGraef | 0:0a2eaa300982 | 335 | { |
DieterGraef | 0:0a2eaa300982 | 336 | memcpy(buffer, hpcd_USB_HS.Setup, 8); |
DieterGraef | 0:0a2eaa300982 | 337 | } |
DieterGraef | 0:0a2eaa300982 | 338 | } |
DieterGraef | 0:0a2eaa300982 | 339 | |
DieterGraef | 0:0a2eaa300982 | 340 | void USBHAL::EP0readStage(void) |
DieterGraef | 0:0a2eaa300982 | 341 | { |
DieterGraef | 0:0a2eaa300982 | 342 | } |
DieterGraef | 0:0a2eaa300982 | 343 | |
DieterGraef | 0:0a2eaa300982 | 344 | void USBHAL::EP0read(void) |
DieterGraef | 0:0a2eaa300982 | 345 | { |
DieterGraef | 0:0a2eaa300982 | 346 | endpointRead(EP0OUT, MAX_PACKET_SIZE_EP0); |
DieterGraef | 0:0a2eaa300982 | 347 | } |
DieterGraef | 0:0a2eaa300982 | 348 | |
DieterGraef | 0:0a2eaa300982 | 349 | |
DieterGraef | 0:0a2eaa300982 | 350 | class rxTempBufferManager |
DieterGraef | 0:0a2eaa300982 | 351 | { |
DieterGraef | 0:0a2eaa300982 | 352 | uint8_t buf0[MAX_PACKET_SIZE_EP0]; |
DieterGraef | 0:0a2eaa300982 | 353 | uint8_t buf1[MAX_PACKET_SIZE_EP1]; |
DieterGraef | 0:0a2eaa300982 | 354 | uint8_t buf2[MAX_PACKET_SIZE_EP2]; |
DieterGraef | 0:0a2eaa300982 | 355 | uint8_t buf3[MAX_PACKET_SIZE_EP3_ISO]; |
DieterGraef | 0:0a2eaa300982 | 356 | public: |
DieterGraef | 0:0a2eaa300982 | 357 | uint8_t* ptr(uint8_t endpoint, int maxPacketSize) |
DieterGraef | 0:0a2eaa300982 | 358 | { |
DieterGraef | 0:0a2eaa300982 | 359 | switch(endpoint) |
DieterGraef | 0:0a2eaa300982 | 360 | { |
DieterGraef | 0:0a2eaa300982 | 361 | case EP0OUT: |
DieterGraef | 0:0a2eaa300982 | 362 | MBED_ASSERT(maxPacketSize <= MAX_PACKET_SIZE_EP0); |
DieterGraef | 0:0a2eaa300982 | 363 | break; |
DieterGraef | 0:0a2eaa300982 | 364 | case EP1OUT: |
DieterGraef | 0:0a2eaa300982 | 365 | MBED_ASSERT(maxPacketSize <= MAX_PACKET_SIZE_EP1); |
DieterGraef | 0:0a2eaa300982 | 366 | break; |
DieterGraef | 0:0a2eaa300982 | 367 | case EP2OUT: |
DieterGraef | 0:0a2eaa300982 | 368 | MBED_ASSERT(maxPacketSize <= MAX_PACKET_SIZE_EP2); |
DieterGraef | 0:0a2eaa300982 | 369 | break; |
DieterGraef | 0:0a2eaa300982 | 370 | case EP3OUT: |
DieterGraef | 0:0a2eaa300982 | 371 | MBED_ASSERT(maxPacketSize <= MAX_PACKET_SIZE_EP3_ISO); |
DieterGraef | 0:0a2eaa300982 | 372 | break; |
DieterGraef | 0:0a2eaa300982 | 373 | } |
DieterGraef | 0:0a2eaa300982 | 374 | return ptr(endpoint); |
DieterGraef | 0:0a2eaa300982 | 375 | } |
DieterGraef | 0:0a2eaa300982 | 376 | uint8_t* ptr(uint8_t endpoint) |
DieterGraef | 0:0a2eaa300982 | 377 | { |
DieterGraef | 0:0a2eaa300982 | 378 | switch(endpoint) |
DieterGraef | 0:0a2eaa300982 | 379 | { |
DieterGraef | 0:0a2eaa300982 | 380 | case EP0OUT: |
DieterGraef | 0:0a2eaa300982 | 381 | return buf0; |
DieterGraef | 0:0a2eaa300982 | 382 | case EP1OUT: |
DieterGraef | 0:0a2eaa300982 | 383 | return buf1; |
DieterGraef | 0:0a2eaa300982 | 384 | case EP2OUT: |
DieterGraef | 0:0a2eaa300982 | 385 | return buf2; |
DieterGraef | 0:0a2eaa300982 | 386 | case EP3OUT: |
DieterGraef | 0:0a2eaa300982 | 387 | return buf3; |
DieterGraef | 0:0a2eaa300982 | 388 | } |
DieterGraef | 0:0a2eaa300982 | 389 | MBED_ASSERT(0); |
DieterGraef | 0:0a2eaa300982 | 390 | return NULL; |
DieterGraef | 0:0a2eaa300982 | 391 | } |
DieterGraef | 0:0a2eaa300982 | 392 | } rxtmp; |
DieterGraef | 0:0a2eaa300982 | 393 | |
DieterGraef | 0:0a2eaa300982 | 394 | |
DieterGraef | 0:0a2eaa300982 | 395 | uint32_t USBHAL::EP0getReadResult(uint8_t *buffer) |
DieterGraef | 0:0a2eaa300982 | 396 | { |
DieterGraef | 0:0a2eaa300982 | 397 | const uint8_t endpoint = EP0OUT; |
DieterGraef | 0:0a2eaa300982 | 398 | uint32_t length; |
DieterGraef | 0:0a2eaa300982 | 399 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 400 | { |
DieterGraef | 0:0a2eaa300982 | 401 | length = HAL_PCD_EP_GetRxCount(&hpcd_USB_FS, endpoint>>1); |
DieterGraef | 0:0a2eaa300982 | 402 | } |
DieterGraef | 0:0a2eaa300982 | 403 | else |
DieterGraef | 0:0a2eaa300982 | 404 | { |
DieterGraef | 0:0a2eaa300982 | 405 | length = HAL_PCD_EP_GetRxCount(&hpcd_USB_HS, endpoint>>1); |
DieterGraef | 0:0a2eaa300982 | 406 | } |
DieterGraef | 0:0a2eaa300982 | 407 | memcpy(buffer, rxtmp.ptr(endpoint), length); |
DieterGraef | 0:0a2eaa300982 | 408 | return length; |
DieterGraef | 0:0a2eaa300982 | 409 | } |
DieterGraef | 0:0a2eaa300982 | 410 | |
DieterGraef | 0:0a2eaa300982 | 411 | void USBHAL::EP0write(uint8_t *buffer, uint32_t size) |
DieterGraef | 0:0a2eaa300982 | 412 | { |
DieterGraef | 0:0a2eaa300982 | 413 | endpointWrite(EP0IN, buffer, size); |
DieterGraef | 0:0a2eaa300982 | 414 | } |
DieterGraef | 0:0a2eaa300982 | 415 | |
DieterGraef | 0:0a2eaa300982 | 416 | void USBHAL::EP0getWriteResult(void) |
DieterGraef | 0:0a2eaa300982 | 417 | { |
DieterGraef | 0:0a2eaa300982 | 418 | } |
DieterGraef | 0:0a2eaa300982 | 419 | |
DieterGraef | 0:0a2eaa300982 | 420 | void USBHAL::EP0stall(void) |
DieterGraef | 0:0a2eaa300982 | 421 | { |
DieterGraef | 0:0a2eaa300982 | 422 | // If we stall the out endpoint here then we have problems transferring |
DieterGraef | 0:0a2eaa300982 | 423 | // and setup requests after the (stalled) get device qualifier requests. |
DieterGraef | 0:0a2eaa300982 | 424 | // TODO: Find out if this is correct behavior, or whether we are doing |
DieterGraef | 0:0a2eaa300982 | 425 | // something else wrong |
DieterGraef | 0:0a2eaa300982 | 426 | stallEndpoint(EP0IN); |
DieterGraef | 0:0a2eaa300982 | 427 | // stallEndpoint(EP0OUT); |
DieterGraef | 0:0a2eaa300982 | 428 | } |
DieterGraef | 0:0a2eaa300982 | 429 | |
DieterGraef | 0:0a2eaa300982 | 430 | EP_STATUS USBHAL::endpointRead(uint8_t endpoint, uint32_t maximumSize) |
DieterGraef | 0:0a2eaa300982 | 431 | { |
DieterGraef | 0:0a2eaa300982 | 432 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 433 | { |
DieterGraef | 0:0a2eaa300982 | 434 | epCompleteFS &= ~(1 << endpoint); |
DieterGraef | 0:0a2eaa300982 | 435 | HAL_PCD_EP_Receive(&hpcd_USB_FS, endpoint>>1, rxtmp.ptr(endpoint, maximumSize), maximumSize); |
DieterGraef | 0:0a2eaa300982 | 436 | } |
DieterGraef | 0:0a2eaa300982 | 437 | else |
DieterGraef | 0:0a2eaa300982 | 438 | { |
DieterGraef | 0:0a2eaa300982 | 439 | epCompleteHS &= ~(1 << endpoint); |
DieterGraef | 0:0a2eaa300982 | 440 | HAL_PCD_EP_Receive(&hpcd_USB_HS, endpoint>>1, rxtmp.ptr(endpoint, maximumSize), maximumSize); |
DieterGraef | 0:0a2eaa300982 | 441 | } |
DieterGraef | 0:0a2eaa300982 | 442 | |
DieterGraef | 0:0a2eaa300982 | 443 | return EP_PENDING; |
DieterGraef | 0:0a2eaa300982 | 444 | } |
DieterGraef | 0:0a2eaa300982 | 445 | |
DieterGraef | 0:0a2eaa300982 | 446 | EP_STATUS USBHAL::endpointReadResult(uint8_t endpoint, uint8_t * buffer, uint32_t *bytesRead) |
DieterGraef | 0:0a2eaa300982 | 447 | { |
DieterGraef | 0:0a2eaa300982 | 448 | int len; |
DieterGraef | 0:0a2eaa300982 | 449 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 450 | { |
DieterGraef | 0:0a2eaa300982 | 451 | |
DieterGraef | 0:0a2eaa300982 | 452 | if (!(epCompleteFS & (1 << endpoint))) |
DieterGraef | 0:0a2eaa300982 | 453 | { |
DieterGraef | 0:0a2eaa300982 | 454 | return EP_PENDING; |
DieterGraef | 0:0a2eaa300982 | 455 | } |
DieterGraef | 0:0a2eaa300982 | 456 | |
DieterGraef | 0:0a2eaa300982 | 457 | len = HAL_PCD_EP_GetRxCount(&hpcd_USB_FS, endpoint>>1); |
DieterGraef | 0:0a2eaa300982 | 458 | } |
DieterGraef | 0:0a2eaa300982 | 459 | else |
DieterGraef | 0:0a2eaa300982 | 460 | { |
DieterGraef | 0:0a2eaa300982 | 461 | |
DieterGraef | 0:0a2eaa300982 | 462 | if (!(epCompleteHS & (1 << endpoint))) |
DieterGraef | 0:0a2eaa300982 | 463 | { |
DieterGraef | 0:0a2eaa300982 | 464 | return EP_PENDING; |
DieterGraef | 0:0a2eaa300982 | 465 | } |
DieterGraef | 0:0a2eaa300982 | 466 | |
DieterGraef | 0:0a2eaa300982 | 467 | len = HAL_PCD_EP_GetRxCount(&hpcd_USB_HS, endpoint>>1); |
DieterGraef | 0:0a2eaa300982 | 468 | } |
DieterGraef | 0:0a2eaa300982 | 469 | memcpy(buffer, rxtmp.ptr(endpoint), len); |
DieterGraef | 0:0a2eaa300982 | 470 | *bytesRead = len; |
DieterGraef | 0:0a2eaa300982 | 471 | return EP_COMPLETED; |
DieterGraef | 0:0a2eaa300982 | 472 | } |
DieterGraef | 0:0a2eaa300982 | 473 | |
DieterGraef | 0:0a2eaa300982 | 474 | EP_STATUS USBHAL::endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size) |
DieterGraef | 0:0a2eaa300982 | 475 | { |
DieterGraef | 0:0a2eaa300982 | 476 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 477 | { |
DieterGraef | 0:0a2eaa300982 | 478 | epCompleteFS &= ~(1 << endpoint); |
DieterGraef | 0:0a2eaa300982 | 479 | HAL_PCD_EP_Transmit(&hpcd_USB_FS, endpoint>>1, data, size); |
DieterGraef | 0:0a2eaa300982 | 480 | } |
DieterGraef | 0:0a2eaa300982 | 481 | else |
DieterGraef | 0:0a2eaa300982 | 482 | { |
DieterGraef | 0:0a2eaa300982 | 483 | epCompleteHS &= ~(1 << endpoint); |
DieterGraef | 0:0a2eaa300982 | 484 | HAL_PCD_EP_Transmit(&hpcd_USB_HS, endpoint>>1, data, size); |
DieterGraef | 0:0a2eaa300982 | 485 | } |
DieterGraef | 0:0a2eaa300982 | 486 | |
DieterGraef | 0:0a2eaa300982 | 487 | return EP_PENDING; |
DieterGraef | 0:0a2eaa300982 | 488 | } |
DieterGraef | 0:0a2eaa300982 | 489 | |
DieterGraef | 0:0a2eaa300982 | 490 | EP_STATUS USBHAL::endpointWriteResult(uint8_t endpoint) |
DieterGraef | 0:0a2eaa300982 | 491 | { |
DieterGraef | 0:0a2eaa300982 | 492 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 493 | { |
DieterGraef | 0:0a2eaa300982 | 494 | if (epCompleteFS & (1 << endpoint)) |
DieterGraef | 0:0a2eaa300982 | 495 | { |
DieterGraef | 0:0a2eaa300982 | 496 | epCompleteFS &= ~(1 << endpoint); |
DieterGraef | 0:0a2eaa300982 | 497 | return EP_COMPLETED; |
DieterGraef | 0:0a2eaa300982 | 498 | } |
DieterGraef | 0:0a2eaa300982 | 499 | return EP_PENDING; |
DieterGraef | 0:0a2eaa300982 | 500 | } |
DieterGraef | 0:0a2eaa300982 | 501 | else |
DieterGraef | 0:0a2eaa300982 | 502 | { |
DieterGraef | 0:0a2eaa300982 | 503 | if (epCompleteHS & (1 << endpoint)) |
DieterGraef | 0:0a2eaa300982 | 504 | { |
DieterGraef | 0:0a2eaa300982 | 505 | epCompleteHS &= ~(1 << endpoint); |
DieterGraef | 0:0a2eaa300982 | 506 | return EP_COMPLETED; |
DieterGraef | 0:0a2eaa300982 | 507 | } |
DieterGraef | 0:0a2eaa300982 | 508 | return EP_PENDING; |
DieterGraef | 0:0a2eaa300982 | 509 | } |
DieterGraef | 0:0a2eaa300982 | 510 | } |
DieterGraef | 0:0a2eaa300982 | 511 | |
DieterGraef | 0:0a2eaa300982 | 512 | void USBHAL::stallEndpoint(uint8_t endpoint) |
DieterGraef | 0:0a2eaa300982 | 513 | { |
DieterGraef | 0:0a2eaa300982 | 514 | PCD_HandleTypeDef *hpcd; |
DieterGraef | 0:0a2eaa300982 | 515 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 516 | { |
DieterGraef | 0:0a2eaa300982 | 517 | hpcd = &hpcd_USB_FS; |
DieterGraef | 0:0a2eaa300982 | 518 | } |
DieterGraef | 0:0a2eaa300982 | 519 | else |
DieterGraef | 0:0a2eaa300982 | 520 | { |
DieterGraef | 0:0a2eaa300982 | 521 | hpcd = &hpcd_USB_HS; |
DieterGraef | 0:0a2eaa300982 | 522 | } |
DieterGraef | 0:0a2eaa300982 | 523 | switch(endpoint) |
DieterGraef | 0:0a2eaa300982 | 524 | { |
DieterGraef | 0:0a2eaa300982 | 525 | case EP0IN: |
DieterGraef | 0:0a2eaa300982 | 526 | HAL_PCD_EP_SetStall(hpcd, 0x80); |
DieterGraef | 0:0a2eaa300982 | 527 | break; |
DieterGraef | 0:0a2eaa300982 | 528 | case EP0OUT: |
DieterGraef | 0:0a2eaa300982 | 529 | HAL_PCD_EP_SetStall(hpcd, 0x00); |
DieterGraef | 0:0a2eaa300982 | 530 | break; |
DieterGraef | 0:0a2eaa300982 | 531 | default: |
DieterGraef | 0:0a2eaa300982 | 532 | break; |
DieterGraef | 0:0a2eaa300982 | 533 | } |
DieterGraef | 0:0a2eaa300982 | 534 | } |
DieterGraef | 0:0a2eaa300982 | 535 | |
DieterGraef | 0:0a2eaa300982 | 536 | void USBHAL::unstallEndpoint(uint8_t endpoint) |
DieterGraef | 0:0a2eaa300982 | 537 | { |
DieterGraef | 0:0a2eaa300982 | 538 | } |
DieterGraef | 0:0a2eaa300982 | 539 | |
DieterGraef | 0:0a2eaa300982 | 540 | bool USBHAL::getEndpointStallState(uint8_t endpoint) |
DieterGraef | 0:0a2eaa300982 | 541 | { |
DieterGraef | 0:0a2eaa300982 | 542 | return false; |
DieterGraef | 0:0a2eaa300982 | 543 | } |
DieterGraef | 0:0a2eaa300982 | 544 | |
DieterGraef | 0:0a2eaa300982 | 545 | void USBHAL::remoteWakeup(void) {} |
DieterGraef | 0:0a2eaa300982 | 546 | |
DieterGraef | 0:0a2eaa300982 | 547 | void USBHAL::_usbisrFS(void) |
DieterGraef | 0:0a2eaa300982 | 548 | { |
DieterGraef | 0:0a2eaa300982 | 549 | HAL_PCD_IRQHandler(&hpcd_USB_FS); |
DieterGraef | 0:0a2eaa300982 | 550 | } |
DieterGraef | 0:0a2eaa300982 | 551 | |
DieterGraef | 0:0a2eaa300982 | 552 | void USBHAL::_usbisrHS(void) |
DieterGraef | 0:0a2eaa300982 | 553 | { |
DieterGraef | 0:0a2eaa300982 | 554 | HAL_PCD_IRQHandler(&hpcd_USB_HS); |
DieterGraef | 0:0a2eaa300982 | 555 | } |
DieterGraef | 0:0a2eaa300982 | 556 | |
DieterGraef | 0:0a2eaa300982 | 557 | void USBHAL::usbisr(void) {} |
DieterGraef | 0:0a2eaa300982 | 558 | |
DieterGraef | 0:0a2eaa300982 | 559 | void USBHAL::SetupStageCallback() |
DieterGraef | 0:0a2eaa300982 | 560 | { |
DieterGraef | 0:0a2eaa300982 | 561 | EP0setupCallback(); |
DieterGraef | 0:0a2eaa300982 | 562 | } |
DieterGraef | 0:0a2eaa300982 | 563 | |
DieterGraef | 0:0a2eaa300982 | 564 | void USBHAL::DataInStageCallback(uint8_t epnum) |
DieterGraef | 0:0a2eaa300982 | 565 | { |
DieterGraef | 0:0a2eaa300982 | 566 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 567 | { |
DieterGraef | 0:0a2eaa300982 | 568 | switch(epnum) |
DieterGraef | 0:0a2eaa300982 | 569 | { |
DieterGraef | 0:0a2eaa300982 | 570 | case 0: // EP0IN |
DieterGraef | 0:0a2eaa300982 | 571 | EP0in(); |
DieterGraef | 0:0a2eaa300982 | 572 | break; |
DieterGraef | 0:0a2eaa300982 | 573 | case 1: |
DieterGraef | 0:0a2eaa300982 | 574 | epCompleteFS |= (1<<EP1IN); |
DieterGraef | 0:0a2eaa300982 | 575 | if (EP1_IN_callback()) |
DieterGraef | 0:0a2eaa300982 | 576 | { |
DieterGraef | 0:0a2eaa300982 | 577 | epCompleteFS &= ~(1<<EP1IN); |
DieterGraef | 0:0a2eaa300982 | 578 | } |
DieterGraef | 0:0a2eaa300982 | 579 | break; |
DieterGraef | 0:0a2eaa300982 | 580 | case 2: |
DieterGraef | 0:0a2eaa300982 | 581 | epCompleteFS |= (1<<EP2IN); |
DieterGraef | 0:0a2eaa300982 | 582 | if (EP2_IN_callback()) |
DieterGraef | 0:0a2eaa300982 | 583 | { |
DieterGraef | 0:0a2eaa300982 | 584 | epCompleteFS &= ~(1<<EP2IN); |
DieterGraef | 0:0a2eaa300982 | 585 | } |
DieterGraef | 0:0a2eaa300982 | 586 | break; |
DieterGraef | 0:0a2eaa300982 | 587 | case 3: |
DieterGraef | 0:0a2eaa300982 | 588 | epCompleteFS |= (1<<EP3IN); |
DieterGraef | 0:0a2eaa300982 | 589 | if (EP3_IN_callback()) |
DieterGraef | 0:0a2eaa300982 | 590 | { |
DieterGraef | 0:0a2eaa300982 | 591 | epCompleteFS &= ~(1<<EP3IN); |
DieterGraef | 0:0a2eaa300982 | 592 | } |
DieterGraef | 0:0a2eaa300982 | 593 | break; |
DieterGraef | 0:0a2eaa300982 | 594 | default: |
DieterGraef | 0:0a2eaa300982 | 595 | MBED_ASSERT(0); |
DieterGraef | 0:0a2eaa300982 | 596 | break; |
DieterGraef | 0:0a2eaa300982 | 597 | } |
DieterGraef | 0:0a2eaa300982 | 598 | } |
DieterGraef | 0:0a2eaa300982 | 599 | else |
DieterGraef | 0:0a2eaa300982 | 600 | { |
DieterGraef | 0:0a2eaa300982 | 601 | switch(epnum) |
DieterGraef | 0:0a2eaa300982 | 602 | { |
DieterGraef | 0:0a2eaa300982 | 603 | case 0: // EP0IN |
DieterGraef | 0:0a2eaa300982 | 604 | EP0in(); |
DieterGraef | 0:0a2eaa300982 | 605 | break; |
DieterGraef | 0:0a2eaa300982 | 606 | case 1: |
DieterGraef | 0:0a2eaa300982 | 607 | epCompleteHS |= (1<<EP1IN); |
DieterGraef | 0:0a2eaa300982 | 608 | if (EP1_IN_callback()) |
DieterGraef | 0:0a2eaa300982 | 609 | { |
DieterGraef | 0:0a2eaa300982 | 610 | epCompleteHS &= ~(1<<EP1IN); |
DieterGraef | 0:0a2eaa300982 | 611 | } |
DieterGraef | 0:0a2eaa300982 | 612 | break; |
DieterGraef | 0:0a2eaa300982 | 613 | case 2: |
DieterGraef | 0:0a2eaa300982 | 614 | epCompleteHS |= (1<<EP2IN); |
DieterGraef | 0:0a2eaa300982 | 615 | if (EP2_IN_callback()) |
DieterGraef | 0:0a2eaa300982 | 616 | { |
DieterGraef | 0:0a2eaa300982 | 617 | epCompleteHS &= ~(1<<EP2IN); |
DieterGraef | 0:0a2eaa300982 | 618 | } |
DieterGraef | 0:0a2eaa300982 | 619 | break; |
DieterGraef | 0:0a2eaa300982 | 620 | case 3: |
DieterGraef | 0:0a2eaa300982 | 621 | epCompleteFS |= (1<<EP3IN); |
DieterGraef | 0:0a2eaa300982 | 622 | if (EP3_IN_callback()) |
DieterGraef | 0:0a2eaa300982 | 623 | { |
DieterGraef | 0:0a2eaa300982 | 624 | epCompleteFS &= ~(1<<EP3IN); |
DieterGraef | 0:0a2eaa300982 | 625 | } |
DieterGraef | 0:0a2eaa300982 | 626 | break; |
DieterGraef | 0:0a2eaa300982 | 627 | default: |
DieterGraef | 0:0a2eaa300982 | 628 | MBED_ASSERT(0); |
DieterGraef | 0:0a2eaa300982 | 629 | break; |
DieterGraef | 0:0a2eaa300982 | 630 | } |
DieterGraef | 0:0a2eaa300982 | 631 | } |
DieterGraef | 0:0a2eaa300982 | 632 | } |
DieterGraef | 0:0a2eaa300982 | 633 | |
DieterGraef | 0:0a2eaa300982 | 634 | void USBHAL::DataOutStageCallback(uint8_t epnum) |
DieterGraef | 0:0a2eaa300982 | 635 | { |
DieterGraef | 0:0a2eaa300982 | 636 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 637 | { |
DieterGraef | 0:0a2eaa300982 | 638 | switch(epnum) |
DieterGraef | 0:0a2eaa300982 | 639 | { |
DieterGraef | 0:0a2eaa300982 | 640 | case 0: // EP0OUT |
DieterGraef | 0:0a2eaa300982 | 641 | if ((hpcd_USB_FS.Setup[0]&0x80) == 0x00) // host to device ? |
DieterGraef | 0:0a2eaa300982 | 642 | { |
DieterGraef | 0:0a2eaa300982 | 643 | EP0out(); |
DieterGraef | 0:0a2eaa300982 | 644 | } |
DieterGraef | 0:0a2eaa300982 | 645 | |
DieterGraef | 0:0a2eaa300982 | 646 | break; |
DieterGraef | 0:0a2eaa300982 | 647 | case 1: |
DieterGraef | 0:0a2eaa300982 | 648 | epCompleteFS |= (1<<EP1OUT); |
DieterGraef | 0:0a2eaa300982 | 649 | if (EP1_OUT_callback()) |
DieterGraef | 0:0a2eaa300982 | 650 | { |
DieterGraef | 0:0a2eaa300982 | 651 | epCompleteFS &= ~(1<<EP1OUT); |
DieterGraef | 0:0a2eaa300982 | 652 | } |
DieterGraef | 0:0a2eaa300982 | 653 | break; |
DieterGraef | 0:0a2eaa300982 | 654 | case 2: |
DieterGraef | 0:0a2eaa300982 | 655 | epCompleteFS |= (1<<EP2OUT); |
DieterGraef | 0:0a2eaa300982 | 656 | if (EP2_OUT_callback()) |
DieterGraef | 0:0a2eaa300982 | 657 | { |
DieterGraef | 0:0a2eaa300982 | 658 | epCompleteFS &= ~(1<<EP2OUT); |
DieterGraef | 0:0a2eaa300982 | 659 | } |
DieterGraef | 0:0a2eaa300982 | 660 | break; |
DieterGraef | 0:0a2eaa300982 | 661 | case 3: |
DieterGraef | 0:0a2eaa300982 | 662 | epCompleteFS |= (1<<EP3OUT); |
DieterGraef | 0:0a2eaa300982 | 663 | if (EP3_OUT_callback()) |
DieterGraef | 0:0a2eaa300982 | 664 | { |
DieterGraef | 0:0a2eaa300982 | 665 | epCompleteFS &= ~(1<<EP3OUT); |
DieterGraef | 0:0a2eaa300982 | 666 | } |
DieterGraef | 0:0a2eaa300982 | 667 | break; |
DieterGraef | 0:0a2eaa300982 | 668 | default: |
DieterGraef | 0:0a2eaa300982 | 669 | MBED_ASSERT(0); |
DieterGraef | 0:0a2eaa300982 | 670 | break; |
DieterGraef | 0:0a2eaa300982 | 671 | } |
DieterGraef | 0:0a2eaa300982 | 672 | } |
DieterGraef | 0:0a2eaa300982 | 673 | else |
DieterGraef | 0:0a2eaa300982 | 674 | { |
DieterGraef | 0:0a2eaa300982 | 675 | switch(epnum) |
DieterGraef | 0:0a2eaa300982 | 676 | { |
DieterGraef | 0:0a2eaa300982 | 677 | case 0: // EP0OUT |
DieterGraef | 0:0a2eaa300982 | 678 | |
DieterGraef | 0:0a2eaa300982 | 679 | if ((hpcd_USB_HS.Setup[0]&0x80) == 0x00) // host to device ? |
DieterGraef | 0:0a2eaa300982 | 680 | { |
DieterGraef | 0:0a2eaa300982 | 681 | EP0out(); |
DieterGraef | 0:0a2eaa300982 | 682 | } |
DieterGraef | 0:0a2eaa300982 | 683 | |
DieterGraef | 0:0a2eaa300982 | 684 | break; |
DieterGraef | 0:0a2eaa300982 | 685 | case 1: |
DieterGraef | 0:0a2eaa300982 | 686 | epCompleteHS |= (1<<EP1OUT); |
DieterGraef | 0:0a2eaa300982 | 687 | if (EP1_OUT_callback()) |
DieterGraef | 0:0a2eaa300982 | 688 | { |
DieterGraef | 0:0a2eaa300982 | 689 | epCompleteHS &= ~(1<<EP1OUT); |
DieterGraef | 0:0a2eaa300982 | 690 | } |
DieterGraef | 0:0a2eaa300982 | 691 | break; |
DieterGraef | 0:0a2eaa300982 | 692 | case 2: |
DieterGraef | 0:0a2eaa300982 | 693 | epCompleteHS |= (1<<EP2OUT); |
DieterGraef | 0:0a2eaa300982 | 694 | if (EP2_OUT_callback()) |
DieterGraef | 0:0a2eaa300982 | 695 | { |
DieterGraef | 0:0a2eaa300982 | 696 | epCompleteHS &= ~(1<<EP2OUT); |
DieterGraef | 0:0a2eaa300982 | 697 | } |
DieterGraef | 0:0a2eaa300982 | 698 | break; |
DieterGraef | 0:0a2eaa300982 | 699 | case 3: |
DieterGraef | 0:0a2eaa300982 | 700 | epCompleteHS |= (1<<EP3OUT); |
DieterGraef | 0:0a2eaa300982 | 701 | if (EP3_OUT_callback()) |
DieterGraef | 0:0a2eaa300982 | 702 | { |
DieterGraef | 0:0a2eaa300982 | 703 | epCompleteHS &= ~(1<<EP3OUT); |
DieterGraef | 0:0a2eaa300982 | 704 | } |
DieterGraef | 0:0a2eaa300982 | 705 | break; |
DieterGraef | 0:0a2eaa300982 | 706 | default: |
DieterGraef | 0:0a2eaa300982 | 707 | MBED_ASSERT(0); |
DieterGraef | 0:0a2eaa300982 | 708 | break; |
DieterGraef | 0:0a2eaa300982 | 709 | } |
DieterGraef | 0:0a2eaa300982 | 710 | } |
DieterGraef | 0:0a2eaa300982 | 711 | } |
DieterGraef | 0:0a2eaa300982 | 712 | |
DieterGraef | 0:0a2eaa300982 | 713 | void USBHAL::ResetCallback() |
DieterGraef | 0:0a2eaa300982 | 714 | { |
DieterGraef | 0:0a2eaa300982 | 715 | PktBufArea.reset(); |
DieterGraef | 0:0a2eaa300982 | 716 | realiseEndpoint(EP0IN, MAX_PACKET_SIZE_EP0, 0); |
DieterGraef | 0:0a2eaa300982 | 717 | realiseEndpoint(EP0OUT, MAX_PACKET_SIZE_EP0, 0); |
DieterGraef | 0:0a2eaa300982 | 718 | } |
DieterGraef | 0:0a2eaa300982 | 719 | |
DieterGraef | 0:0a2eaa300982 | 720 | void USBHAL::SOFCallback() |
DieterGraef | 0:0a2eaa300982 | 721 | { |
DieterGraef | 0:0a2eaa300982 | 722 | if(HW_Interfaces==Fastspeed_Interface) |
DieterGraef | 0:0a2eaa300982 | 723 | { |
DieterGraef | 0:0a2eaa300982 | 724 | SOF(1); |
DieterGraef | 0:0a2eaa300982 | 725 | } |
DieterGraef | 0:0a2eaa300982 | 726 | else |
DieterGraef | 0:0a2eaa300982 | 727 | { |
DieterGraef | 0:0a2eaa300982 | 728 | SOF(1); |
DieterGraef | 0:0a2eaa300982 | 729 | } |
DieterGraef | 0:0a2eaa300982 | 730 | } |
DieterGraef | 0:0a2eaa300982 | 731 | |
DieterGraef | 0:0a2eaa300982 | 732 | void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
DieterGraef | 0:0a2eaa300982 | 733 | { |
DieterGraef | 0:0a2eaa300982 | 734 | reinterpret_cast<USBHAL*>(hpcd->pData)->SetupStageCallback(); |
DieterGraef | 0:0a2eaa300982 | 735 | } |
DieterGraef | 0:0a2eaa300982 | 736 | |
DieterGraef | 0:0a2eaa300982 | 737 | void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
DieterGraef | 0:0a2eaa300982 | 738 | { |
DieterGraef | 0:0a2eaa300982 | 739 | reinterpret_cast<USBHAL*>(hpcd->pData)->DataInStageCallback(epnum); |
DieterGraef | 0:0a2eaa300982 | 740 | } |
DieterGraef | 0:0a2eaa300982 | 741 | |
DieterGraef | 0:0a2eaa300982 | 742 | void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
DieterGraef | 0:0a2eaa300982 | 743 | { |
DieterGraef | 0:0a2eaa300982 | 744 | reinterpret_cast<USBHAL*>(hpcd->pData)->DataOutStageCallback(epnum); |
DieterGraef | 0:0a2eaa300982 | 745 | } |
DieterGraef | 0:0a2eaa300982 | 746 | |
DieterGraef | 0:0a2eaa300982 | 747 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
DieterGraef | 0:0a2eaa300982 | 748 | { |
DieterGraef | 0:0a2eaa300982 | 749 | reinterpret_cast<USBHAL*>(hpcd->pData)->ResetCallback(); |
DieterGraef | 0:0a2eaa300982 | 750 | } |
DieterGraef | 0:0a2eaa300982 | 751 | |
DieterGraef | 0:0a2eaa300982 | 752 | void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) |
DieterGraef | 0:0a2eaa300982 | 753 | { |
DieterGraef | 0:0a2eaa300982 | 754 | reinterpret_cast<USBHAL*>(hpcd->pData)->SOFCallback(); |
DieterGraef | 0:0a2eaa300982 | 755 | } |
DieterGraef | 0:0a2eaa300982 | 756 | |
DieterGraef | 0:0a2eaa300982 | 757 | void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
DieterGraef | 0:0a2eaa300982 | 758 | { |
DieterGraef | 0:0a2eaa300982 | 759 | if (hpcd->Init.low_power_enable) |
DieterGraef | 0:0a2eaa300982 | 760 | { |
DieterGraef | 0:0a2eaa300982 | 761 | SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); |
DieterGraef | 0:0a2eaa300982 | 762 | } |
DieterGraef | 0:0a2eaa300982 | 763 | } |
DieterGraef | 0:0a2eaa300982 | 764 | |
DieterGraef | 0:0a2eaa300982 | 765 | |
DieterGraef | 0:0a2eaa300982 | 766 | |
DieterGraef | 0:0a2eaa300982 | 767 | #endif |