mbed library sources

Fork of mbed-src by mbed official

Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
--- a/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_hcd.c	Tue Aug 18 15:00:09 2015 +0100
+++ b/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_hal_hcd.c	Thu Aug 20 10:45:13 2015 +0100
@@ -2,8 +2,8 @@
   ******************************************************************************
   * @file    stm32f4xx_hal_hcd.c
   * @author  MCD Application Team
-  * @version V1.3.0
-  * @date    09-March-2015
+  * @version V1.3.2
+  * @date    26-June-2015
   * @brief   HCD HAL module driver.
   *          This file provides firmware functions to manage the following 
   *          functionalities of the USB Peripheral Controller:
@@ -26,8 +26,9 @@
 
     (#)Initialize the HCD low level resources through the HAL_HCD_MspInit() API:
         (##) Enable the HCD/USB Low Level interface clock using the following macros
-             (+++) __OTGFS-OTG_CLK_ENABLE() or __OTGHS-OTG_CLK_ENABLE()
-             (+++) __OTGHSULPI_CLK_ENABLE() For High Speed Mode
+             (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+             (+++) __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); (For High Speed Mode)
+             (+++) __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE(); (For High Speed Mode)
            
         (##) Initialize the related GPIO clocks
         (##) Configure HCD pin-out
@@ -77,7 +78,8 @@
   * @{
   */
 
-/** @addtogroup HCD 
+/** @defgroup HCD HCD 
+  * @brief HCD HAL module driver
   * @{
   */
 
@@ -87,8 +89,8 @@
 /* Private define ------------------------------------------------------------*/
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
-/* Private function ----------------------------------------------------------*/
-/** @addtogroup HCD_Private_Functions
+/* Private function prototypes -----------------------------------------------*/
+/** @defgroup HCD_Private_Functions HCD Private Functions
   * @{
   */
 static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
@@ -100,12 +102,12 @@
   */
 
 /* Exported functions --------------------------------------------------------*/
-/** @addtogroup HCD_Exported_Functions
+/** @defgroup HCD_Exported_Functions HCD Exported Functions
   * @{
   */
 
-/** @addtogroup HCD_Exported_Functions_Group1
- *  @brief   Initialization and de-initialization functions 
+/** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions 
+ *  @brief    Initialization and Configuration functions 
  *
 @verbatim     
  ===============================================================================
@@ -118,14 +120,14 @@
   */
 
 /**
-  * @brief  Initialize the host driver
+  * @brief  Initialize the host driver.
   * @param  hhcd: HCD handle
   * @retval HAL status
   */
 HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
 { 
   /* Check the HCD handle allocation */
-  if(hhcd == HAL_NULL)
+  if(hhcd == NULL)
   {
     return HAL_ERROR;
   }
@@ -156,7 +158,7 @@
 }
 
 /**
-  * @brief  Initialize a host channel
+  * @brief  Initialize a host channel.
   * @param  hhcd: HCD handle
   * @param  ch_num: Channel number.
   *         This parameter can be a value from 1 to 15
@@ -212,7 +214,7 @@
 }
 
 /**
-  * @brief  Halt a host channel
+  * @brief  Halt a host channel.
   * @param  hhcd: HCD handle
   * @param  ch_num: Channel number.
   *         This parameter can be a value from 1 to 15
@@ -230,14 +232,14 @@
 }
 
 /**
-  * @brief  DeInitialize the host driver
+  * @brief  DeInitialize the host driver.
   * @param  hhcd: HCD handle
   * @retval HAL status
   */
 HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd)
 {
   /* Check the HCD handle allocation */
-  if(hhcd == HAL_NULL)
+  if(hhcd == NULL)
   {
     return HAL_ERROR;
   }
@@ -255,7 +257,7 @@
 }
 
 /**
-  * @brief  Initializes the HCD MSP.
+  * @brief  Initialize the HCD MSP.
   * @param  hhcd: HCD handle
   * @retval None
   */
@@ -267,7 +269,7 @@
 }
 
 /**
-  * @brief  DeInitializes HCD MSP.
+  * @brief  DeInitialize the HCD MSP.
   * @param  hhcd: HCD handle
   * @retval None
   */
@@ -282,14 +284,14 @@
   * @}
   */
 
-/** @addtogroup HCD_Exported_Functions_Group2
+/** @defgroup HCD_Exported_Functions_Group2 Input and Output operation functions
   *  @brief   HCD IO operation functions
   *
 @verbatim
  ===============================================================================
                       ##### IO operation functions #####
  ===============================================================================
-    This subsection provides a set of functions allowing to manage the USB Host Data 
+ [..] This subsection provides a set of functions allowing to manage the USB Host Data 
     Transfer
        
 @endverbatim
@@ -297,7 +299,7 @@
   */
   
 /**                                
-  * @brief  Submit a new URB for processing 
+  * @brief  Submit a new URB for processing. 
   * @param  hhcd: HCD handle
   * @param  ch_num: Channel number.
   *         This parameter can be a value from 1 to 15
@@ -440,7 +442,7 @@
 }
 
 /**
-  * @brief  This function handles HCD interrupt request.
+  * @brief  Handle HCD interrupt request.
   * @param  hhcd: HCD handle
   * @retval None
   */
@@ -555,7 +557,7 @@
 }
 
 /**
-  * @brief Connexion Event callback.
+  * @brief Connection Event callback.
   * @param  hhcd: HCD handle
   * @retval None
   */
@@ -567,7 +569,7 @@
 }
 
 /**
-  * @brief  Disconnexion Event callback.
+  * @brief  Disconnection Event callback.
   * @param  hhcd: HCD handle
   * @retval None
   */
@@ -604,8 +606,8 @@
   * @}
   */
 
-/** @addtogroup HCD_Exported_Functions_Group3
- *  @brief   Peripheral State functions 
+/** @defgroup HCD_Exported_Functions_Group3 Peripheral Control functions 
+ *  @brief   Management functions 
  *
 @verbatim 
  ===============================================================================
@@ -620,7 +622,7 @@
   */
 
 /**
-  * @brief  Start the host driver
+  * @brief  Start the host driver.
   * @param  hhcd: HCD handle
   * @retval HAL status
   */
@@ -634,7 +636,7 @@
 }
 
 /**
-  * @brief  Stop the host driver
+  * @brief  Stop the host driver.
   * @param  hhcd: HCD handle
   * @retval HAL status
   */
@@ -648,7 +650,7 @@
 }
 
 /**
-  * @brief  Reset the host port
+  * @brief  Reset the host port.
   * @param  hhcd: HCD handle
   * @retval HAL status
   */
@@ -661,7 +663,7 @@
   * @}
   */
 
-/** @addtogroup HCD_Exported_Functions_Group4
+/** @defgroup HCD_Exported_Functions_Group4 Peripheral State functions 
  *  @brief   Peripheral State functions 
  *
 @verbatim 
@@ -677,7 +679,7 @@
   */
 
 /**
-  * @brief  Return the HCD state
+  * @brief  Return the HCD handle state.
   * @param  hhcd: HCD handle
   * @retval HAL state
   */
@@ -687,7 +689,7 @@
 }
 
 /**
-  * @brief  Return  URB state for a channel
+  * @brief  Return  URB state for a channel.
   * @param  hhcd: HCD handle
   * @param  chnum: Channel number.
   *         This parameter can be a value from 1 to 15
@@ -698,7 +700,7 @@
   *            URB_NOTREADY/
   *            URB_NYET/ 
   *            URB_ERROR/  
-  *            URB_STALL/      
+  *            URB_STALL      
   */
 HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
 {
@@ -707,7 +709,7 @@
 
 
 /**
-  * @brief  Return the last host transfer size
+  * @brief  Return the last host transfer size.
   * @param  hhcd: HCD handle
   * @param  chnum: Channel number.
   *         This parameter can be a value from 1 to 15
@@ -719,12 +721,12 @@
 }
   
 /**
-  * @brief  Return the Host Channel state
+  * @brief  Return the Host Channel state.
   * @param  hhcd: HCD handle
   * @param  chnum: Channel number.
   *         This parameter can be a value from 1 to 15
   * @retval Host channel state
-  *          This parameter can be one of the these values:
+  *          This parameter can be one of these values:
   *            HC_IDLE/
   *            HC_XFRC/
   *            HC_HALTED/
@@ -733,7 +735,7 @@
   *            HC_STALL/ 
   *            HC_XACTERR/  
   *            HC_BBLERR/  
-  *            HC_DATATGLERR/    
+  *            HC_DATATGLERR    
   */
 HCD_HCStateTypeDef  HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
 {
@@ -741,7 +743,7 @@
 }
 
 /**
-  * @brief  Return the current Host frame number
+  * @brief  Return the current Host frame number.
   * @param  hhcd: HCD handle
   * @retval Current Host frame number
   */
@@ -751,7 +753,7 @@
 }
 
 /**
-  * @brief  Return the Host enumeration speed
+  * @brief  Return the Host enumeration speed.
   * @param  hhcd: HCD handle
   * @retval Enumeration speed
   */
@@ -759,6 +761,7 @@
 {
   return (USB_GetHostSpeed(hhcd->Instance));
 }
+
 /**
   * @}
   */
@@ -771,7 +774,7 @@
   * @{
   */
 /**
-  * @brief  This function handles Host Channel IN interrupt requests.
+  * @brief  Handle Host Channel IN interrupt requests.
   * @param  hhcd: HCD handle
   * @param  chnum: Channel number.
   *         This parameter can be a value from 1 to 15
@@ -780,6 +783,7 @@
 static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
 {
   USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
+  uint32_t tmpreg = 0;
   
   if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_AHBERR)
   {
@@ -874,8 +878,10 @@
       }
       
       /* re-activate the channel  */
-      USBx_HC(chnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS;         
-      USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;      
+      tmpreg = USBx_HC(chnum)->HCCHAR;
+      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
+      tmpreg |= USB_OTG_HCCHAR_CHENA;
+      USBx_HC(chnum)->HCCHAR = tmpreg;
     }
     __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
     HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
@@ -899,10 +905,11 @@
     else if  ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)||
               (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
     {
-      /* re-activate the channel  */
-      USBx_HC(chnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS;         
-      USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
-      
+      /* re-activate the channel */
+      tmpreg = USBx_HC(chnum)->HCCHAR;
+      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
+      tmpreg |= USB_OTG_HCCHAR_CHENA;
+      USBx_HC(chnum)->HCCHAR = tmpreg;
     }
     hhcd->hc[chnum].state = HC_NAK;
     __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
@@ -910,7 +917,7 @@
 }
 
 /**
-  * @brief  This function handles Host Channel OUT interrupt requests.
+  * @brief  Handle Host Channel OUT interrupt requests.
   * @param  hhcd: HCD handle
   * @param  chnum: Channel number.
   *         This parameter can be a value from 1 to 15
@@ -919,6 +926,7 @@
 static void HCD_HC_OUT_IRQHandler  (HCD_HandleTypeDef *hhcd, uint8_t chnum)
 {
   USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
+  uint32_t tmpreg = 0;
   
   if ((USBx_HC(chnum)->HCINT) &  USB_OTG_HCINT_AHBERR)
   {
@@ -1042,8 +1050,10 @@
       }
       
       /* re-activate the channel  */
-      USBx_HC(chnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS;         
-      USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;      
+      tmpreg = USBx_HC(chnum)->HCCHAR;
+      tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
+      tmpreg |= USB_OTG_HCCHAR_CHENA;
+      USBx_HC(chnum)->HCCHAR = tmpreg;
     }
     
     __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
@@ -1052,7 +1062,7 @@
 } 
 
 /**
-  * @brief  This function handles Rx Queue Level interrupt requests.
+  * @brief  Handle Rx Queue Level interrupt requests.
   * @param  hhcd: HCD handle
   * @retval None
   */
@@ -1063,6 +1073,7 @@
   uint32_t pktsts;
   uint32_t pktcnt; 
   uint32_t temp = 0;
+  uint32_t tmpreg = 0;
   
   temp = hhcd->Instance->GRXSTSP;
   channelnum = temp &  USB_OTG_GRXSTSP_EPNUM;  
@@ -1085,8 +1096,10 @@
       if((USBx_HC(channelnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) > 0)
       {
         /* re-activate the channel when more packets are expected */
-        USBx_HC(channelnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS; 
-        USBx_HC(channelnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
+        tmpreg = USBx_HC(channelnum)->HCCHAR;
+        tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
+        tmpreg |= USB_OTG_HCCHAR_CHENA;
+        USBx_HC(channelnum)->HCCHAR = tmpreg;
         hhcd->hc[channelnum].toggle_in ^= 1;
       }
     }
@@ -1102,7 +1115,7 @@
 }
 
 /**
-  * @brief  This function handles Host Port interrupt requests.
+  * @brief  Handle Host Port interrupt requests.
   * @param  hhcd: HCD handle
   * @retval None
   */
@@ -1186,6 +1199,10 @@
   * @}
   */
 
+/**
+  * @}
+  */
+
 #endif /* HAL_HCD_MODULE_ENABLED */
 /**
   * @}