38
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file stm32f4xx_hal_pcd_ex.c
|
|
4 * @author MCD Application Team
|
|
5 * @version V1.2.0
|
|
6 * @date 26-December-2014
|
|
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) 2014 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
|
|
55 /* Private types -------------------------------------------------------------*/
|
|
56 /* Private variables ---------------------------------------------------------*/
|
|
57 /* Private constants ---------------------------------------------------------*/
|
|
58 /* Private macros ------------------------------------------------------------*/
|
|
59 /* Private functions ---------------------------------------------------------*/
|
|
60 /* Exported functions --------------------------------------------------------*/
|
|
61
|
|
62 /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
|
|
63 * @{
|
|
64 */
|
|
65
|
|
66 /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
|
|
67 * @brief PCDEx control functions
|
|
68 *
|
|
69 @verbatim
|
|
70 ===============================================================================
|
|
71 ##### Extended features functions #####
|
|
72 ===============================================================================
|
|
73 [..] This section provides functions allowing to:
|
|
74 (+) Update FIFO configuration
|
|
75
|
|
76 @endverbatim
|
|
77 * @{
|
|
78 */
|
|
79
|
|
80 /**
|
|
81 * @brief Set Tx FIFO
|
|
82 * @param hpcd: PCD handle
|
|
83 * @param fifo: The number of Tx fifo
|
|
84 * @param size: Fifo size
|
|
85 * @retval HAL status
|
|
86 */
|
|
87 HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
|
|
88 {
|
|
89 uint8_t i = 0;
|
|
90 uint32_t Tx_Offset = 0;
|
|
91
|
|
92 /* TXn min size = 16 words. (n : Transmit FIFO index)
|
|
93 When a TxFIFO is not used, the Configuration should be as follows:
|
|
94 case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
|
|
95 --> Txm can use the space allocated for Txn.
|
|
96 case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
|
|
97 --> Txn should be configured with the minimum space of 16 words
|
|
98 The FIFO is used optimally when used TxFIFOs are allocated in the top
|
|
99 of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
|
|
100 When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
|
|
101
|
|
102 Tx_Offset = hpcd->Instance->GRXFSIZ;
|
|
103
|
|
104 if(fifo == 0)
|
|
105 {
|
|
106 hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (size << 16) | Tx_Offset;
|
|
107 }
|
|
108 else
|
|
109 {
|
|
110 Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
|
|
111 for (i = 0; i < (fifo - 1); i++)
|
|
112 {
|
|
113 Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
|
|
114 }
|
|
115
|
|
116 /* Multiply Tx_Size by 2 to get higher performance */
|
|
117 hpcd->Instance->DIEPTXF[fifo - 1] = (size << 16) | Tx_Offset;
|
|
118
|
|
119 }
|
|
120
|
|
121 return HAL_OK;
|
|
122 }
|
|
123
|
|
124 /**
|
|
125 * @brief Set Rx FIFO
|
|
126 * @param hpcd: PCD handle
|
|
127 * @param size: Size of Rx fifo
|
|
128 * @retval HAL status
|
|
129 */
|
|
130 HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
|
|
131 {
|
|
132 hpcd->Instance->GRXFSIZ = size;
|
|
133
|
|
134 return HAL_OK;
|
|
135 }
|
|
136
|
|
137 /**
|
|
138 * @}
|
|
139 */
|
|
140
|
|
141 /**
|
|
142 * @}
|
|
143 */
|
|
144
|
|
145 #endif /* HAL_PCD_MODULE_ENABLED */
|
|
146 /**
|
|
147 * @}
|
|
148 */
|
|
149
|
|
150 /**
|
|
151 * @}
|
|
152 */
|
|
153
|
|
154 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|