1 | /**
|
---|
2 | ******************************************************************************
|
---|
3 | * @file stm32f4xx_hal_pcd_ex.c
|
---|
4 | * @author MCD Application Team
|
---|
5 | * @version V1.4.1
|
---|
6 | * @date 09-October-2015
|
---|
7 | * @brief 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
|
---|
11 | *
|
---|
12 | ******************************************************************************
|
---|
13 | * @attention
|
---|
14 | *
|
---|
15 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
---|
16 | *
|
---|
17 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
18 | * are permitted provided that the following conditions are met:
|
---|
19 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
20 | * this list of conditions and the following disclaimer.
|
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
22 | * this list of conditions and the following disclaimer in the documentation
|
---|
23 | * and/or other materials provided with the distribution.
|
---|
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
---|
25 | * may be used to endorse or promote products derived from this software
|
---|
26 | * without specific prior written permission.
|
---|
27 | *
|
---|
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
---|
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
---|
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
---|
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
38 | *
|
---|
39 | ******************************************************************************
|
---|
40 | */
|
---|
41 |
|
---|
42 | /* Includes ------------------------------------------------------------------*/
|
---|
43 | #include "stm32f4xx_hal.h"
|
---|
44 |
|
---|
45 | /** @addtogroup STM32F4xx_HAL_Driver
|
---|
46 | * @{
|
---|
47 | */
|
---|
48 |
|
---|
49 | /** @defgroup PCDEx PCDEx
|
---|
50 | * @brief PCD Extended HAL module driver
|
---|
51 | * @{
|
---|
52 | */
|
---|
53 | #ifdef HAL_PCD_MODULE_ENABLED
|
---|
54 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \
|
---|
55 | defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
|
---|
56 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \
|
---|
57 | defined(STM32F469xx) || defined(STM32F479xx)
|
---|
58 | /* Private types -------------------------------------------------------------*/
|
---|
59 | /* Private variables ---------------------------------------------------------*/
|
---|
60 | /* Private constants ---------------------------------------------------------*/
|
---|
61 | /* Private macros ------------------------------------------------------------*/
|
---|
62 | /* Private functions ---------------------------------------------------------*/
|
---|
63 | /* Exported functions --------------------------------------------------------*/
|
---|
64 |
|
---|
65 | /** @defgroup PCDEx_Exported_Functions PCD Extended Exported Functions
|
---|
66 | * @{
|
---|
67 | */
|
---|
68 |
|
---|
69 | /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
|
---|
70 | * @brief PCDEx control functions
|
---|
71 | *
|
---|
72 | @verbatim
|
---|
73 | ===============================================================================
|
---|
74 | ##### Extended features functions #####
|
---|
75 | ===============================================================================
|
---|
76 | [..] This section provides functions allowing to:
|
---|
77 | (+) Update FIFO configuration
|
---|
78 |
|
---|
79 | @endverbatim
|
---|
80 | * @{
|
---|
81 | */
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * @brief Set Tx FIFO
|
---|
85 | * @param hpcd: PCD handle
|
---|
86 | * @param fifo: The number of Tx fifo
|
---|
87 | * @param size: Fifo size
|
---|
88 | * @retval HAL status
|
---|
89 | */
|
---|
90 | HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
|
---|
91 | {
|
---|
92 | uint8_t i = 0;
|
---|
93 | uint32_t Tx_Offset = 0;
|
---|
94 |
|
---|
95 | /* TXn min size = 16 words. (n : Transmit FIFO index)
|
---|
96 | When a TxFIFO is not used, the Configuration should be as follows:
|
---|
97 | case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
|
---|
98 | --> Txm can use the space allocated for Txn.
|
---|
99 | case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
|
---|
100 | --> Txn should be configured with the minimum space of 16 words
|
---|
101 | The FIFO is used optimally when used TxFIFOs are allocated in the top
|
---|
102 | of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
|
---|
103 | When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
|
---|
104 |
|
---|
105 | Tx_Offset = hpcd->Instance->GRXFSIZ;
|
---|
106 |
|
---|
107 | if(fifo == 0)
|
---|
108 | {
|
---|
109 | hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((uint32_t)size << 16) | Tx_Offset);
|
---|
110 | }
|
---|
111 | else
|
---|
112 | {
|
---|
113 | Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
|
---|
114 | for (i = 0; i < (fifo - 1); i++)
|
---|
115 | {
|
---|
116 | Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /* Multiply Tx_Size by 2 to get higher performance */
|
---|
120 | hpcd->Instance->DIEPTXF[fifo - 1] = (uint32_t)(((uint32_t)size << 16) | Tx_Offset);
|
---|
121 | }
|
---|
122 |
|
---|
123 | return HAL_OK;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * @brief Set Rx FIFO
|
---|
128 | * @param hpcd: PCD handle
|
---|
129 | * @param size: Size of Rx fifo
|
---|
130 | * @retval HAL status
|
---|
131 | */
|
---|
132 | HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
|
---|
133 | {
|
---|
134 | hpcd->Instance->GRXFSIZ = size;
|
---|
135 |
|
---|
136 | return HAL_OK;
|
---|
137 | }
|
---|
138 |
|
---|
139 | #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx)
|
---|
140 | /**
|
---|
141 | * @brief Activate LPM feature
|
---|
142 | * @param hpcd: PCD handle
|
---|
143 | * @retval HAL status
|
---|
144 | */
|
---|
145 | HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd)
|
---|
146 | {
|
---|
147 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
---|
148 |
|
---|
149 | hpcd->lpm_active = ENABLE;
|
---|
150 | hpcd->LPM_State = LPM_L0;
|
---|
151 | USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM;
|
---|
152 | USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
|
---|
153 |
|
---|
154 | return HAL_OK;
|
---|
155 | }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * @brief Deactivate LPM feature.
|
---|
159 | * @param hpcd: PCD handle
|
---|
160 | * @retval HAL status
|
---|
161 | */
|
---|
162 | HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd)
|
---|
163 | {
|
---|
164 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
---|
165 |
|
---|
166 | hpcd->lpm_active = DISABLE;
|
---|
167 | USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM;
|
---|
168 | USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL);
|
---|
169 |
|
---|
170 | return HAL_OK;
|
---|
171 | }
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * @brief Send LPM message to user layer callback.
|
---|
175 | * @param hpcd: PCD handle
|
---|
176 | * @param msg: LPM message
|
---|
177 | * @retval HAL status
|
---|
178 | */
|
---|
179 | __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
|
---|
180 | {
|
---|
181 | }
|
---|
182 | #endif /* STM32F446xx || STM32F469xx || STM32F479xx */
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * @}
|
---|
186 | */
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * @}
|
---|
190 | */
|
---|
191 |
|
---|
192 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||
|
---|
193 | STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx */
|
---|
194 | #endif /* HAL_PCD_MODULE_ENABLED */
|
---|
195 | /**
|
---|
196 | * @}
|
---|
197 | */
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * @}
|
---|
201 | */
|
---|
202 |
|
---|
203 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|