Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG_patch mbed-rtos mbed
usbh_conf.c
00001 /** 00002 ****************************************************************************** 00003 * @file usbh_conf.c 00004 * @author MCD Application Team 00005 * @version V1.1.0 00006 * @date 21-September-2015 00007 * @brief USB Host configuration file. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Includes ------------------------------------------------------------------*/ 00039 #include "stm32f7xx_hal.h" 00040 #include "usbh_core.h" 00041 00042 HCD_HandleTypeDef hhcd; 00043 00044 /******************************************************************************* 00045 HCD BSP Routines 00046 *******************************************************************************/ 00047 /** 00048 * @brief Initializes the HCD MSP. 00049 * @param hhcd: HCD handle 00050 * @retval None 00051 */ 00052 void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd) 00053 { 00054 GPIO_InitTypeDef GPIO_InitStruct; 00055 00056 /* Configure USB HS GPIOs */ 00057 __HAL_RCC_GPIOA_CLK_ENABLE(); 00058 __HAL_RCC_GPIOB_CLK_ENABLE(); 00059 __HAL_RCC_GPIOC_CLK_ENABLE(); 00060 __HAL_RCC_GPIOH_CLK_ENABLE(); 00061 00062 /* CLK */ 00063 GPIO_InitStruct.Pin = GPIO_PIN_5; 00064 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00065 GPIO_InitStruct.Pull = GPIO_NOPULL; 00066 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00067 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; 00068 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00069 00070 /* D0 */ 00071 GPIO_InitStruct.Pin = GPIO_PIN_3; 00072 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00073 GPIO_InitStruct.Pull = GPIO_NOPULL; 00074 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; 00075 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; 00076 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 00077 00078 /* D1 D2 D3 D4 D5 D6 D7 */ 00079 GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |\ 00080 GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13; 00081 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00082 GPIO_InitStruct.Pull = GPIO_NOPULL; 00083 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; 00084 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 00085 00086 /* STP */ 00087 GPIO_InitStruct.Pin = GPIO_PIN_0; 00088 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00089 GPIO_InitStruct.Pull = GPIO_NOPULL; 00090 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; 00091 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 00092 00093 /* NXT */ 00094 GPIO_InitStruct.Pin = GPIO_PIN_4; 00095 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00096 GPIO_InitStruct.Pull = GPIO_NOPULL; 00097 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; 00098 HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); 00099 00100 /* DIR */ 00101 GPIO_InitStruct.Pin = GPIO_PIN_2; 00102 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00103 GPIO_InitStruct.Pull = GPIO_NOPULL; 00104 GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; 00105 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 00106 00107 __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE(); 00108 00109 /* Enable USB HS Clocks */ 00110 __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); 00111 00112 /* Set USBHS Interrupt priority */ 00113 HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0); 00114 00115 /* Enable USBHS Interrupt */ 00116 HAL_NVIC_EnableIRQ(OTG_HS_IRQn); 00117 } 00118 00119 /** 00120 * @brief DeInitializes the HCD MSP. 00121 * @param hhcd: HCD handle 00122 * @retval None 00123 */ 00124 void HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd) 00125 { 00126 /* Disable USB HS Clocks */ 00127 __HAL_RCC_USB_OTG_HS_CLK_DISABLE(); 00128 __HAL_RCC_USB_OTG_HS_ULPI_CLK_DISABLE(); 00129 } 00130 00131 /******************************************************************************* 00132 LL Driver Callbacks (HCD -> USB Host Library) 00133 *******************************************************************************/ 00134 00135 /** 00136 * @brief SOF callback. 00137 * @param hhcd: HCD handle 00138 * @retval None 00139 */ 00140 void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd) 00141 { 00142 USBH_LL_IncTimer(hhcd->pData); 00143 } 00144 00145 /** 00146 * @brief Connect callback. 00147 * @param hhcd: HCD handle 00148 * @retval None 00149 */ 00150 void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) 00151 { 00152 00153 USBH_LL_Connect(hhcd->pData); 00154 00155 HAL_Delay(100); 00156 } 00157 00158 /** 00159 * @brief Disconnect callback. 00160 * @param hhcd: HCD handle 00161 * @retval None 00162 */ 00163 void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) 00164 { 00165 USBH_LL_Disconnect(hhcd->pData); 00166 } 00167 00168 00169 /** 00170 * @brief Notify URB state change callback. 00171 * @param hhcd: HCD handle 00172 * @param chnum: Channel number 00173 * @param urb_state: URB State 00174 * @retval None 00175 */ 00176 void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state) 00177 { 00178 #if (USBH_USE_OS == 1) 00179 USBH_LL_NotifyURBChange(hhcd->pData); 00180 #endif 00181 } 00182 00183 /******************************************************************************* 00184 LL Driver Interface (USB Host Library --> HCD) 00185 *******************************************************************************/ 00186 00187 /** 00188 * @brief Initializes the Low Level portion of the Host driver. 00189 * @param phost: Host handle 00190 * @retval USBH Status 00191 */ 00192 USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost) 00193 { 00194 /* Set the LL driver parameters */ 00195 hhcd.Instance = USB_OTG_HS; 00196 hhcd.Init.Host_channels = 11; 00197 hhcd.Init.dma_enable = 0; 00198 hhcd.Init.low_power_enable = 0; 00199 hhcd.Init.phy_itface = HCD_PHY_ULPI; 00200 hhcd.Init.Sof_enable = 0; 00201 hhcd.Init.speed = HCD_SPEED_HIGH; 00202 hhcd.Init.vbus_sensing_enable = 1; 00203 hhcd.Init.use_external_vbus = 1; 00204 /* Link the driver to the stack */ 00205 hhcd.pData = phost; 00206 phost->pData = &hhcd; 00207 /* Initialize the LL driver */ 00208 HAL_HCD_Init(&hhcd); 00209 00210 00211 USBH_LL_SetTimer(phost, HAL_HCD_GetCurrentFrame(&hhcd)); 00212 00213 return USBH_OK; 00214 } 00215 00216 00217 /** 00218 * @brief De-Initializes the Low Level portion of the Host driver. 00219 * @param phost: Host handle 00220 * @retval USBH Status 00221 */ 00222 USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost) 00223 { 00224 HAL_HCD_DeInit(phost->pData); 00225 return USBH_OK; 00226 } 00227 00228 /** 00229 * @brief Starts the Low Level portion of the Host driver. 00230 * @param phost: Host handle 00231 * @retval USBH Status 00232 */ 00233 USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost) 00234 { 00235 HAL_HCD_Start(phost->pData); 00236 return USBH_OK; 00237 } 00238 00239 /** 00240 * @brief Stops the Low Level portion of the Host driver. 00241 * @param phost: Host handle 00242 * @retval USBH Status 00243 */ 00244 USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost) 00245 { 00246 HAL_HCD_Stop(phost->pData); 00247 return USBH_OK; 00248 } 00249 00250 /** 00251 * @brief Returns the USB Host Speed from the Low Level Driver. 00252 * @param phost: Host handle 00253 * @retval USBH Speeds 00254 */ 00255 USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost) 00256 { 00257 USBH_SpeedTypeDef speed = USBH_SPEED_FULL; 00258 00259 switch (HAL_HCD_GetCurrentSpeed(phost->pData)) 00260 { 00261 case 0: 00262 speed = USBH_SPEED_HIGH; 00263 break; 00264 00265 case 1: 00266 speed = USBH_SPEED_FULL; 00267 break; 00268 00269 case 2: 00270 speed = USBH_SPEED_LOW; 00271 break; 00272 00273 default: 00274 speed = USBH_SPEED_FULL; 00275 break; 00276 } 00277 return speed; 00278 } 00279 00280 /** 00281 * @brief Resets the Host Port of the Low Level Driver. 00282 * @param phost: Host handle 00283 * @retval USBH Status 00284 */ 00285 USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost) 00286 { 00287 HAL_HCD_ResetPort(phost->pData); 00288 return USBH_OK; 00289 } 00290 00291 /** 00292 * @brief Returns the last transfered packet size. 00293 * @param phost: Host handle 00294 * @param pipe: Pipe index 00295 * @retval Packet Size 00296 */ 00297 uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost, uint8_t pipe) 00298 { 00299 return HAL_HCD_HC_GetXferCount(phost->pData, pipe); 00300 } 00301 00302 /** 00303 * @brief Opens a pipe of the Low Level Driver. 00304 * @param phost: Host handle 00305 * @param pipe: Pipe index 00306 * @param epnum: Endpoint Number 00307 * @param dev_address: Device USB address 00308 * @param speed: Device Speed 00309 * @param ep_type: Endpoint Type 00310 * @param mps: Endpoint Max Packet Size 00311 * @retval USBH Status 00312 */ 00313 USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost, 00314 uint8_t pipe, 00315 uint8_t epnum, 00316 uint8_t dev_address, 00317 uint8_t speed, 00318 uint8_t ep_type, 00319 uint16_t mps) 00320 { 00321 HAL_HCD_HC_Init(phost->pData, 00322 pipe, 00323 epnum, 00324 dev_address, 00325 speed, 00326 ep_type, 00327 mps); 00328 return USBH_OK; 00329 } 00330 00331 /** 00332 * @brief Closes a pipe of the Low Level Driver. 00333 * @param phost: Host handle 00334 * @param pipe: Pipe index 00335 * @retval USBH Status 00336 */ 00337 USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe) 00338 { 00339 HAL_HCD_HC_Halt(phost->pData, pipe); 00340 return USBH_OK; 00341 } 00342 00343 /** 00344 * @brief Submits a new URB to the low level driver. 00345 * @param phost: Host handle 00346 * @param pipe: Pipe index 00347 * This parameter can be a value from 1 to 15 00348 * @param direction: Channel number 00349 * This parameter can be one of these values: 00350 * 0: Output 00351 * 1: Input 00352 * @param ep_type: Endpoint Type 00353 * This parameter can be one of these values: 00354 * @arg EP_TYPE_CTRL: Control type 00355 * @arg EP_TYPE_ISOC: Isochrounous type 00356 * @arg EP_TYPE_BULK: Bulk type 00357 * @arg EP_TYPE_INTR: Interrupt type 00358 * @param token: Endpoint Type 00359 * This parameter can be one of these values: 00360 * @arg 0: PID_SETUP 00361 * @arg 1: PID_DATA 00362 * @param pbuff: pointer to URB data 00363 * @param length: length of URB data 00364 * @param do_ping: activate do ping protocol (for high speed only) 00365 * This parameter can be one of these values: 00366 * 0: do ping inactive 00367 * 1: do ping active 00368 * @retval USBH Status 00369 */ 00370 USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost, 00371 uint8_t pipe, 00372 uint8_t direction, 00373 uint8_t ep_type, 00374 uint8_t token, 00375 uint8_t* pbuff, 00376 uint16_t length, 00377 uint8_t do_ping) 00378 { 00379 HAL_HCD_HC_SubmitRequest(phost->pData, 00380 pipe, 00381 direction, 00382 ep_type, 00383 token, 00384 pbuff, 00385 length, 00386 do_ping); 00387 return USBH_OK; 00388 } 00389 00390 /** 00391 * @brief Gets a URB state from the low level driver. 00392 * @param phost: Host handle 00393 * @param pipe: Pipe index 00394 * This parameter can be a value from 1 to 15 00395 * @retval URB state 00396 * This parameter can be one of these values: 00397 * @arg URB_IDLE 00398 * @arg URB_DONE 00399 * @arg URB_NOTREADY 00400 * @arg URB_NYET 00401 * @arg URB_ERROR 00402 * @arg URB_STALL 00403 */ 00404 USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t pipe) 00405 { 00406 return (USBH_URBStateTypeDef)HAL_HCD_HC_GetURBState (phost->pData, pipe); 00407 } 00408 00409 /** 00410 * @brief Drives VBUS. 00411 * @param phost: Host handle 00412 * @param state: VBUS state 00413 * This parameter can be one of these values: 00414 * 0: VBUS Active 00415 * 1: VBUS Inactive 00416 * @retval USBH Status 00417 */ 00418 USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state) 00419 { 00420 /* VBUS driven by ULPI interface */ 00421 HAL_Delay(200); 00422 return USBH_OK; 00423 } 00424 00425 /** 00426 * @brief Sets toggle for a pipe. 00427 * @param phost: Host handle 00428 * @param pipe: Pipe index 00429 * @param toggle: toggle (0/1) 00430 * @retval USBH Status 00431 */ 00432 USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle) 00433 { 00434 if(hhcd.hc[pipe].ep_is_in) 00435 { 00436 hhcd.hc[pipe].toggle_in = toggle; 00437 } 00438 else 00439 { 00440 hhcd.hc[pipe].toggle_out = toggle; 00441 } 00442 return USBH_OK; 00443 } 00444 00445 /** 00446 * @brief Returns the current toggle of a pipe. 00447 * @param phost: Host handle 00448 * @param pipe: Pipe index 00449 * @retval toggle (0/1) 00450 */ 00451 uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe) 00452 { 00453 uint8_t toggle = 0; 00454 00455 if(hhcd.hc[pipe].ep_is_in) 00456 { 00457 toggle = hhcd.hc[pipe].toggle_in; 00458 } 00459 else 00460 { 00461 toggle = hhcd.hc[pipe].toggle_out; 00462 } 00463 return toggle; 00464 } 00465 00466 /** 00467 * @brief Delay routine for the USB Host Library 00468 * @param Delay: Delay in ms 00469 * @retval None 00470 */ 00471 void USBH_Delay(uint32_t Delay) 00472 { 00473 HAL_Delay(Delay); 00474 } 00475 00476 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 14:58:20 by
1.7.2