Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file stm32f1xx_hal_pcd_ex.c |
||
| 4 | * @author MCD Application Team |
||
| 5 | * @brief PCD Extended HAL module driver. |
||
| 6 | * This file provides firmware functions to manage the following |
||
| 7 | * functionalities of the USB Peripheral Controller: |
||
| 8 | * + Extended features functions |
||
| 9 | * |
||
| 10 | ****************************************************************************** |
||
| 11 | * @attention |
||
| 12 | * |
||
| 13 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
||
| 14 | * All rights reserved.</center></h2> |
||
| 15 | * |
||
| 16 | * This software component is licensed by ST under BSD 3-Clause license, |
||
| 17 | * the "License"; You may not use this file except in compliance with the |
||
| 18 | * License. You may obtain a copy of the License at: |
||
| 19 | * opensource.org/licenses/BSD-3-Clause |
||
| 20 | * |
||
| 21 | ****************************************************************************** |
||
| 22 | */ |
||
| 23 | |||
| 24 | /* Includes ------------------------------------------------------------------*/ |
||
| 25 | #include "stm32f1xx_hal.h" |
||
| 26 | |||
| 27 | /** @addtogroup STM32F1xx_HAL_Driver |
||
| 28 | * @{ |
||
| 29 | */ |
||
| 30 | |||
| 31 | /** @defgroup PCDEx PCDEx |
||
| 32 | * @brief PCD Extended HAL module driver |
||
| 33 | * @{ |
||
| 34 | */ |
||
| 35 | |||
| 36 | #ifdef HAL_PCD_MODULE_ENABLED |
||
| 37 | |||
| 38 | #if defined (USB) || defined (USB_OTG_FS) |
||
| 39 | /* Private types -------------------------------------------------------------*/ |
||
| 40 | /* Private variables ---------------------------------------------------------*/ |
||
| 41 | /* Private constants ---------------------------------------------------------*/ |
||
| 42 | /* Private macros ------------------------------------------------------------*/ |
||
| 43 | /* Private functions ---------------------------------------------------------*/ |
||
| 44 | /* Exported functions --------------------------------------------------------*/ |
||
| 45 | |||
| 46 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions |
||
| 47 | * @{ |
||
| 48 | */ |
||
| 49 | |||
| 50 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions |
||
| 51 | * @brief PCDEx control functions |
||
| 52 | * |
||
| 53 | @verbatim |
||
| 54 | =============================================================================== |
||
| 55 | ##### Extended features functions ##### |
||
| 56 | =============================================================================== |
||
| 57 | [..] This section provides functions allowing to: |
||
| 58 | (+) Update FIFO configuration |
||
| 59 | |||
| 60 | @endverbatim |
||
| 61 | * @{ |
||
| 62 | */ |
||
| 63 | #if defined (USB_OTG_FS) |
||
| 64 | /** |
||
| 65 | * @brief Set Tx FIFO |
||
| 66 | * @param hpcd PCD handle |
||
| 67 | * @param fifo The number of Tx fifo |
||
| 68 | * @param size Fifo size |
||
| 69 | * @retval HAL status |
||
| 70 | */ |
||
| 71 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) |
||
| 72 | { |
||
| 73 | uint8_t i; |
||
| 74 | uint32_t Tx_Offset; |
||
| 75 | |||
| 76 | /* TXn min size = 16 words. (n : Transmit FIFO index) |
||
| 77 | When a TxFIFO is not used, the Configuration should be as follows: |
||
| 78 | case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) |
||
| 79 | --> Txm can use the space allocated for Txn. |
||
| 80 | case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) |
||
| 81 | --> Txn should be configured with the minimum space of 16 words |
||
| 82 | The FIFO is used optimally when used TxFIFOs are allocated in the top |
||
| 83 | of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. |
||
| 84 | When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */ |
||
| 85 | |||
| 86 | Tx_Offset = hpcd->Instance->GRXFSIZ; |
||
| 87 | |||
| 88 | if (fifo == 0U) |
||
| 89 | { |
||
| 90 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset; |
||
| 91 | } |
||
| 92 | else |
||
| 93 | { |
||
| 94 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16; |
||
| 95 | for (i = 0U; i < (fifo - 1U); i++) |
||
| 96 | { |
||
| 97 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16); |
||
| 98 | } |
||
| 99 | |||
| 100 | /* Multiply Tx_Size by 2 to get higher performance */ |
||
| 101 | hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset; |
||
| 102 | } |
||
| 103 | |||
| 104 | return HAL_OK; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @brief Set Rx FIFO |
||
| 109 | * @param hpcd PCD handle |
||
| 110 | * @param size Size of Rx fifo |
||
| 111 | * @retval HAL status |
||
| 112 | */ |
||
| 113 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) |
||
| 114 | { |
||
| 115 | hpcd->Instance->GRXFSIZ = size; |
||
| 116 | |||
| 117 | return HAL_OK; |
||
| 118 | } |
||
| 119 | #endif /* defined (USB_OTG_FS) */ |
||
| 120 | #if defined (USB) |
||
| 121 | /** |
||
| 122 | * @brief Configure PMA for EP |
||
| 123 | * @param hpcd Device instance |
||
| 124 | * @param ep_addr endpoint address |
||
| 125 | * @param ep_kind endpoint Kind |
||
| 126 | * USB_SNG_BUF: Single Buffer used |
||
| 127 | * USB_DBL_BUF: Double Buffer used |
||
| 128 | * @param pmaadress: EP address in The PMA: In case of single buffer endpoint |
||
| 129 | * this parameter is 16-bit value providing the address |
||
| 130 | * in PMA allocated to endpoint. |
||
| 131 | * In case of double buffer endpoint this parameter |
||
| 132 | * is a 32-bit value providing the endpoint buffer 0 address |
||
| 133 | * in the LSB part of 32-bit value and endpoint buffer 1 address |
||
| 134 | * in the MSB part of 32-bit value. |
||
| 135 | * @retval HAL status |
||
| 136 | */ |
||
| 137 | |||
| 138 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, |
||
| 139 | uint16_t ep_addr, |
||
| 140 | uint16_t ep_kind, |
||
| 141 | uint32_t pmaadress) |
||
| 142 | { |
||
| 143 | PCD_EPTypeDef *ep; |
||
| 144 | |||
| 145 | /* initialize ep structure*/ |
||
| 146 | if ((0x80U & ep_addr) == 0x80U) |
||
| 147 | { |
||
| 148 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
||
| 149 | } |
||
| 150 | else |
||
| 151 | { |
||
| 152 | ep = &hpcd->OUT_ep[ep_addr]; |
||
| 153 | } |
||
| 154 | |||
| 155 | /* Here we check if the endpoint is single or double Buffer*/ |
||
| 156 | if (ep_kind == PCD_SNG_BUF) |
||
| 157 | { |
||
| 158 | /* Single Buffer */ |
||
| 159 | ep->doublebuffer = 0U; |
||
| 160 | /* Configure the PMA */ |
||
| 161 | ep->pmaadress = (uint16_t)pmaadress; |
||
| 162 | } |
||
| 163 | else /* USB_DBL_BUF */ |
||
| 164 | { |
||
| 165 | /* Double Buffer Endpoint */ |
||
| 166 | ep->doublebuffer = 1U; |
||
| 167 | /* Configure the PMA */ |
||
| 168 | ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU); |
||
| 169 | ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16); |
||
| 170 | } |
||
| 171 | |||
| 172 | return HAL_OK; |
||
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @brief Software Device Connection, |
||
| 177 | * this function is not required by USB OTG FS peripheral, it is used |
||
| 178 | * only by USB Device FS peripheral. |
||
| 179 | * @param hpcd: PCD handle |
||
| 180 | * @param state: connection state (0 : disconnected / 1: connected) |
||
| 181 | * @retval None |
||
| 182 | */ |
||
| 183 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) |
||
| 184 | { |
||
| 185 | /* Prevent unused argument(s) compilation warning */ |
||
| 186 | UNUSED(hpcd); |
||
| 187 | UNUSED(state); |
||
| 188 | /* NOTE : This function Should not be modified, when the callback is needed, |
||
| 189 | the HAL_PCDEx_SetConnectionState could be implemented in the user file |
||
| 190 | */ |
||
| 191 | } |
||
| 192 | #endif /* defined (USB) */ |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @brief Send LPM message to user layer callback. |
||
| 196 | * @param hpcd PCD handle |
||
| 197 | * @param msg LPM message |
||
| 198 | * @retval HAL status |
||
| 199 | */ |
||
| 200 | __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) |
||
| 201 | { |
||
| 202 | /* Prevent unused argument(s) compilation warning */ |
||
| 203 | UNUSED(hpcd); |
||
| 204 | UNUSED(msg); |
||
| 205 | |||
| 206 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 207 | the HAL_PCDEx_LPM_Callback could be implemented in the user file |
||
| 208 | */ |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @brief Send BatteryCharging message to user layer callback. |
||
| 213 | * @param hpcd PCD handle |
||
| 214 | * @param msg LPM message |
||
| 215 | * @retval HAL status |
||
| 216 | */ |
||
| 217 | __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg) |
||
| 218 | { |
||
| 219 | /* Prevent unused argument(s) compilation warning */ |
||
| 220 | UNUSED(hpcd); |
||
| 221 | UNUSED(msg); |
||
| 222 | |||
| 223 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 224 | the HAL_PCDEx_BCD_Callback could be implemented in the user file |
||
| 225 | */ |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @} |
||
| 230 | */ |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @} |
||
| 234 | */ |
||
| 235 | #endif /* defined (USB) || defined (USB_OTG_FS) */ |
||
| 236 | #endif /* HAL_PCD_MODULE_ENABLED */ |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @} |
||
| 240 | */ |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @} |
||
| 244 | */ |
||
| 245 | |||
| 246 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |