Subversion Repositories DashDisplay

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f1xx_hal_pcd_ex.c
  4.   * @author  MCD Application Team
  5.   * @version V1.0.1
  6.   * @date    31-July-2015
  7.   * @brief   Extended PCD HAL module driver.
  8.   *          This file provides firmware functions to manage the following
  9.   *          functionalities of the USB Peripheral Controller:
  10.   *           + Extended features functions: Update FIFO configuration,
  11.   *           PMA configuration for EPs  
  12.   *
  13.   ******************************************************************************
  14.   * @attention
  15.   *
  16.   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  17.   *
  18.   * Redistribution and use in source and binary forms, with or without modification,
  19.   * are permitted provided that the following conditions are met:
  20.   *   1. Redistributions of source code must retain the above copyright notice,
  21.   *      this list of conditions and the following disclaimer.
  22.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  23.   *      this list of conditions and the following disclaimer in the documentation
  24.   *      and/or other materials provided with the distribution.
  25.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  26.   *      may be used to endorse or promote products derived from this software
  27.   *      without specific prior written permission.
  28.   *
  29.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  32.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  33.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  35.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  36.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  37.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39.   *
  40.   ******************************************************************************
  41.   */
  42.  
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f1xx_hal.h"
  45.  
  46. /** @addtogroup STM32F1xx_HAL_Driver
  47.   * @{
  48.   */
  49.  
  50. #ifdef HAL_PCD_MODULE_ENABLED
  51.  
  52. #if defined(STM32F102x6) || defined(STM32F102xB) || \
  53.     defined(STM32F103x6) || defined(STM32F103xB) || \
  54.     defined(STM32F103xE) || defined(STM32F103xG) || \
  55.     defined(STM32F105xC) || defined(STM32F107xC)
  56.  
  57.  
  58. /** @defgroup PCDEx PCDEx
  59.   * @brief PCD Extended HAL module driver
  60.   * @{
  61.   */
  62.  
  63.  
  64. /* Private types -------------------------------------------------------------*/
  65. /* Private variables ---------------------------------------------------------*/
  66. /* Private constants ---------------------------------------------------------*/
  67. /* Private macros ------------------------------------------------------------*/
  68. /* Private functions ---------------------------------------------------------*/
  69. /* Exported functions --------------------------------------------------------*/
  70. /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
  71.   * @{
  72.   */
  73.  
  74. /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
  75.   * @brief    PCDEx control functions
  76.   *
  77. @verbatim
  78.  ===============================================================================
  79.               ##### Extended Peripheral Control functions #####
  80.  ===============================================================================
  81.     [..]  This section provides functions allowing to:
  82.       (+) Update FIFO (USB_OTG_FS)
  83.       (+) Update PMA configuration (USB)
  84.  
  85. @endverbatim
  86.   * @{
  87.   */
  88.  
  89. #if defined (USB_OTG_FS)
  90. /**
  91.   * @brief  Set Tx FIFO
  92.   * @param  hpcd: PCD handle
  93.   * @param  fifo: The number of Tx fifo
  94.   * @param  size: Fifo size
  95.   * @retval HAL status
  96.   */
  97. HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
  98. {
  99.   uint8_t index = 0;
  100.   uint32_t Tx_Offset = 0;
  101.  
  102.   /*  TXn min size = 16 words. (n  : Transmit FIFO index)
  103.       When a TxFIFO is not used, the Configuration should be as follows:
  104.           case 1 :  n > m    and Txn is not used    (n,m  : Transmit FIFO indexes)
  105.          --> Txm can use the space allocated for Txn.
  106.          case2  :  n < m    and Txn is not used    (n,m  : Transmit FIFO indexes)
  107.          --> Txn should be configured with the minimum space of 16 words
  108.      The FIFO is used optimally when used TxFIFOs are allocated in the top
  109.          of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
  110.      When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
  111.  
  112.   Tx_Offset = hpcd->Instance->GRXFSIZ;
  113.  
  114.   if(fifo == 0)
  115.   {
  116.     hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (size << 16) | Tx_Offset;
  117.   }
  118.   else
  119.   {
  120.     Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
  121.     for (index = 0; index < (fifo - 1); index++)
  122.     {
  123.       Tx_Offset += (hpcd->Instance->DIEPTXF[index] >> 16);
  124.     }
  125.    
  126.     /* Multiply Tx_Size by 2 to get higher performance */
  127.     hpcd->Instance->DIEPTXF[fifo - 1] = (size << 16) | Tx_Offset;
  128.    
  129.   }
  130.  
  131.   return HAL_OK;
  132. }
  133.  
  134. /**
  135.   * @brief  Set Rx FIFO
  136.   * @param  hpcd: PCD handle
  137.   * @param  size: Size of Rx fifo
  138.   * @retval HAL status
  139.   */
  140. HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
  141. {
  142.   hpcd->Instance->GRXFSIZ = size;
  143.   return HAL_OK;
  144. }
  145. #endif /* USB_OTG_FS */
  146.  
  147. #if defined (USB)
  148. /**
  149.   * @brief  Configure PMA for EP
  150.   * @param  hpcd : Device instance
  151.   * @param  ep_addr: endpoint address
  152.   * @param  ep_kind: endpoint Kind
  153.   *                  USB_SNG_BUF: Single Buffer used
  154.   *                  USB_DBL_BUF: Double Buffer used
  155.   * @param  pmaadress: EP address in The PMA: In case of single buffer endpoint
  156.   *                   this parameter is 16-bit value providing the address
  157.   *                   in PMA allocated to endpoint.
  158.   *                   In case of double buffer endpoint this parameter
  159.   *                   is a 32-bit value providing the endpoint buffer 0 address
  160.   *                   in the LSB part of 32-bit value and endpoint buffer 1 address
  161.   *                   in the MSB part of 32-bit value.
  162.   * @retval HAL status
  163.   */
  164.  
  165. HAL_StatusTypeDef  HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd,
  166.                                        uint16_t ep_addr,
  167.                                        uint16_t ep_kind,
  168.                                        uint32_t pmaadress)
  169.  
  170. {
  171.   PCD_EPTypeDef *ep = NULL;
  172.  
  173.   /* initialize ep structure*/
  174.   if ((0x80 & ep_addr) == 0x80)
  175.   {
  176.     ep = &hpcd->IN_ep[ep_addr & 0x7F];
  177.   }
  178.   else
  179.   {
  180.     ep = &hpcd->OUT_ep[ep_addr];
  181.   }
  182.  
  183.   /* Here we check if the endpoint is single or double Buffer*/
  184.   if (ep_kind == PCD_SNG_BUF)
  185.   {
  186.     /*Single Buffer*/
  187.     ep->doublebuffer = 0;
  188.     /*Configure te PMA*/
  189.     ep->pmaadress = (uint16_t)pmaadress;
  190.   }
  191.   else /*USB_DBL_BUF*/
  192.   {
  193.     /*Double Buffer Endpoint*/
  194.     ep->doublebuffer = 1;
  195.     /*Configure the PMA*/
  196.     ep->pmaaddr0 =  pmaadress & 0xFFFF;
  197.     ep->pmaaddr1 =  (pmaadress & 0xFFFF0000) >> 16;
  198.   }
  199.  
  200.   return HAL_OK;
  201. }
  202. #endif /* USB */
  203. /**
  204.   * @}
  205.   */
  206.  
  207. /** @defgroup PCDEx_Exported_Functions_Group2 Peripheral State functions
  208.   * @brief    Manage device connection state  
  209.   * @{
  210.   */
  211. /**
  212.   * @brief  Software Device Connection,  
  213.   *         this function is not required by USB OTG FS peripheral, it is used
  214.   *         only by USB Device FS peripheral.
  215.   * @param  hpcd: PCD handle
  216.   * @param  state: connection state (0 : disconnected / 1: connected)
  217.   * @retval None
  218.   */
  219. __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
  220. {
  221.   /* NOTE : This function Should not be modified, when the callback is needed,
  222.             the HAL_PCDEx_SetConnectionState could be implemented in the user file
  223.    */
  224. }
  225. /**
  226.   * @}
  227.   */
  228.  
  229. /**
  230.   * @}
  231.   */
  232.  
  233. /**
  234.   * @}
  235.   */
  236.  
  237. #endif /* STM32F102x6 || STM32F102xB || */
  238.        /* STM32F103x6 || STM32F103xB || */
  239.        /* STM32F103xE || STM32F103xG || */
  240.        /* STM32F105xC || STM32F107xC    */
  241.  
  242. #endif /* HAL_PCD_MODULE_ENABLED */
  243.  
  244.  
  245. /**
  246.   * @}
  247.   */
  248.  
  249. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  250.