| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 | 
							- /**
 
-   ******************************************************************************
 
-   * @file            : usbh_conf.c
 
-   * @version         : v1.0_Cube
 
-   * @brief           : This file implements the board support package for the USB host library
 
-   ******************************************************************************
 
-   * COPYRIGHT(c) 2016 STMicroelectronics
 
-   *
 
-   * Redistribution and use in source and binary forms, with or without modification,
 
-   * are permitted provided that the following conditions are met:
 
-   * 1. Redistributions of source code must retain the above copyright notice,
 
-   * this list of conditions and the following disclaimer.
 
-   * 2. Redistributions in binary form must reproduce the above copyright notice,
 
-   * this list of conditions and the following disclaimer in the documentation
 
-   * and/or other materials provided with the distribution.
 
-   * 3. Neither the name of STMicroelectronics nor the names of its contributors
 
-   * may be used to endorse or promote products derived from this software
 
-   * without specific prior written permission.
 
-   *
 
-   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
-   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
-   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
-   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 
-   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
-   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
-   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
-   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
-   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
-   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-   *
 
-   ******************************************************************************
 
- */
 
- /* Includes ------------------------------------------------------------------*/
 
- #include "usbh_core.h"
 
- HCD_HandleTypeDef hhcd_USB_OTG_HS;
 
- /*******************************************************************************
 
-                        LL Driver Callbacks (HCD -> USB Host Library)
 
- *******************************************************************************/
 
- /* MSP Init */
 
- void HAL_HCD_MspInit(HCD_HandleTypeDef* hhcd)
 
- {
 
-   GPIO_InitTypeDef GPIO_InitStruct;
 
-   if(hhcd->Instance==USB_OTG_HS)
 
-   {
 
-   /* USER CODE BEGIN USB_OTG_HS_MspInit 0 */
 
-   /* USER CODE END USB_OTG_HS_MspInit 0 */
 
-   
 
-     /**USB_OTG_HS GPIO Configuration    
 
-     PB14     ------> USB_OTG_HS_DM
 
-     PB15     ------> USB_OTG_HS_DP 
 
-     */
 
-     GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
 
-     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 
-     GPIO_InitStruct.Pull = GPIO_NOPULL;
 
-     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 
-     GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;
 
-     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
-     /* Peripheral clock enable */
 
-     __USB_OTG_HS_CLK_ENABLE();
 
-     /* Peripheral interrupt init*/
 
-     HAL_NVIC_SetPriority(OTG_HS_IRQn, 0, 0);
 
-     HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
 
-   /* USER CODE BEGIN USB_OTG_HS_MspInit 1 */
 
-   /* USER CODE END USB_OTG_HS_MspInit 1 */
 
-   }
 
- }
 
- void HAL_HCD_MspDeInit(HCD_HandleTypeDef* hhcd)
 
- {
 
-   if(hhcd->Instance==USB_OTG_HS)
 
-   {
 
-   /* USER CODE BEGIN USB_OTG_HS_MspDeInit 0 */
 
-   /* USER CODE END USB_OTG_HS_MspDeInit 0 */
 
-     /* Peripheral clock disable */
 
-     __USB_OTG_HS_CLK_DISABLE();
 
-   
 
-     /**USB_OTG_HS GPIO Configuration    
 
-     PB14     ------> USB_OTG_HS_DM
 
-     PB15     ------> USB_OTG_HS_DP 
 
-     */
 
-     HAL_GPIO_DeInit(GPIOB, GPIO_PIN_14|GPIO_PIN_15);
 
-     /* Peripheral interrupt Deinit*/
 
-     HAL_NVIC_DisableIRQ(OTG_HS_IRQn);
 
-   /* USER CODE BEGIN USB_OTG_HS_MspDeInit 1 */
 
-   /* USER CODE END USB_OTG_HS_MspDeInit 1 */
 
-   }
 
- }
 
- /**
 
-   * @brief  SOF callback.
 
-   * @param  hhcd: HCD handle
 
-   * @retval None
 
-   */
 
- void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
 
- {
 
-   USBH_LL_IncTimer (hhcd->pData);
 
- }
 
- /**
 
-   * @brief  SOF callback.
 
-   * @param  hhcd: HCD handle
 
-   * @retval None
 
-   */
 
- void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
 
- {
 
-   USBH_LL_Connect(hhcd->pData);
 
- }
 
- /**
 
-   * @brief  SOF callback.
 
-   * @param  hhcd: HCD handle
 
-   * @retval None
 
-   */
 
- void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
 
- {
 
-   USBH_LL_Disconnect(hhcd->pData);
 
- } 
 
- /**
 
-   * @brief  Notify URB state change callback.
 
-   * @param  hhcd: HCD handle
 
-   * @retval None
 
-   */
 
- void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
 
- {
 
-   /* To be used with OS to sync URB state with the global state machine */
 
- #if (USBH_USE_OS == 1)   
 
-   USBH_LL_NotifyURBChange(hhcd->pData);
 
- #endif 
 
- }
 
- /*******************************************************************************
 
-                        LL Driver Interface (USB Host Library --> HCD)
 
- *******************************************************************************/
 
- /**
 
-   * @brief  USBH_LL_Init 
 
-   *         Initialize the Low Level portion of the Host driver.
 
-   * @param  phost: Host handle
 
-   * @retval USBH Status
 
-   */
 
- USBH_StatusTypeDef  USBH_LL_Init (USBH_HandleTypeDef *phost)
 
- {
 
-   /* Init USB_IP */
 
-   if (phost->id == HOST_HS) {
 
-   /* Link The driver to the stack */
 
-   hhcd_USB_OTG_HS.pData = phost;
 
-   phost->pData = &hhcd_USB_OTG_HS;
 
-   hhcd_USB_OTG_HS.Instance = USB_OTG_HS;
 
-   hhcd_USB_OTG_HS.Init.Host_channels = 12;
 
-   hhcd_USB_OTG_HS.Init.speed = HCD_SPEED_FULL;
 
-   hhcd_USB_OTG_HS.Init.dma_enable = DISABLE;
 
-   hhcd_USB_OTG_HS.Init.phy_itface = USB_OTG_EMBEDDED_PHY;
 
-   hhcd_USB_OTG_HS.Init.Sof_enable = DISABLE;
 
-   hhcd_USB_OTG_HS.Init.low_power_enable = DISABLE;
 
-   hhcd_USB_OTG_HS.Init.vbus_sensing_enable = DISABLE;
 
-   hhcd_USB_OTG_HS.Init.use_external_vbus = DISABLE;
 
-   HAL_HCD_Init(&hhcd_USB_OTG_HS);
 
-   USBH_LL_SetTimer (phost, HAL_HCD_GetCurrentFrame(&hhcd_USB_OTG_HS));
 
-   }
 
-   return USBH_OK;
 
- }
 
- /**
 
-   * @brief  USBH_LL_DeInit 
 
-   *         De-Initialize the Low Level portion of the Host driver.
 
-   * @param  phost: Host handle
 
-   * @retval USBH Status
 
-   */
 
- USBH_StatusTypeDef  USBH_LL_DeInit (USBH_HandleTypeDef *phost)
 
- {
 
-   HAL_HCD_DeInit(phost->pData);
 
-   return USBH_OK; 
 
- }
 
- /**
 
-   * @brief  USBH_LL_Start 
 
-   *         Start the Low Level portion of the Host driver.
 
-   * @param  phost: Host handle
 
-   * @retval USBH Status
 
-   */
 
- USBH_StatusTypeDef  USBH_LL_Start(USBH_HandleTypeDef *phost)
 
- {
 
-   HAL_HCD_Start(phost->pData);
 
-   return USBH_OK; 
 
- }
 
- /**
 
-   * @brief  USBH_LL_Stop 
 
-   *         Stop the Low Level portion of the Host driver.
 
-   * @param  phost: Host handle
 
-   * @retval USBH Status
 
-   */
 
- USBH_StatusTypeDef  USBH_LL_Stop (USBH_HandleTypeDef *phost)
 
- {
 
-   HAL_HCD_Stop(phost->pData);
 
-   return USBH_OK; 
 
- }
 
- /**
 
-   * @brief  USBH_LL_GetSpeed 
 
-   *         Return the USB Host Speed from the Low Level Driver.
 
-   * @param  phost: Host handle
 
-   * @retval USBH Speeds
 
-   */
 
- USBH_SpeedTypeDef USBH_LL_GetSpeed  (USBH_HandleTypeDef *phost)
 
- {
 
-   USBH_SpeedTypeDef speed = USBH_SPEED_FULL;
 
-     
 
-   switch (HAL_HCD_GetCurrentSpeed(phost->pData))
 
-   {
 
-   case 0 : 
 
-     speed = USBH_SPEED_HIGH;
 
-     break;
 
-     
 
-   case 1 : 
 
-     speed = USBH_SPEED_FULL;    
 
-     break;
 
-     
 
-   case 2 : 
 
-     speed = USBH_SPEED_LOW;    
 
-     break;
 
- 	
 
-   default:  
 
-    speed = USBH_SPEED_FULL;    
 
-     break;  
 
-   }
 
-   return  speed;
 
- }
 
- /**
 
-   * @brief  USBH_LL_ResetPort 
 
-   *         Reset the Host Port of the Low Level Driver.
 
-   * @param  phost: Host handle
 
-   * @retval USBH Status
 
-   */
 
- USBH_StatusTypeDef USBH_LL_ResetPort (USBH_HandleTypeDef *phost) 
 
- {
 
-   HAL_HCD_ResetPort(phost->pData);
 
-   return USBH_OK; 
 
- }
 
- /**
 
-   * @brief  USBH_LL_GetLastXferSize 
 
-   *         Return the last transfered packet size.
 
-   * @param  phost: Host handle
 
-   * @param  pipe: Pipe index   
 
-   * @retval Packet Size
 
-   */
 
- uint32_t USBH_LL_GetLastXferSize  (USBH_HandleTypeDef *phost, uint8_t pipe)  
 
- {
 
-   return HAL_HCD_HC_GetXferCount(phost->pData, pipe);
 
- }
 
- /**
 
-   * @brief  USBH_LL_OpenPipe 
 
-   *         Open a pipe of the Low Level Driver.
 
-   * @param  phost: Host handle
 
-   * @param  pipe_num: Pipe index
 
-   * @param  epnum: Endpoint Number
 
-   * @param  dev_address: Device USB address
 
-   * @param  speed: Device Speed 
 
-   * @param  ep_type: Endpoint Type
 
-   * @param  mps: Endpoint Max Packet Size                 
 
-   * @retval USBH Status
 
-   */
 
- USBH_StatusTypeDef   USBH_LL_OpenPipe    (USBH_HandleTypeDef *phost, 
 
-                                       uint8_t pipe_num,
 
-                                       uint8_t epnum,                                      
 
-                                       uint8_t dev_address,
 
-                                       uint8_t speed,
 
-                                       uint8_t ep_type,
 
-                                       uint16_t mps)
 
- {
 
-   HAL_HCD_HC_Init(phost->pData,
 
-                   pipe_num,
 
-                   epnum,
 
-                   dev_address,
 
-                   speed,
 
-                   ep_type,
 
-                   mps);
 
-   return USBH_OK; 
 
- }
 
- /**
 
-   * @brief  USBH_LL_ClosePipe 
 
-   *         Close a pipe of the Low Level Driver.
 
-   * @param  phost: Host handle
 
-   * @param  pipe_num: Pipe index               
 
-   * @retval USBH Status
 
-   */
 
- USBH_StatusTypeDef   USBH_LL_ClosePipe   (USBH_HandleTypeDef *phost, uint8_t pipe)   
 
- {
 
-   HAL_HCD_HC_Halt(phost->pData, pipe);
 
-   return USBH_OK; 
 
- }
 
- /**
 
-   * @brief  USBH_LL_SubmitURB 
 
-   *         Submit a new URB to the low level driver.
 
-   * @param  phost: Host handle
 
-   * @param  pipe: Pipe index    
 
-   *         This parameter can be a value from 1 to 15
 
-   * @param  direction : Channel number
 
-   *          This parameter can be one of the these values:
 
-   *           0 : Output 
 
-   *           1 : Input
 
-   * @param  ep_type : Endpoint Type
 
-   *          This parameter can be one of the these values:
 
-   *            @arg EP_TYPE_CTRL: Control type
 
-   *            @arg EP_TYPE_ISOC: Isochrounous type
 
-   *            @arg EP_TYPE_BULK: Bulk type
 
-   *            @arg EP_TYPE_INTR: Interrupt type
 
-   * @param  token : Endpoint Type
 
-   *          This parameter can be one of the these values:
 
-   *            @arg 0: PID_SETUP
 
-   *            @arg 1: PID_DATA
 
-   * @param  pbuff : pointer to URB data
 
-   * @param  length : Length of URB data
 
-   * @param  do_ping : activate do ping protocol (for high speed only)
 
-   *          This parameter can be one of the these values:
 
-   *           0 : do ping inactive 
 
-   *           1 : do ping active 
 
-   * @retval Status
 
-   */
 
- USBH_StatusTypeDef   USBH_LL_SubmitURB  (USBH_HandleTypeDef *phost, 
 
-                                             uint8_t pipe, 
 
-                                             uint8_t direction ,
 
-                                             uint8_t ep_type,  
 
-                                             uint8_t token, 
 
-                                             uint8_t* pbuff, 
 
-                                             uint16_t length,
 
-                                             uint8_t do_ping ) 
 
- {
 
-   HAL_HCD_HC_SubmitRequest (phost->pData,
 
-                             pipe, 
 
-                             direction ,
 
-                             ep_type,  
 
-                             token, 
 
-                             pbuff, 
 
-                             length,
 
-                             do_ping);
 
-   return USBH_OK;   
 
- }
 
- /**
 
-   * @brief  USBH_LL_GetURBState 
 
-   *         Get a URB state from the low level driver.
 
-   * @param  phost: Host handle
 
-   * @param  pipe: Pipe index
 
-   *         This parameter can be a value from 1 to 15
 
-   * @retval URB state
 
-   *          This parameter can be one of the these values:
 
-   *            @arg URB_IDLE
 
-   *            @arg URB_DONE
 
-   *            @arg URB_NOTREADY
 
-   *            @arg URB_NYET 
 
-   *            @arg URB_ERROR  
 
-   *            @arg URB_STALL      
 
-   */
 
- USBH_URBStateTypeDef  USBH_LL_GetURBState (USBH_HandleTypeDef *phost, uint8_t pipe) 
 
- {
 
-   return (USBH_URBStateTypeDef)HAL_HCD_HC_GetURBState (phost->pData, pipe);
 
- }
 
- /**
 
-   * @brief  USBH_LL_DriverVBUS 
 
-   *         Drive VBUS.
 
-   * @param  phost: Host handle
 
-   * @param  state : VBUS state
 
-   *          This parameter can be one of the these values:
 
-   *           0 : VBUS Active 
 
-   *           1 : VBUS Inactive
 
-   * @retval Status
 
-   */
 
- USBH_StatusTypeDef  USBH_LL_DriverVBUS (USBH_HandleTypeDef *phost, uint8_t state)
 
- { 
 
-   /* USER CODE BEGIN 0 */
 
-   /* USER CODE END 0*/     
 
-   if (phost->id == HOST_HS) 
 
-   {  
 
-     if (state == 0)	  
 
-     {
 
-       /* Drive high Charge pump */
 
-       /* ToDo: Add IOE driver control */	   
 
-       /* USER CODE BEGIN DRIVE_HIGH_CHARGE_FOR_HS */
 
-  
 
- 	  /* USER CODE END DRIVE_HIGH_CHARGE_FOR_HS */ 
 
-     }
 
-     else
 
-     {
 
-       /* Drive low Charge pump */
 
-       /* ToDo: Add IOE driver control */	
 
-       /* USER CODE BEGIN DRIVE_LOW_CHARGE_FOR_HS */
 
- 		
 
-       /* USER CODE BEGIN DRIVE_LOW_CHARGE_FOR_HS */    	 
 
-     }  
 
-   }
 
-   HAL_Delay(200);
 
-   return USBH_OK;  
 
- }
 
- /**
 
-   * @brief  USBH_LL_SetToggle 
 
-   *         Set toggle for a pipe.
 
-   * @param  phost: Host handle
 
-   * @param  pipe: Pipe index
 
-   * @param  pipe_num: Pipe index     
 
-   * @param  toggle: toggle (0/1)
 
-   * @retval Status
 
-   */
 
- USBH_StatusTypeDef   USBH_LL_SetToggle   (USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle)   
 
- {
 
-   HCD_HandleTypeDef *pHandle;
 
-   pHandle = phost->pData;
 
-   
 
-   if(pHandle->hc[pipe].ep_is_in)
 
-   {
 
-     pHandle->hc[pipe].toggle_in = toggle;
 
-   }
 
-   else
 
-   {
 
-     pHandle->hc[pipe].toggle_out = toggle;
 
-   }
 
-   
 
-   return USBH_OK; 
 
- }
 
- /**
 
-   * @brief  USBH_LL_GetToggle 
 
-   *         Return the current toggle of a pipe.
 
-   * @param  phost: Host handle
 
-   * @param  pipe: Pipe index
 
-   * @retval toggle (0/1)
 
-   */
 
- uint8_t  USBH_LL_GetToggle   (USBH_HandleTypeDef *phost, uint8_t pipe)   
 
- {
 
-   uint8_t toggle = 0;
 
-   HCD_HandleTypeDef *pHandle;
 
-   pHandle = phost->pData; 
 
-   
 
-   if(pHandle->hc[pipe].ep_is_in)
 
-   {
 
-     toggle = pHandle->hc[pipe].toggle_in;
 
-   }
 
-   else
 
-   {
 
-     toggle = pHandle->hc[pipe].toggle_out;
 
-   }
 
-   return toggle; 
 
- }
 
- /**
 
-   * @brief  USBH_Delay 
 
-   *         Delay routine for the USB Host Library
 
-   * @param  Delay: Delay in ms
 
-   * @retval None
 
-   */
 
- void  USBH_Delay (uint32_t Delay)
 
- {
 
-   HAL_Delay(Delay);  
 
- }
 
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 
 
  |