Rev 2 | Details | Compare with Previous | 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 |
||
| 9 | mjames | 5 | * @brief PCD Extended HAL module driver. |
| 6 | * This file provides firmware functions to manage the following |
||
| 2 | mjames | 7 | * functionalities of the USB Peripheral Controller: |
| 9 | mjames | 8 | * + Extended features functions |
| 2 | mjames | 9 | * |
| 10 | ****************************************************************************** |
||
| 11 | * @attention |
||
| 12 | * |
||
| 9 | mjames | 13 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
| 14 | * All rights reserved.</center></h2> |
||
| 2 | mjames | 15 | * |
| 9 | mjames | 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 |
||
| 2 | mjames | 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 | |||
| 9 | mjames | 36 | #ifdef HAL_PCD_MODULE_ENABLED |
| 2 | mjames | 37 | |
| 9 | mjames | 38 | #if defined (USB) || defined (USB_OTG_FS) |
| 2 | mjames | 39 | /* Private types -------------------------------------------------------------*/ |
| 40 | /* Private variables ---------------------------------------------------------*/ |
||
| 41 | /* Private constants ---------------------------------------------------------*/ |
||
| 42 | /* Private macros ------------------------------------------------------------*/ |
||
| 43 | /* Private functions ---------------------------------------------------------*/ |
||
| 44 | /* Exported functions --------------------------------------------------------*/ |
||
| 9 | mjames | 45 | |
| 2 | mjames | 46 | /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions |
| 47 | * @{ |
||
| 48 | */ |
||
| 49 | |||
| 50 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions |
||
| 9 | mjames | 51 | * @brief PCDEx control functions |
| 2 | mjames | 52 | * |
| 53 | @verbatim |
||
| 54 | =============================================================================== |
||
| 9 | mjames | 55 | ##### Extended features functions ##### |
| 2 | mjames | 56 | =============================================================================== |
| 57 | [..] This section provides functions allowing to: |
||
| 9 | mjames | 58 | (+) Update FIFO configuration |
| 2 | mjames | 59 | |
| 60 | @endverbatim |
||
| 61 | * @{ |
||
| 62 | */ |
||
| 63 | #if defined (USB_OTG_FS) |
||
| 64 | /** |
||
| 65 | * @brief Set Tx FIFO |
||
| 9 | mjames | 66 | * @param hpcd PCD handle |
| 67 | * @param fifo The number of Tx fifo |
||
| 68 | * @param size Fifo size |
||
| 2 | mjames | 69 | * @retval HAL status |
| 70 | */ |
||
| 71 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) |
||
| 72 | { |
||
| 9 | mjames | 73 | uint8_t i; |
| 74 | uint32_t Tx_Offset; |
||
| 75 | |||
| 2 | mjames | 76 | /* TXn min size = 16 words. (n : Transmit FIFO index) |
| 9 | mjames | 77 | When a TxFIFO is not used, the Configuration should be as follows: |
| 2 | mjames | 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 |
||
| 9 | mjames | 82 | The FIFO is used optimally when used TxFIFOs are allocated in the top |
| 2 | mjames | 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 */ |
||
| 9 | mjames | 85 | |
| 2 | mjames | 86 | Tx_Offset = hpcd->Instance->GRXFSIZ; |
| 9 | mjames | 87 | |
| 88 | if (fifo == 0U) |
||
| 2 | mjames | 89 | { |
| 9 | mjames | 90 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset; |
| 2 | mjames | 91 | } |
| 92 | else |
||
| 93 | { |
||
| 9 | mjames | 94 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16; |
| 95 | for (i = 0U; i < (fifo - 1U); i++) |
||
| 2 | mjames | 96 | { |
| 9 | mjames | 97 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16); |
| 2 | mjames | 98 | } |
| 9 | mjames | 99 | |
| 2 | mjames | 100 | /* Multiply Tx_Size by 2 to get higher performance */ |
| 9 | mjames | 101 | hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset; |
| 2 | mjames | 102 | } |
| 9 | mjames | 103 | |
| 2 | mjames | 104 | return HAL_OK; |
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @brief Set Rx FIFO |
||
| 9 | mjames | 109 | * @param hpcd PCD handle |
| 110 | * @param size Size of Rx fifo |
||
| 2 | mjames | 111 | * @retval HAL status |
| 112 | */ |
||
| 113 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) |
||
| 114 | { |
||
| 115 | hpcd->Instance->GRXFSIZ = size; |
||
| 9 | mjames | 116 | |
| 2 | mjames | 117 | return HAL_OK; |
| 118 | } |
||
| 9 | mjames | 119 | #endif /* defined (USB_OTG_FS) */ |
| 2 | mjames | 120 | #if defined (USB) |
| 121 | /** |
||
| 122 | * @brief Configure PMA for EP |
||
| 9 | mjames | 123 | * @param hpcd Device instance |
| 124 | * @param ep_addr endpoint address |
||
| 125 | * @param ep_kind endpoint Kind |
||
| 2 | mjames | 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 | |||
| 9 | mjames | 138 | HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr, |
| 139 | uint16_t ep_kind, uint32_t pmaadress) |
||
| 140 | { |
||
| 141 | PCD_EPTypeDef *ep; |
||
| 2 | mjames | 142 | |
| 143 | /* initialize ep structure*/ |
||
| 9 | mjames | 144 | if ((0x80U & ep_addr) == 0x80U) |
| 2 | mjames | 145 | { |
| 9 | mjames | 146 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
| 2 | mjames | 147 | } |
| 148 | else |
||
| 149 | { |
||
| 150 | ep = &hpcd->OUT_ep[ep_addr]; |
||
| 151 | } |
||
| 9 | mjames | 152 | |
| 2 | mjames | 153 | /* Here we check if the endpoint is single or double Buffer*/ |
| 154 | if (ep_kind == PCD_SNG_BUF) |
||
| 155 | { |
||
| 9 | mjames | 156 | /* Single Buffer */ |
| 2 | mjames | 157 | ep->doublebuffer = 0U; |
| 9 | mjames | 158 | /* Configure the PMA */ |
| 2 | mjames | 159 | ep->pmaadress = (uint16_t)pmaadress; |
| 160 | } |
||
| 9 | mjames | 161 | else /* USB_DBL_BUF */ |
| 2 | mjames | 162 | { |
| 9 | mjames | 163 | /* Double Buffer Endpoint */ |
| 2 | mjames | 164 | ep->doublebuffer = 1U; |
| 9 | mjames | 165 | /* Configure the PMA */ |
| 166 | ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU); |
||
| 167 | ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16); |
||
| 2 | mjames | 168 | } |
| 9 | mjames | 169 | |
| 170 | return HAL_OK; |
||
| 2 | mjames | 171 | } |
| 172 | |||
| 173 | /** |
||
| 9 | mjames | 174 | * @brief Software Device Connection, |
| 175 | * this function is not required by USB OTG FS peripheral, it is used |
||
| 2 | mjames | 176 | * only by USB Device FS peripheral. |
| 9 | mjames | 177 | * @param hpcd PCD handle |
| 178 | * @param state connection state (0 : disconnected / 1: connected) |
||
| 2 | mjames | 179 | * @retval None |
| 180 | */ |
||
| 181 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) |
||
| 182 | { |
||
| 183 | /* Prevent unused argument(s) compilation warning */ |
||
| 184 | UNUSED(hpcd); |
||
| 185 | UNUSED(state); |
||
| 186 | /* NOTE : This function Should not be modified, when the callback is needed, |
||
| 187 | the HAL_PCDEx_SetConnectionState could be implemented in the user file |
||
| 9 | mjames | 188 | */ |
| 2 | mjames | 189 | } |
| 9 | mjames | 190 | #endif /* defined (USB) */ |
| 191 | |||
| 2 | mjames | 192 | /** |
| 9 | mjames | 193 | * @brief Send LPM message to user layer callback. |
| 194 | * @param hpcd PCD handle |
||
| 195 | * @param msg LPM message |
||
| 196 | * @retval HAL status |
||
| 2 | mjames | 197 | */ |
| 9 | mjames | 198 | __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) |
| 199 | { |
||
| 200 | /* Prevent unused argument(s) compilation warning */ |
||
| 201 | UNUSED(hpcd); |
||
| 202 | UNUSED(msg); |
||
| 2 | mjames | 203 | |
| 9 | mjames | 204 | /* NOTE : This function should not be modified, when the callback is needed, |
| 205 | the HAL_PCDEx_LPM_Callback could be implemented in the user file |
||
| 206 | */ |
||
| 207 | } |
||
| 208 | |||
| 2 | mjames | 209 | /** |
| 9 | mjames | 210 | * @brief Send BatteryCharging message to user layer callback. |
| 211 | * @param hpcd PCD handle |
||
| 212 | * @param msg LPM message |
||
| 213 | * @retval HAL status |
||
| 214 | */ |
||
| 215 | __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg) |
||
| 216 | { |
||
| 217 | /* Prevent unused argument(s) compilation warning */ |
||
| 218 | UNUSED(hpcd); |
||
| 219 | UNUSED(msg); |
||
| 220 | |||
| 221 | /* NOTE : This function should not be modified, when the callback is needed, |
||
| 222 | the HAL_PCDEx_BCD_Callback could be implemented in the user file |
||
| 223 | */ |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 2 | mjames | 227 | * @} |
| 228 | */ |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @} |
||
| 232 | */ |
||
| 9 | mjames | 233 | #endif /* defined (USB) || defined (USB_OTG_FS) */ |
| 2 | mjames | 234 | #endif /* HAL_PCD_MODULE_ENABLED */ |
| 235 | |||
| 9 | mjames | 236 | /** |
| 237 | * @} |
||
| 238 | */ |
||
| 2 | mjames | 239 | |
| 240 | /** |
||
| 241 | * @} |
||
| 242 | */ |
||
| 243 | |||
| 244 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |