1 /**
2 ******************************************************************************
3 * @file stm32f3xx_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 * Copyright (c) 2016 STMicroelectronics.
14 * All rights reserved.
15 *
16 * This software is licensed under terms that can be found in the LICENSE file
17 * in the root directory of this software component.
18 * If no LICENSE file comes with this software, it is provided AS-IS.
19 *
20 ******************************************************************************
21 */
22
23 /* Includes ------------------------------------------------------------------*/
24 #include "stm32f3xx_hal.h"
25
26 /** @addtogroup STM32F3xx_HAL_Driver
27 * @{
28 */
29
30 /** @defgroup PCDEx PCDEx
31 * @brief PCD Extended HAL module driver
32 * @{
33 */
34
35 #ifdef HAL_PCD_MODULE_ENABLED
36
37 #if defined (USB)
38 /* Private types -------------------------------------------------------------*/
39 /* Private variables ---------------------------------------------------------*/
40 /* Private constants ---------------------------------------------------------*/
41 /* Private macros ------------------------------------------------------------*/
42 /* Private functions ---------------------------------------------------------*/
43 /* Exported functions --------------------------------------------------------*/
44
45 /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
46 * @{
47 */
48
49 /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
50 * @brief PCDEx control functions
51 *
52 @verbatim
53 ===============================================================================
54 ##### Extended features functions #####
55 ===============================================================================
56 [..] This section provides functions allowing to:
57 (+) Update FIFO configuration
58
59 @endverbatim
60 * @{
61 */
62
63 /**
64 * @brief Configure PMA for EP
65 * @param hpcd Device instance
66 * @param ep_addr endpoint address
67 * @param ep_kind endpoint Kind
68 * USB_SNG_BUF: Single Buffer used
69 * USB_DBL_BUF: Double Buffer used
70 * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
71 * this parameter is 16-bit value providing the address
72 * in PMA allocated to endpoint.
73 * In case of double buffer endpoint this parameter
74 * is a 32-bit value providing the endpoint buffer 0 address
75 * in the LSB part of 32-bit value and endpoint buffer 1 address
76 * in the MSB part of 32-bit value.
77 * @retval HAL status
78 */
79
HAL_PCDEx_PMAConfig(PCD_HandleTypeDef * hpcd,uint16_t ep_addr,uint16_t ep_kind,uint32_t pmaadress)80 HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr,
81 uint16_t ep_kind, uint32_t pmaadress)
82 {
83 PCD_EPTypeDef *ep;
84
85 /* initialize ep structure*/
86 if ((0x80U & ep_addr) == 0x80U)
87 {
88 ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
89 }
90 else
91 {
92 ep = &hpcd->OUT_ep[ep_addr];
93 }
94
95 /* Here we check if the endpoint is single or double Buffer*/
96 if (ep_kind == PCD_SNG_BUF)
97 {
98 /* Single Buffer */
99 ep->doublebuffer = 0U;
100 /* Configure the PMA */
101 ep->pmaadress = (uint16_t)pmaadress;
102 }
103 #if (USE_USB_DOUBLE_BUFFER == 1U)
104 else /* USB_DBL_BUF */
105 {
106 /* Double Buffer Endpoint */
107 ep->doublebuffer = 1U;
108 /* Configure the PMA */
109 ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU);
110 ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16);
111 }
112 #endif /* (USE_USB_DOUBLE_BUFFER == 1U) */
113
114 return HAL_OK;
115 }
116
117 /**
118 * @brief Software Device Connection,
119 * this function is not required by USB OTG FS peripheral, it is used
120 * only by USB Device FS peripheral.
121 * @param hpcd PCD handle
122 * @param state connection state (0 : disconnected / 1: connected)
123 * @retval None
124 */
HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef * hpcd,uint8_t state)125 __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
126 {
127 /* Prevent unused argument(s) compilation warning */
128 UNUSED(hpcd);
129 UNUSED(state);
130 /* NOTE : This function Should not be modified, when the callback is needed,
131 the HAL_PCDEx_SetConnectionState could be implemented in the user file
132 */
133 }
134
135
136 /**
137 * @brief Send LPM message to user layer callback.
138 * @param hpcd PCD handle
139 * @param msg LPM message
140 * @retval HAL status
141 */
HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef * hpcd,PCD_LPM_MsgTypeDef msg)142 __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
143 {
144 /* Prevent unused argument(s) compilation warning */
145 UNUSED(hpcd);
146 UNUSED(msg);
147
148 /* NOTE : This function should not be modified, when the callback is needed,
149 the HAL_PCDEx_LPM_Callback could be implemented in the user file
150 */
151 }
152
153 /**
154 * @brief Send BatteryCharging message to user layer callback.
155 * @param hpcd PCD handle
156 * @param msg LPM message
157 * @retval HAL status
158 */
HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef * hpcd,PCD_BCD_MsgTypeDef msg)159 __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
160 {
161 /* Prevent unused argument(s) compilation warning */
162 UNUSED(hpcd);
163 UNUSED(msg);
164
165 /* NOTE : This function should not be modified, when the callback is needed,
166 the HAL_PCDEx_BCD_Callback could be implemented in the user file
167 */
168 }
169
170 /**
171 * @}
172 */
173
174 /**
175 * @}
176 */
177 #endif /* defined (USB) */
178 #endif /* HAL_PCD_MODULE_ENABLED */
179
180 /**
181 * @}
182 */
183
184 /**
185 * @}
186 */
187