1
1
/**
2
2
******************************************************************************
3
- * @file USB_Device/HID_Standalone/Src/ usbd_conf.c
3
+ * @file usbd_conf.c
4
4
* @author MCD Application Team
5
- * @version V1.0.2
6
- * @date 06-May-2016
7
- * @brief This file implements the USB Device library callbacks and MSP
5
+ * @brief USB Device configuration and interface file
8
6
******************************************************************************
9
7
* @attention
10
8
*
11
- * <h2><center>© Copyright � 2016 STMicroelectronics International N.V .
9
+ * <h2><center>© Copyright (c) 2015 STMicroelectronics.
12
10
* All rights reserved.</center></h2>
13
11
*
14
- * Redistribution and use in source and binary forms, with or without
15
- * modification, are permitted, provided that the following conditions are met:
16
- *
17
- * 1. Redistribution of source code must retain the above copyright notice,
18
- * this list of conditions and the following disclaimer.
19
- * 2. Redistributions in binary form must reproduce the above copyright notice,
20
- * this list of conditions and the following disclaimer in the documentation
21
- * and/or other materials provided with the distribution.
22
- * 3. Neither the name of STMicroelectronics nor the names of other
23
- * contributors to this software may be used to endorse or promote products
24
- * derived from this software without specific written permission.
25
- * 4. This software, including modifications and/or derivative works of this
26
- * software, must execute solely and exclusively on microcontroller or
27
- * microprocessor devices manufactured by or for STMicroelectronics.
28
- * 5. Redistribution and use of this software other than as permitted under
29
- * this license is void and will automatically terminate your rights under
30
- * this license.
31
- *
32
- * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
33
- * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
34
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35
- * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
36
- * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
37
- * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
40
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
43
- * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12
+ * This software component is licensed by ST under Ultimate Liberty license
13
+ * SLA0044, the "License"; You may not use this file except in compliance with
14
+ * the License. You may obtain a copy of the License at:
15
+ * http://www.st.com/SLA0044
44
16
*
45
17
******************************************************************************
46
18
*/
47
19
#ifdef USBCON
48
20
/* Includes ------------------------------------------------------------------*/
49
- #include "usbd_conf.h"
50
21
#include "usbd_core.h"
51
- #include "hw_config.h"
52
-
53
22
/* Private typedef -----------------------------------------------------------*/
54
23
/* Private define ------------------------------------------------------------*/
55
24
/* Private macro -------------------------------------------------------------*/
56
25
/* Private variables ---------------------------------------------------------*/
57
26
PCD_HandleTypeDef g_hpcd ;
58
-
59
27
/* Private function prototypes -----------------------------------------------*/
60
- //static void SystemClockConfig_STOP(void);
61
-
62
28
/* Private functions ---------------------------------------------------------*/
63
-
64
29
/*******************************************************************************
65
30
PCD BSP Routines
66
31
*******************************************************************************/
@@ -74,6 +39,9 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
74
39
{
75
40
GPIO_InitTypeDef GPIO_InitStruct ;
76
41
42
+ /* Enable USB power on Pwrctrl CR2 register */
43
+ HAL_PWREx_EnableVddUSB ();
44
+
77
45
/* Configure USB FS GPIOs */
78
46
__HAL_RCC_GPIOA_CLK_ENABLE ();
79
47
@@ -85,27 +53,44 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
85
53
GPIO_InitStruct .Alternate = GPIO_AF10_OTG_FS ;
86
54
HAL_GPIO_Init (GPIOA , & GPIO_InitStruct );
87
55
88
- /* Enable USB FS Clocks */
56
+ /* Configure VBUS Pin */
57
+ GPIO_InitStruct .Pin = GPIO_PIN_9 ;
58
+ GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
59
+ GPIO_InitStruct .Pull = GPIO_NOPULL ;
60
+ HAL_GPIO_Init (GPIOA , & GPIO_InitStruct );
61
+
62
+ /* Configure ID pin */
63
+ GPIO_InitStruct .Pin = GPIO_PIN_10 ;
64
+ GPIO_InitStruct .Mode = GPIO_MODE_AF_OD ;
65
+ GPIO_InitStruct .Pull = GPIO_PULLUP ;
66
+ GPIO_InitStruct .Alternate = GPIO_AF10_OTG_FS ;
67
+ HAL_GPIO_Init (GPIOA , & GPIO_InitStruct );
68
+
69
+ /* Configure power enable pin (USB_OTG_FS_PWR_EN) */
70
+ __HAL_RCC_GPIOD_CLK_ENABLE ();
71
+ GPIO_InitStruct .Pin = GPIO_PIN_12 ;
72
+ GPIO_InitStruct .Mode = GPIO_MODE_OUTPUT_PP ;
73
+ GPIO_InitStruct .Pull = GPIO_PULLUP ;
74
+ HAL_GPIO_Init (GPIOD , & GPIO_InitStruct );
75
+
76
+ /* USB power output is disabled in device mode */
77
+ HAL_GPIO_WritePin (GPIOD , GPIO_PIN_12 , GPIO_PIN_SET );
78
+
79
+ /* Enable USB FS Clock */
89
80
__HAL_RCC_USB_OTG_FS_CLK_ENABLE ();
90
81
91
- /* Set USBFS Interrupt priority */
82
+ /* Set USB FS Interrupt priority */
92
83
HAL_NVIC_SetPriority (OTG_FS_IRQn , 5 , 0 );
93
84
94
- /* Enable USBFS Interrupt */
85
+ /* Enable USB FS Interrupt */
95
86
HAL_NVIC_EnableIRQ (OTG_FS_IRQn );
96
87
97
88
if (hpcd -> Init .low_power_enable == 1 )
98
89
{
99
- /* Enable EXTI Line 18 for USB wakeup*/
90
+ /* Enable EXTI Line 18 for USB wakeup */
100
91
__HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG ();
101
92
__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE ();
102
93
__HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT ();
103
-
104
- /* Set EXTI Wakeup Interrupt priority*/
105
- HAL_NVIC_SetPriority (OTG_FS_WKUP_IRQn , 0 , 0 );
106
-
107
- /* Enable EXTI Interrupt */
108
- HAL_NVIC_EnableIRQ (OTG_FS_WKUP_IRQn );
109
94
}
110
95
}
111
96
@@ -117,7 +102,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
117
102
void HAL_PCD_MspDeInit (PCD_HandleTypeDef * hpcd )
118
103
{
119
104
UNUSED (hpcd );
120
-
105
+
121
106
/* Disable USB FS Clock */
122
107
__HAL_RCC_USB_OTG_FS_CLK_DISABLE ();
123
108
__HAL_RCC_SYSCFG_CLK_DISABLE ();
@@ -178,6 +163,7 @@ void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
178
163
{
179
164
USBD_SpeedTypeDef speed = USBD_SPEED_FULL ;
180
165
166
+ #if defined (USB_OTG_HS )
181
167
/* Set USB Current Speed */
182
168
switch (hpcd -> Init .speed )
183
169
{
@@ -193,7 +179,7 @@ void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
193
179
speed = USBD_SPEED_FULL ;
194
180
break ;
195
181
}
196
-
182
+ #endif
197
183
/* Reset Device */
198
184
USBD_LL_Reset (hpcd -> pData );
199
185
@@ -210,7 +196,7 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
210
196
__HAL_PCD_GATE_PHYCLOCK (hpcd );
211
197
USBD_LL_Suspend (hpcd -> pData );
212
198
213
- /*Enter in STOP mode */
199
+ /*Enter in STOP mode */
214
200
if (hpcd -> Init .low_power_enable )
215
201
{
216
202
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */
@@ -225,6 +211,7 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
225
211
*/
226
212
void HAL_PCD_ResumeCallback (PCD_HandleTypeDef * hpcd )
227
213
{
214
+ __HAL_PCD_UNGATE_PHYCLOCK (hpcd );
228
215
USBD_LL_Resume (hpcd -> pData );
229
216
}
230
217
@@ -306,11 +293,9 @@ void OTG_FS_WKUP_IRQHandler(void)
306
293
/* Clear EXTI pending Bit*/
307
294
__HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG ();
308
295
}
309
-
310
296
/*******************************************************************************
311
297
LL Driver Interface (USB Device Library --> PCD)
312
298
*******************************************************************************/
313
-
314
299
/**
315
300
* @brief Initializes the Low Level portion of the Device driver.
316
301
* @param pdev: Device handle
@@ -320,27 +305,30 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
320
305
{
321
306
/* Set LL Driver parameters */
322
307
g_hpcd .Instance = USB_OTG_FS ;
323
- g_hpcd .Init .dev_endpoints = 4 ;
308
+ g_hpcd .Init .dev_endpoints = 3 ;
324
309
g_hpcd .Init .use_dedicated_ep1 = 0 ;
325
- g_hpcd .Init .ep0_mps = DEP0CTL_MPS_64 ; //0x40;
310
+ g_hpcd .Init .ep0_mps = DEP0CTL_MPS_64 ;
326
311
g_hpcd .Init .dma_enable = 0 ;
327
312
g_hpcd .Init .low_power_enable = 0 ;
313
+ g_hpcd .Init .lpm_enable = 0 ;
314
+ g_hpcd .Init .battery_charging_enable = 0 ;
328
315
g_hpcd .Init .phy_itface = PCD_PHY_EMBEDDED ;
329
316
g_hpcd .Init .Sof_enable = 0 ;
330
317
g_hpcd .Init .speed = PCD_SPEED_FULL ;
331
- g_hpcd .Init .vbus_sensing_enable = 0 ;
318
+ g_hpcd .Init .vbus_sensing_enable = 1 ;
332
319
g_hpcd .Init .lpm_enable = 0 ;
320
+ g_hpcd .Init .use_external_vbus = 0 ;
333
321
/* Link The driver to the stack */
334
322
g_hpcd .pData = pdev ;
335
323
pdev -> pData = & g_hpcd ;
336
-
337
324
/* Initialize LL Driver */
338
325
HAL_PCD_Init (& g_hpcd );
339
326
327
+ /* configure EPs FIFOs */
340
328
HAL_PCDEx_SetRxFiFo (& g_hpcd , 0x80 );
341
329
HAL_PCDEx_SetTxFiFo (& g_hpcd , 0 , 0x40 );
342
330
HAL_PCDEx_SetTxFiFo (& g_hpcd , 1 , 0x80 );
343
-
331
+ HAL_PCDEx_SetTxFiFo ( & g_hpcd , 2 , 0x80 );
344
332
return USBD_OK ;
345
333
}
346
334
@@ -394,7 +382,6 @@ USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
394
382
ep_addr ,
395
383
ep_mps ,
396
384
ep_type );
397
-
398
385
return USBD_OK ;
399
386
}
400
387
@@ -532,6 +519,6 @@ void USBD_LL_Delay(uint32_t Delay)
532
519
{
533
520
HAL_Delay (Delay );
534
521
}
535
-
536
- #endif // USBCON
522
+ #endif /* USBCON */
537
523
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
524
+
0 commit comments