STM32F103xB HAL User Manual
stm32f1xx_hal_pcd_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_hal_pcd_ex.c
00004   * @author  MCD Application Team
00005   * @brief   PCD Extended HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the USB Peripheral Controller:
00008   *           + Extended features functions
00009   *
00010   ******************************************************************************
00011   * @attention
00012   *
00013   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00014   * All rights reserved.</center></h2>
00015   *
00016   * This software component is licensed by ST under BSD 3-Clause license,
00017   * the "License"; You may not use this file except in compliance with the
00018   * License. You may obtain a copy of the License at:
00019   *                        opensource.org/licenses/BSD-3-Clause
00020   *
00021   ******************************************************************************
00022   */
00023 
00024 /* Includes ------------------------------------------------------------------*/
00025 #include "stm32f1xx_hal.h"
00026 
00027 /** @addtogroup STM32F1xx_HAL_Driver
00028   * @{
00029   */
00030 
00031 /** @defgroup PCDEx PCDEx
00032   * @brief PCD Extended HAL module driver
00033   * @{
00034   */
00035 
00036 #ifdef HAL_PCD_MODULE_ENABLED
00037 
00038 #if defined (USB) || defined (USB_OTG_FS)
00039 /* Private types -------------------------------------------------------------*/
00040 /* Private variables ---------------------------------------------------------*/
00041 /* Private constants ---------------------------------------------------------*/
00042 /* Private macros ------------------------------------------------------------*/
00043 /* Private functions ---------------------------------------------------------*/
00044 /* Exported functions --------------------------------------------------------*/
00045 
00046 /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
00047   * @{
00048   */
00049 
00050 /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
00051   * @brief    PCDEx control functions
00052   *
00053 @verbatim
00054  ===============================================================================
00055                  ##### Extended features functions #####
00056  ===============================================================================
00057     [..]  This section provides functions allowing to:
00058       (+) Update FIFO configuration
00059 
00060 @endverbatim
00061   * @{
00062   */
00063 #if defined (USB_OTG_FS)
00064 /**
00065   * @brief  Set Tx FIFO
00066   * @param  hpcd PCD handle
00067   * @param  fifo The number of Tx fifo
00068   * @param  size Fifo size
00069   * @retval HAL status
00070   */
00071 HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
00072 {
00073   uint8_t i;
00074   uint32_t Tx_Offset;
00075 
00076   /*  TXn min size = 16 words. (n  : Transmit FIFO index)
00077       When a TxFIFO is not used, the Configuration should be as follows:
00078           case 1 :  n > m    and Txn is not used    (n,m  : Transmit FIFO indexes)
00079          --> Txm can use the space allocated for Txn.
00080          case2  :  n < m    and Txn is not used    (n,m  : Transmit FIFO indexes)
00081          --> Txn should be configured with the minimum space of 16 words
00082      The FIFO is used optimally when used TxFIFOs are allocated in the top
00083          of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
00084      When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
00085 
00086   Tx_Offset = hpcd->Instance->GRXFSIZ;
00087 
00088   if (fifo == 0U)
00089   {
00090     hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
00091   }
00092   else
00093   {
00094     Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
00095     for (i = 0U; i < (fifo - 1U); i++)
00096     {
00097       Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
00098     }
00099 
00100     /* Multiply Tx_Size by 2 to get higher performance */
00101     hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset;
00102   }
00103 
00104   return HAL_OK;
00105 }
00106 
00107 /**
00108   * @brief  Set Rx FIFO
00109   * @param  hpcd PCD handle
00110   * @param  size Size of Rx fifo
00111   * @retval HAL status
00112   */
00113 HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
00114 {
00115   hpcd->Instance->GRXFSIZ = size;
00116 
00117   return HAL_OK;
00118 }
00119 #endif /* defined (USB_OTG_FS) */
00120 #if defined (USB)
00121 /**
00122   * @brief  Configure PMA for EP
00123   * @param  hpcd  Device instance
00124   * @param  ep_addr endpoint address
00125   * @param  ep_kind endpoint Kind
00126   *                  USB_SNG_BUF: Single Buffer used
00127   *                  USB_DBL_BUF: Double Buffer used
00128   * @param  pmaadress: EP address in The PMA: In case of single buffer endpoint
00129   *                   this parameter is 16-bit value providing the address
00130   *                   in PMA allocated to endpoint.
00131   *                   In case of double buffer endpoint this parameter
00132   *                   is a 32-bit value providing the endpoint buffer 0 address
00133   *                   in the LSB part of 32-bit value and endpoint buffer 1 address
00134   *                   in the MSB part of 32-bit value.
00135   * @retval HAL status
00136   */
00137 
00138 HAL_StatusTypeDef  HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr,
00139                                        uint16_t ep_kind, uint32_t pmaadress)
00140 {
00141   PCD_EPTypeDef *ep;
00142 
00143   /* initialize ep structure*/
00144   if ((0x80U & ep_addr) == 0x80U)
00145   {
00146     ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
00147   }
00148   else
00149   {
00150     ep = &hpcd->OUT_ep[ep_addr];
00151   }
00152 
00153   /* Here we check if the endpoint is single or double Buffer*/
00154   if (ep_kind == PCD_SNG_BUF)
00155   {
00156     /* Single Buffer */
00157     ep->doublebuffer = 0U;
00158     /* Configure the PMA */
00159     ep->pmaadress = (uint16_t)pmaadress;
00160   }
00161   else /* USB_DBL_BUF */
00162   {
00163     /* Double Buffer Endpoint */
00164     ep->doublebuffer = 1U;
00165     /* Configure the PMA */
00166     ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU);
00167     ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16);
00168   }
00169 
00170   return HAL_OK;
00171 }
00172 
00173 /**
00174   * @brief  Software Device Connection,
00175   *         this function is not required by USB OTG FS peripheral, it is used
00176   *         only by USB Device FS peripheral.
00177   * @param  hpcd PCD handle
00178   * @param  state connection state (0 : disconnected / 1: connected)
00179   * @retval None
00180   */
00181 __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
00182 {
00183   /* Prevent unused argument(s) compilation warning */
00184   UNUSED(hpcd);
00185   UNUSED(state);
00186   /* NOTE : This function Should not be modified, when the callback is needed,
00187             the HAL_PCDEx_SetConnectionState could be implemented in the user file
00188    */
00189 }
00190 #endif /* defined (USB) */
00191 
00192 /**
00193   * @brief  Send LPM message to user layer callback.
00194   * @param  hpcd PCD handle
00195   * @param  msg LPM message
00196   * @retval HAL status
00197   */
00198 __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
00199 {
00200   /* Prevent unused argument(s) compilation warning */
00201   UNUSED(hpcd);
00202   UNUSED(msg);
00203 
00204   /* NOTE : This function should not be modified, when the callback is needed,
00205             the HAL_PCDEx_LPM_Callback could be implemented in the user file
00206    */
00207 }
00208 
00209 /**
00210   * @brief  Send BatteryCharging message to user layer callback.
00211   * @param  hpcd PCD handle
00212   * @param  msg LPM message
00213   * @retval HAL status
00214   */
00215 __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
00216 {
00217   /* Prevent unused argument(s) compilation warning */
00218   UNUSED(hpcd);
00219   UNUSED(msg);
00220 
00221   /* NOTE : This function should not be modified, when the callback is needed,
00222             the HAL_PCDEx_BCD_Callback could be implemented in the user file
00223    */
00224 }
00225 
00226 /**
00227   * @}
00228   */
00229 
00230 /**
00231   * @}
00232   */
00233 #endif /* defined (USB) || defined (USB_OTG_FS) */
00234 #endif /* HAL_PCD_MODULE_ENABLED */
00235 
00236 /**
00237   * @}
00238   */
00239 
00240 /**
00241   * @}
00242   */
00243 
00244 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/