annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_ll_usb.c @ 59:00e70b60c69f

language updates
author heinrichsweikamp
date Fri, 10 Aug 2018 19:22:12 +0200
parents 5f11787b4f42
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_ll_usb.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief USB Low Layer HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * functionalities of the USB Peripheral Controller:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * + Initialization/de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 * + I/O operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 * + Peripheral Control functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 * + Peripheral State functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 (#) Fill parameters of Init structure in USB_OTG_CfgTypeDef structure.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 (#) Call USB_CoreInit() API to initialize the USB Core peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 (#) The upper HAL HCD/PCD driver will call the righ routines for its internal processes.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 /** @addtogroup STM32F4xx_LL_USB_DRIVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 #if defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 /** @defgroup PCD_Private_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 /** @defgroup LL_USB_Group1 Initialization/de-initialization functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 * @brief Initialization and Configuration functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 ##### Initialization/de-initialization functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86 [..] This section provides functions allowing to:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 * @brief Initializes the USB Core
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 * @param USBx: USB Instance
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 * @param cfg : pointer to a USB_OTG_CfgTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 * the configuration information for the specified USBx peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 if (cfg.phy_itface == USB_OTG_ULPI_PHY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 /* Init The ULPI Interface */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 USBx->GUSBCFG &= ~(USB_OTG_GUSBCFG_TSDPS | USB_OTG_GUSBCFG_ULPIFSLS | USB_OTG_GUSBCFG_PHYSEL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 /* Select vbus source */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 USBx->GUSBCFG &= ~(USB_OTG_GUSBCFG_ULPIEVBUSD | USB_OTG_GUSBCFG_ULPIEVBUSI);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 if(cfg.use_external_vbus == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 USBx->GUSBCFG |= USB_OTG_GUSBCFG_ULPIEVBUSD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 /* Reset after a PHY select */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 USB_CoreReset(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 else /* FS interface (embedded Phy) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 /* Select FS Embedded PHY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 USBx->GUSBCFG |= USB_OTG_GUSBCFG_PHYSEL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 /* Reset after a PHY select and set Host mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 USB_CoreReset(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 /* Deactivate the power down*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 USBx->GCCFG = USB_OTG_GCCFG_PWRDWN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 if(cfg.dma_enable == ENABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 USBx->GAHBCFG |= (USB_OTG_GAHBCFG_HBSTLEN_1 | USB_OTG_GAHBCFG_HBSTLEN_2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 USBx->GAHBCFG |= USB_OTG_GAHBCFG_DMAEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141 * @brief USB_EnableGlobalInt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 * Enables the controller's Global Int in the AHB Config reg
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 USBx->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 * @brief USB_DisableGlobalInt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 * Disable the controller's Global Int in the AHB Config reg
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 USBx->GAHBCFG &= ~USB_OTG_GAHBCFG_GINT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 * @brief USB_SetCurrentMode : Set functional mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 * @param mode : current core mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 * @arg USB_OTG_DEVICE_MODE: Peripheral mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 * @arg USB_OTG_HOST_MODE: Host mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 * @arg USB_OTG_DRD_MODE: Dual Role Device mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx , USB_OTG_ModeTypeDef mode)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 USBx->GUSBCFG &= ~(USB_OTG_GUSBCFG_FHMOD | USB_OTG_GUSBCFG_FDMOD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 if ( mode == USB_OTG_HOST_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 USBx->GUSBCFG |= USB_OTG_GUSBCFG_FHMOD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 else if ( mode == USB_OTG_DEVICE_MODE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 USBx->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 HAL_Delay(50);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 * @brief USB_DevInit : Initializes the USB_OTG controller registers
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 * for device mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 * @param cfg : pointer to a USB_OTG_CfgTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 * the configuration information for the specified USBx peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 HAL_StatusTypeDef USB_DevInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 uint32_t i = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 /*Activate VBUS Sensing B */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 USBx->GCCFG |= USB_OTG_GCCFG_VBUSBSEN;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 if (cfg.vbus_sensing_enable == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 USBx->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 /* Restart the Phy Clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 USBx_PCGCCTL = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 /* Device mode configuration */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 USBx_DEVICE->DCFG |= DCFG_FRAME_INTERVAL_80;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 if(cfg.phy_itface == USB_OTG_ULPI_PHY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 if(cfg.speed == USB_OTG_SPEED_HIGH)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 /* Set High speed phy */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 USB_SetDevSpeed (USBx , USB_OTG_SPEED_HIGH);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 /* set High speed phy in Full speed mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 USB_SetDevSpeed (USBx , USB_OTG_SPEED_HIGH_IN_FULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 /* Set Full speed phy */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 USB_SetDevSpeed (USBx , USB_OTG_SPEED_FULL);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 /* Flush the FIFOs */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 USB_FlushTxFifo(USBx , 0x10); /* all Tx FIFOs */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 USB_FlushRxFifo(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 /* Clear all pending Device Interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 USBx_DEVICE->DIEPMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 USBx_DEVICE->DOEPMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 USBx_DEVICE->DAINT = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 USBx_DEVICE->DAINTMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 for (i = 0; i < cfg.dev_endpoints; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 if ((USBx_INEP(i)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == USB_OTG_DIEPCTL_EPENA)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 USBx_INEP(i)->DIEPCTL = (USB_OTG_DIEPCTL_EPDIS | USB_OTG_DIEPCTL_SNAK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 USBx_INEP(i)->DIEPCTL = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 USBx_INEP(i)->DIEPTSIZ = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 USBx_INEP(i)->DIEPINT = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 for (i = 0; i < cfg.dev_endpoints; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 if ((USBx_OUTEP(i)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 USBx_OUTEP(i)->DOEPCTL = (USB_OTG_DOEPCTL_EPDIS | USB_OTG_DOEPCTL_SNAK);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 USBx_OUTEP(i)->DOEPCTL = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 USBx_OUTEP(i)->DOEPTSIZ = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 USBx_OUTEP(i)->DOEPINT = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 USBx_DEVICE->DIEPMSK &= ~(USB_OTG_DIEPMSK_TXFURM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 if (cfg.dma_enable == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 /*Set threshold parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 USBx_DEVICE->DTHRCTL = (USB_OTG_DTHRCTL_TXTHRLEN_6 | USB_OTG_DTHRCTL_RXTHRLEN_6);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 USBx_DEVICE->DTHRCTL |= (USB_OTG_DTHRCTL_RXTHREN | USB_OTG_DTHRCTL_ISOTHREN | USB_OTG_DTHRCTL_NONISOTHREN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 i= USBx_DEVICE->DTHRCTL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 /* Disable all interrupts. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 USBx->GINTMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 /* Clear any pending interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 USBx->GINTSTS = 0xBFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 /* Enable the common interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 if (cfg.dma_enable == DISABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 USBx->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 /* Enable interrupts matching to the Device mode ONLY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 USBx->GINTMSK |= (USB_OTG_GINTMSK_USBSUSPM | USB_OTG_GINTMSK_USBRST |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 USB_OTG_GINTMSK_ENUMDNEM | USB_OTG_GINTMSK_IEPINT |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 USB_OTG_GINTMSK_OEPINT | USB_OTG_GINTMSK_IISOIXFRM|\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 USB_OTG_GINTMSK_PXFRM_IISOOXFRM | USB_OTG_GINTMSK_WUIM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 if(cfg.Sof_enable)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 USBx->GINTMSK |= USB_OTG_GINTMSK_SOFM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 if (cfg.vbus_sensing_enable == ENABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 USBx->GINTMSK |= (USB_OTG_GINTMSK_SRQIM | USB_OTG_GINTMSK_OTGINT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 * @brief USB_OTG_FlushTxFifo : Flush a Tx FIFO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 * @param num : FIFO number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 * This parameter can be a value from 1 to 15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 15 means Flush all Tx FIFOs
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 HAL_StatusTypeDef USB_FlushTxFifo (USB_OTG_GlobalTypeDef *USBx, uint32_t num )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 uint32_t count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 USBx->GRSTCTL = ( USB_OTG_GRSTCTL_TXFFLSH |(uint32_t)( num << 5 ));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 if (++count > 200000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH) == USB_OTG_GRSTCTL_TXFFLSH);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 * @brief USB_FlushRxFifo : Flush Rx FIFO
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 uint32_t count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 USBx->GRSTCTL = USB_OTG_GRSTCTL_RXFFLSH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 if (++count > 200000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_RXFFLSH) == USB_OTG_GRSTCTL_RXFFLSH);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 * @brief USB_SetDevSpeed :Initializes the DevSpd field of DCFG register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 * depending the PHY type and the enumeration speed of the device.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 * @param speed : device speed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 * @arg USB_OTG_SPEED_HIGH: High speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 * @arg USB_OTG_SPEED_HIGH_IN_FULL: High speed core in Full Speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 * @arg USB_OTG_SPEED_FULL: Full speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 * @arg USB_OTG_SPEED_LOW: Low speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 * @retval Hal status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx , uint8_t speed)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 USBx_DEVICE->DCFG |= speed;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 * @brief USB_GetDevSpeed :Return the Dev Speed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 * @retval speed : device speed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 * @arg USB_OTG_SPEED_HIGH: High speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 * @arg USB_OTG_SPEED_FULL: Full speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 * @arg USB_OTG_SPEED_LOW: Low speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 uint8_t speed = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 if((USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD) == DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 speed = USB_OTG_SPEED_HIGH;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 else if (((USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD) == DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ)||
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 ((USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD) == DSTS_ENUMSPD_FS_PHY_48MHZ))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 speed = USB_OTG_SPEED_FULL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 else if((USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD) == DSTS_ENUMSPD_LS_PHY_6MHZ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 speed = USB_OTG_SPEED_LOW;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416 return speed;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 * @brief Activate and configure an endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 USBx_DEVICE->DAINTMSK |= USB_OTG_DAINTMSK_IEPM & ((1 << (ep->num)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 if (((USBx_INEP(ep->num)->DIEPCTL) & USB_OTG_DIEPCTL_USBAEP) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 USBx_INEP(ep->num)->DIEPCTL |= ((ep->maxpacket & USB_OTG_DIEPCTL_MPSIZ ) | (ep->type << 18 ) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 ((ep->num) << 22 ) | (USB_OTG_DIEPCTL_SD0PID_SEVNFRM) | (USB_OTG_DIEPCTL_USBAEP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 USBx_DEVICE->DAINTMSK |= USB_OTG_DAINTMSK_OEPM & ((1 << (ep->num)) << 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 if (((USBx_OUTEP(ep->num)->DOEPCTL) & USB_OTG_DOEPCTL_USBAEP) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 USBx_OUTEP(ep->num)->DOEPCTL |= ((ep->maxpacket & USB_OTG_DOEPCTL_MPSIZ ) | (ep->type << 18 ) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 (USB_OTG_DIEPCTL_SD0PID_SEVNFRM)| (USB_OTG_DOEPCTL_USBAEP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 * @brief Activate and configure a dedicated endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 static __IO uint32_t debug = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 /* Read DEPCTLn register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 if (((USBx_INEP(ep->num)->DIEPCTL) & USB_OTG_DIEPCTL_USBAEP) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 USBx_INEP(ep->num)->DIEPCTL |= ((ep->maxpacket & USB_OTG_DIEPCTL_MPSIZ ) | (ep->type << 18 ) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 ((ep->num) << 22 ) | (USB_OTG_DIEPCTL_SD0PID_SEVNFRM) | (USB_OTG_DIEPCTL_USBAEP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 debug |= ((ep->maxpacket & USB_OTG_DIEPCTL_MPSIZ ) | (ep->type << 18 ) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 ((ep->num) << 22 ) | (USB_OTG_DIEPCTL_SD0PID_SEVNFRM) | (USB_OTG_DIEPCTL_USBAEP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 USBx_DEVICE->DEACHMSK |= USB_OTG_DAINTMSK_IEPM & ((1 << (ep->num)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 if (((USBx_OUTEP(ep->num)->DOEPCTL) & USB_OTG_DOEPCTL_USBAEP) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 USBx_OUTEP(ep->num)->DOEPCTL |= ((ep->maxpacket & USB_OTG_DOEPCTL_MPSIZ ) | (ep->type << 18 ) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 ((ep->num) << 22 ) | (USB_OTG_DOEPCTL_USBAEP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 debug = (uint32_t)(((uint32_t )USBx) + USB_OTG_OUT_ENDPOINT_BASE + (0)*USB_OTG_EP_REG_SIZE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 debug = (uint32_t )&USBx_OUTEP(ep->num)->DOEPCTL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 debug |= ((ep->maxpacket & USB_OTG_DOEPCTL_MPSIZ ) | (ep->type << 18 ) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 ((ep->num) << 22 ) | (USB_OTG_DOEPCTL_USBAEP));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 USBx_DEVICE->DEACHMSK |= USB_OTG_DAINTMSK_OEPM & ((1 << (ep->num)) << 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 * @brief De-activate and de-initialize an endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 /* Read DEPCTLn register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 USBx_DEVICE->DEACHMSK &= ~(USB_OTG_DAINTMSK_IEPM & ((1 << (ep->num))));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_IEPM & ((1 << (ep->num))));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 USBx_INEP(ep->num)->DIEPCTL &= ~ USB_OTG_DIEPCTL_USBAEP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 USBx_DEVICE->DEACHMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((1 << (ep->num)) << 16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((1 << (ep->num)) << 16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 USBx_OUTEP(ep->num)->DOEPCTL &= ~USB_OTG_DOEPCTL_USBAEP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 * @brief De-activate and de-initialize a dedicated endpoint
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 /* Read DEPCTLn register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 USBx_INEP(ep->num)->DIEPCTL &= ~ USB_OTG_DIEPCTL_USBAEP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_IEPM & ((1 << (ep->num))));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 USBx_OUTEP(ep->num)->DOEPCTL &= ~USB_OTG_DOEPCTL_USBAEP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((1 << (ep->num)) << 16));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 * @brief USB_EPStartXfer : setup and starts a transfer over an EP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 * @param dma: USB dma enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 * 0 : DMA feature not used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 * 1 : DMA feature used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 uint16_t pktcnt = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 /* IN endpoint */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 /* Zero Length Packet? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 if (ep->xfer_len == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1 << 19)) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 /* Program the transfer size and packet count
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 * as follows: xfersize = N * maxpacket +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 * short_packet pktcnt = N + (short_packet
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 * exist ? 1 : 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (((ep->xfer_len + ep->maxpacket -1)/ ep->maxpacket) << 19)) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_XFRSIZ & ep->xfer_len);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 if (ep->type == EP_TYPE_ISOC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_MULCNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_MULCNT & (1 << 29));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 if (dma == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 USBx_INEP(ep->num)->DIEPDMA = (uint32_t)(ep->dma_addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589 if (ep->type != EP_TYPE_ISOC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 /* Enable the Tx FIFO Empty Interrupt for this EP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 if (ep->xfer_len > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 USBx_DEVICE->DIEPEMPMSK |= 1 << ep->num;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 if (ep->type == EP_TYPE_ISOC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 if ((USBx_DEVICE->DSTS & ( 1 << 8 )) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 USBx_INEP(ep->num)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 USBx_INEP(ep->num)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 /* EP enable, IN data in FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 USBx_INEP(ep->num)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 if (ep->type == EP_TYPE_ISOC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 USB_WritePacket(USBx, ep->xfer_buff, ep->num, ep->xfer_len, dma);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 else /* OUT endpoint */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 /* Program the transfer size and packet count as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 * pktcnt = N
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 * xfersize = N * maxpacket
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 USBx_OUTEP(ep->num)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_XFRSIZ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 USBx_OUTEP(ep->num)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_PKTCNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 if (ep->xfer_len == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 USBx_OUTEP(ep->num)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_XFRSIZ & ep->maxpacket);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 USBx_OUTEP(ep->num)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19)) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 pktcnt = (ep->xfer_len + ep->maxpacket -1)/ ep->maxpacket;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 USBx_OUTEP(ep->num)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (pktcnt << 19)); ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 USBx_OUTEP(ep->num)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_XFRSIZ & (ep->maxpacket * pktcnt));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 if (dma == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 USBx_OUTEP(ep->num)->DOEPDMA = (uint32_t)ep->xfer_buff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 if (ep->type == EP_TYPE_ISOC)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 if ((USBx_DEVICE->DSTS & ( 1 << 8 )) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 USBx_OUTEP(ep->num)->DOEPCTL |= USB_OTG_DOEPCTL_SODDFRM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 USBx_OUTEP(ep->num)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 /* EP enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 USBx_OUTEP(ep->num)->DOEPCTL |= (USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 * @brief USB_EP0StartXfer : setup and starts a transfer over the EP 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 * @param dma: USB dma enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 * 0 : DMA feature not used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 * 1 : DMA feature used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 HAL_StatusTypeDef USB_EP0StartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 /* IN endpoint */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 /* Zero Length Packet? */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 if (ep->xfer_len == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1 << 19)) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 /* Program the transfer size and packet count
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 * as follows: xfersize = N * maxpacket +
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 * short_packet pktcnt = N + (short_packet
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 * exist ? 1 : 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 USBx_INEP(ep->num)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 if(ep->xfer_len > ep->maxpacket)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 ep->xfer_len = ep->maxpacket;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1 << 19)) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_XFRSIZ & ep->xfer_len);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 if (dma == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 USBx_INEP(ep->num)->DIEPDMA = (uint32_t)(ep->dma_addr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 /* Enable the Tx FIFO Empty Interrupt for this EP */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 if (ep->xfer_len > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 USBx_DEVICE->DIEPEMPMSK |= 1 << (ep->num);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 /* EP enable, IN data in FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 USBx_INEP(ep->num)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 else /* OUT endpoint */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 /* Program the transfer size and packet count as follows:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 * pktcnt = N
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 * xfersize = N * maxpacket
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 USBx_OUTEP(ep->num)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_XFRSIZ);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 USBx_OUTEP(ep->num)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_PKTCNT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 if (ep->xfer_len > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 ep->xfer_len = ep->maxpacket;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 USBx_OUTEP(ep->num)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 USBx_OUTEP(ep->num)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_XFRSIZ & (ep->maxpacket));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 if (dma == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 USBx_OUTEP(ep->num)->DOEPDMA = (uint32_t)(ep->xfer_buff);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 /* EP enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 USBx_OUTEP(ep->num)->DOEPCTL |= (USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 * @brief USB_WritePacket : Writes a packet into the Tx FIFO associated
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 * with the EP/channel
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 * @param src : pointer to source buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 * @param ch_ep_num : endpoint or host channel number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 * @param len : Number of bytes to write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 * @param dma: USB dma enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 * 0 : DMA feature not used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 * 1 : DMA feature used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 uint32_t count32b= 0 , i= 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 if (dma == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 count32b = (len + 3) / 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 for (i = 0; i < count32b; i++, src += 4)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 USBx_DFIFO(ch_ep_num) = *((__packed uint32_t *)src);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 * @brief USB_ReadPacket : read a packet from the Tx FIFO associated
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 * with the EP/channel
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 * @param src : source pointer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 * @param ch_ep_num : endpoint or host channel number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 * @param len : Number of bytes to read
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 * @param dma: USB dma enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 * 0 : DMA feature not used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 * 1 : DMA feature used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 * @retval pointer to destination buffer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 uint32_t i=0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 uint32_t count32b = (len + 3) / 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 for ( i = 0; i < count32b; i++, dest += 4 )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 *(__packed uint32_t *)dest = USBx_DFIFO(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 return ((void *)dest);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 * @brief USB_EPSetStall : set a stall condition over an EP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 if (((USBx_INEP(ep->num)->DIEPCTL) & USB_OTG_DIEPCTL_EPENA) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 USBx_INEP(ep->num)->DIEPCTL &= ~(USB_OTG_DIEPCTL_EPDIS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 USBx_INEP(ep->num)->DIEPCTL |= USB_OTG_DIEPCTL_STALL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 if (((USBx_OUTEP(ep->num)->DOEPCTL) & USB_OTG_DOEPCTL_EPENA) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 USBx_OUTEP(ep->num)->DOEPCTL &= ~(USB_OTG_DOEPCTL_EPDIS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 USBx_OUTEP(ep->num)->DOEPCTL |= USB_OTG_DOEPCTL_STALL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 * @brief USB_EPClearStall : Clear a stall condition over an EP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 * @param ep: pointer to endpoint structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 if (ep->is_in == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 USBx_INEP(ep->num)->DIEPCTL &= ~USB_OTG_DIEPCTL_STALL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 if (ep->type == EP_TYPE_INTR || ep->type == EP_TYPE_BULK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 USBx_INEP(ep->num)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM; /* DATA0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 USBx_OUTEP(ep->num)->DOEPCTL &= ~USB_OTG_DOEPCTL_STALL;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 if (ep->type == EP_TYPE_INTR || ep->type == EP_TYPE_BULK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 USBx_OUTEP(ep->num)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM; /* DATA0 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 * @brief USB_StopDevice : Stop the usb device mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 uint32_t i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 /* Clear Pending interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 for (i = 0; i < 15 ; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 USBx_INEP(i)->DIEPINT = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 USBx_OUTEP(i)->DOEPINT = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 USBx_DEVICE->DAINT = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 /* Clear interrupt masks */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 USBx_DEVICE->DIEPMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 USBx_DEVICE->DOEPMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 USBx_DEVICE->DAINTMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 /* Flush the FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 USB_FlushRxFifo(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 USB_FlushTxFifo(USBx , 0x10 );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 * @brief USB_SetDevAddress : Stop the usb device mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 * @param address : new device address to be assigned
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 * This parameter can be a value from 0 to 255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 HAL_StatusTypeDef USB_SetDevAddress (USB_OTG_GlobalTypeDef *USBx, uint8_t address)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 USBx_DEVICE->DCFG &= ~ (USB_OTG_DCFG_DAD);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 USBx_DEVICE->DCFG |= (address << 4) & USB_OTG_DCFG_DAD ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 * @brief USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 HAL_StatusTypeDef USB_DevConnect (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_SDIS ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 HAL_Delay(3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 * @brief USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 HAL_StatusTypeDef USB_DevDisconnect (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 USBx_DEVICE->DCTL |= USB_OTG_DCTL_SDIS ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 HAL_Delay(3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 * @brief USB_ReadInterrupts: return the global USB interrupt status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 uint32_t USB_ReadInterrupts (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 uint32_t v = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 v = USBx->GINTSTS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 v &= USBx->GINTMSK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 return v;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 * @brief USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 uint32_t USB_ReadDevAllOutEpInterrupt (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 uint32_t v;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 v = USBx_DEVICE->DAINT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 v &= USBx_DEVICE->DAINTMSK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 return ((v & 0xffff0000) >> 16);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 * @brief USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 uint32_t USB_ReadDevAllInEpInterrupt (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 uint32_t v;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 v = USBx_DEVICE->DAINT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 v &= USBx_DEVICE->DAINTMSK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 return ((v & 0xFFFF));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 * @brief Returns Device OUT EP Interrupt register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 * @param epnum : endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 * This parameter can be a value from 0 to 15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 * @retval Device OUT EP Interrupt register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 uint32_t USB_ReadDevOutEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 uint32_t v;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 v = USBx_OUTEP(epnum)->DOEPINT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 v &= USBx_DEVICE->DOEPMSK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 return v;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 * @brief Returns Device IN EP Interrupt register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985 * @param epnum : endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 * This parameter can be a value from 0 to 15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 * @retval Device IN EP Interrupt register
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 uint32_t USB_ReadDevInEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 uint32_t v, msk, emp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 msk = USBx_DEVICE->DIEPMSK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 emp = USBx_DEVICE->DIEPEMPMSK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 msk |= ((emp >> epnum) & 0x1) << 7;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 v = USBx_INEP(epnum)->DIEPINT & msk;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 return v;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 * @brief USB_ClearInterrupts: clear a USB interrupt
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 * @param interrupt : interrupt flag
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 void USB_ClearInterrupts (USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 USBx->GINTSTS |= interrupt;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 * @brief Returns USB core mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 * @retval return core mode : Host or Device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 * 0 : Host
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 * 1 : Device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 return ((USBx->GINTSTS ) & 0x1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 * @brief Activate EP0 for Setup transactions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 HAL_StatusTypeDef USB_ActivateSetup (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 /* Set the MPS of the IN EP based on the enumeration speed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 USBx_INEP(0)->DIEPCTL &= ~USB_OTG_DIEPCTL_MPSIZ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 if((USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD) == DSTS_ENUMSPD_LS_PHY_6MHZ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 USBx_INEP(0)->DIEPCTL |= 3;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGINAK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 * @brief Prepare the EP0 to start the first control setup
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 * @param dma: USB dma enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 * 0 : DMA feature not used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 * 1 : DMA feature used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 * @param psetup : pointer to setup packet
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t dma, uint8_t *psetup)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 USBx_OUTEP(0)->DOEPTSIZ = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 USBx_OUTEP(0)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1 << 19)) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 USBx_OUTEP(0)->DOEPTSIZ |= (3 * 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 USBx_OUTEP(0)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_STUPCNT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 if (dma == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 USBx_OUTEP(0)->DOEPDMA = (uint32_t)psetup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 /* EP enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 USBx_OUTEP(0)->DOEPCTL = 0x80008000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 * @brief Reset the USB Core (needed after USB clock settings change)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 uint32_t count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 /* Wait for AHB master IDLE state. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 if (++count > 200000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_AHBIDL) == 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 /* Core Soft Reset */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 USBx->GRSTCTL |= USB_OTG_GRSTCTL_CSRST;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 if (++count > 200000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 return HAL_TIMEOUT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_CSRST) == USB_OTG_GRSTCTL_CSRST);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 * @brief USB_HostInit : Initializes the USB OTG controller registers
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 * for Host mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 * @param cfg : pointer to a USB_OTG_CfgTypeDef structure that contains
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 * the configuration information for the specified USBx peripheral.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 HAL_StatusTypeDef USB_HostInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 uint32_t i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 /* Restart the Phy Clock */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 USBx_PCGCCTL = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 /* no VBUS sensing*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 USBx->GCCFG &=~ (USB_OTG_GCCFG_VBUSASEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 USBx->GCCFG &=~ (USB_OTG_GCCFG_VBUSBSEN);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 USBx->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 /* Disable the FS/LS support mode only */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 if((cfg.speed == USB_OTG_SPEED_FULL)&&
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 (USBx != USB_OTG_FS))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 USBx_HOST->HCFG |= USB_OTG_HCFG_FSLSS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 USBx_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 /* Make sure the FIFOs are flushed. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 USB_FlushTxFifo(USBx, 0x10 ); /* all Tx FIFOs */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 USB_FlushRxFifo(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 /* Clear all pending HC Interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 for (i = 0; i < cfg.Host_channels; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 USBx_HC(i)->HCINT = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 USBx_HC(i)->HCINTMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 /* Enable VBUS driving */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 USB_DriveVbus(USBx, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 HAL_Delay(200);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 /* Disable all interrupts. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 USBx->GINTMSK = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 /* Clear any pending interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 USBx->GINTSTS = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 if(USBx == USB_OTG_FS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 /* set Rx FIFO size */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 USBx->GRXFSIZ = (uint32_t )0x80;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 USBx->DIEPTXF0_HNPTXFSIZ = (uint32_t )(((0x60 << 16)& USB_OTG_NPTXFD) | 0x80);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 USBx->HPTXFSIZ = (uint32_t )(((0x40 << 16)& USB_OTG_HPTXFSIZ_PTXFD) | 0xE0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 /* set Rx FIFO size */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 USBx->GRXFSIZ = (uint32_t )0x200;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 USBx->DIEPTXF0_HNPTXFSIZ = (uint32_t )(((0x100 << 16)& USB_OTG_NPTXFD) | 0x200);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 USBx->HPTXFSIZ = (uint32_t )(((0xE0 << 16)& USB_OTG_HPTXFSIZ_PTXFD) | 0x300);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 /* Enable the common interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 if (cfg.dma_enable == DISABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 USBx->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 /* Enable interrupts matching to the Host mode ONLY */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 USBx->GINTMSK |= (USB_OTG_GINTMSK_PRTIM | USB_OTG_GINTMSK_HCIM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 USB_OTG_GINTMSK_SOFM |USB_OTG_GINTSTS_DISCINT|\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 USB_OTG_GINTMSK_PXFRM_IISOOXFRM | USB_OTG_GINTMSK_WUIM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 * @brief USB_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 * HCFG register on the PHY type and set the right frame interval
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 * @param freq : clock frequency
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 * HCFG_48_MHZ : Full Speed 48 MHz Clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 * HCFG_6_MHZ : Low Speed 6 MHz Clock
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx , uint8_t freq)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 USBx_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSPCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 USBx_HOST->HCFG |= (freq & USB_OTG_HCFG_FSLSPCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 if (freq == HCFG_48_MHZ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 USBx_HOST->HFIR = (uint32_t)48000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 else if (freq == HCFG_6_MHZ)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215 USBx_HOST->HFIR = (uint32_t)6000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 * @brief USB_OTG_ResetPort : Reset Host Port
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 * @note : (1)The application must wait at least 10 ms
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 * before clearing the reset bit.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 __IO uint32_t hprt0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 hprt0 = USBx_HPRT0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 hprt0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 USBx_HPRT0 = (USB_OTG_HPRT_PRST | hprt0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 HAL_Delay (10); /* See Note #1 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 USBx_HPRT0 = ((~USB_OTG_HPRT_PRST) & hprt0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 * @brief USB_DriveVbus : activate or de-activate vbus
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 * @param state : VBUS state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 * 0 : VBUS Active
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 * 1 : VBUS Inactive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 * @retval HAL status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 HAL_StatusTypeDef USB_DriveVbus (USB_OTG_GlobalTypeDef *USBx, uint8_t state)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 __IO uint32_t hprt0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 hprt0 = USBx_HPRT0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 hprt0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 if (((hprt0 & USB_OTG_HPRT_PPWR) == 0 ) && (state == 1 ))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 USBx_HPRT0 = (USB_OTG_HPRT_PPWR | hprt0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 if (((hprt0 & USB_OTG_HPRT_PPWR) == USB_OTG_HPRT_PPWR) && (state == 0 ))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 USBx_HPRT0 = ((~USB_OTG_HPRT_PPWR) & hprt0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 * @brief Return Host Core speed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 * @retval speed : Host speed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 * @arg USB_OTG_SPEED_HIGH: High speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 * @arg USB_OTG_SPEED_FULL: Full speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 * @arg USB_OTG_SPEED_LOW: Low speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 uint32_t USB_GetHostSpeed (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 __IO uint32_t hprt0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 hprt0 = USBx_HPRT0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 return ((hprt0 & USB_OTG_HPRT_PSPD) >> 17);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 * @brief Return Host Current Frame number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 * @retval current frame number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 uint32_t USB_GetCurrentFrame (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 return (USBx_HOST->HFNUM & USB_OTG_HFNUM_FRNUM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 * @brief Initialize a host channel
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 * @param ch_num : Channel number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 * This parameter can be a value from 1 to 15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 * @param epnum : Endpoint number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 * This parameter can be a value from 1 to 15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 * @param dev_address : Current device address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 * This parameter can be a value from 0 to 255
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 * @param speed : Current device speed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307 * @arg USB_OTG_SPEED_HIGH: High speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 * @arg USB_OTG_SPEED_FULL: Full speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 * @arg USB_OTG_SPEED_LOW: Low speed mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 * @param ep_type : Endpoint Type
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 * @arg EP_TYPE_CTRL: Control type
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 * @arg EP_TYPE_ISOC: Isochronous type
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 * @arg EP_TYPE_BULK: Bulk type
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 * @arg EP_TYPE_INTR: Interrupt type
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 * @param mps : Max Packet Size
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 * This parameter can be a value from 0 to32K
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 uint8_t ch_num,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 uint8_t epnum,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 uint8_t dev_address,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 uint8_t speed,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 uint8_t ep_type,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 uint16_t mps)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 /* Clear old interrupt conditions for this host channel. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 USBx_HC(ch_num)->HCINT = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 /* Enable channel interrupts required for this transfer. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 switch (ep_type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 case EP_TYPE_CTRL:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 case EP_TYPE_BULK:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 USBx_HC(ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 USB_OTG_HCINTMSK_STALLM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 USB_OTG_HCINTMSK_TXERRM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 USB_OTG_HCINTMSK_DTERRM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 USB_OTG_HCINTMSK_AHBERR |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 USB_OTG_HCINTMSK_NAKM ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345 if (epnum & 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 if(USBx != USB_OTG_FS)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 USBx_HC(ch_num)->HCINTMSK |= (USB_OTG_HCINTMSK_NYET | USB_OTG_HCINTMSK_ACKM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 case EP_TYPE_INTR:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 USBx_HC(ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 USB_OTG_HCINTMSK_STALLM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 USB_OTG_HCINTMSK_TXERRM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 USB_OTG_HCINTMSK_DTERRM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 USB_OTG_HCINTMSK_NAKM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 USB_OTG_HCINTMSK_AHBERR |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 USB_OTG_HCINTMSK_FRMORM ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 if (epnum & 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 USBx_HC(ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 case EP_TYPE_ISOC:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 USBx_HC(ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 USB_OTG_HCINTMSK_ACKM |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 USB_OTG_HCINTMSK_AHBERR |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 USB_OTG_HCINTMSK_FRMORM ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 if (epnum & 0x80)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382 USBx_HC(ch_num)->HCINTMSK |= (USB_OTG_HCINTMSK_TXERRM | USB_OTG_HCINTMSK_BBERRM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 /* Enable the top level host channel interrupt. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 USBx_HOST->HAINTMSK |= (1 << ch_num);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 /* Make sure host channel interrupts are enabled. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 USBx->GINTMSK |= USB_OTG_GINTMSK_HCIM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 /* Program the HCCHAR register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 USBx_HC(ch_num)->HCCHAR = (((dev_address << 22) & USB_OTG_HCCHAR_DAD) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 (((epnum & 0x7F)<< 11) & USB_OTG_HCCHAR_EPNUM)|\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 ((((epnum & 0x80) == 0x80)<< 15) & USB_OTG_HCCHAR_EPDIR)|\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 (((speed == HPRT0_PRTSPD_LOW_SPEED)<< 17) & USB_OTG_HCCHAR_LSDEV)|\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398 ((ep_type << 18) & USB_OTG_HCCHAR_EPTYP)|\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 (mps & USB_OTG_HCCHAR_MPSIZ));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401 if (ep_type == EP_TYPE_INTR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403 USBx_HC(ch_num)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 * @brief Start a transfer over a host channel
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412 * @param hc : pointer to host channel structure
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 * @param dma: USB dma enabled or disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 * This parameter can be one of the these values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415 * 0 : DMA feature not used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 * 1 : DMA feature used
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 #if defined (__CC_ARM) /*!< ARM Compiler */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 #pragma O0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421 #elif defined (__GNUC__) /*!< GNU Compiler */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422 #pragma GCC optimize ("O0")
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423 #endif /* __CC_ARM */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc, uint8_t dma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1426 uint8_t is_oddframe = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427 uint16_t len_words = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 uint16_t num_packets = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 uint16_t max_hc_pkt_count = 256;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 if((USBx != USB_OTG_FS) && (hc->speed == USB_OTG_SPEED_HIGH))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 if((dma == 0) && (hc->do_ping == 1))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 USB_DoPing(USBx, hc->ch_num);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 else if(dma == 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440 USBx_HC(hc->ch_num)->HCINTMSK &= ~(USB_OTG_HCINTMSK_NYET | USB_OTG_HCINTMSK_ACKM);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 hc->do_ping = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445 /* Compute the expected number of packets associated to the transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 if (hc->xfer_len > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 num_packets = (hc->xfer_len + hc->max_packet - 1) / hc->max_packet;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450 if (num_packets > max_hc_pkt_count)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 num_packets = max_hc_pkt_count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453 hc->xfer_len = num_packets * hc->max_packet;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 num_packets = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 if (hc->ep_is_in)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 hc->xfer_len = num_packets * hc->max_packet;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467 /* Initialize the HCTSIZn register */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 USBx_HC(hc->ch_num)->HCTSIZ = (((hc->xfer_len) & USB_OTG_HCTSIZ_XFRSIZ)) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469 ((num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 (((hc->data_pid) << 29) & USB_OTG_HCTSIZ_DPID);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 if (dma)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 /* xfer_buff MUST be 32-bits aligned */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 USBx_HC(hc->ch_num)->HCDMA = (uint32_t)hc->xfer_buff;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478 is_oddframe = (USBx_HOST->HFNUM & 0x01) ? 0 : 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479 USBx_HC(hc->ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_ODDFRM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 USBx_HC(hc->ch_num)->HCCHAR |= (is_oddframe << 29);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 /* Set host channel enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 USBx_HC(hc->ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 USBx_HC(hc->ch_num)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486 if (dma == 0) /* Slave mode */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 if((hc->ep_is_in == 0) && (hc->xfer_len > 0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490 switch(hc->ep_type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 /* Non periodic transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 case EP_TYPE_CTRL:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 case EP_TYPE_BULK:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496 len_words = (hc->xfer_len + 3) / 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 /* check if there is enough space in FIFO space */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 if(len_words > (USBx->HNPTXSTS & 0xFFFF))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 /* need to process data in nptxfempty interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502 USBx->GINTMSK |= USB_OTG_GINTMSK_NPTXFEM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 /* Periodic transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506 case EP_TYPE_INTR:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507 case EP_TYPE_ISOC:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508 len_words = (hc->xfer_len + 3) / 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 /* check if there is enough space in FIFO space */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 if(len_words > (USBx_HOST->HPTXSTS & 0xFFFF)) /* split the transfer */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 /* need to process data in ptxfempty interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 USBx->GINTMSK |= USB_OTG_GINTMSK_PTXFEM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 /* Write packet into the Tx FIFO. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522 USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, hc->xfer_len, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 * @brief Read all host channel interrupts status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 uint32_t USB_HC_ReadInterrupt (USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 return ((USBx_HOST->HAINT) & 0xFFFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540 * @brief Halt a host channel
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 * @param hc_num : Host Channel number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543 * This parameter can be a value from 1 to 15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx , uint8_t hc_num)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 uint32_t count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550 /* Check for space in the request queue to issue the halt. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 if (((USBx_HC(hc_num)->HCCHAR) & (HCCHAR_CTRL << 18)) || ((USBx_HC(hc_num)->HCCHAR) & (HCCHAR_BULK << 18)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553 USBx_HC(hc_num)->HCCHAR |= USB_OTG_HCCHAR_CHDIS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 if ((USBx->HNPTXSTS & 0xFFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 USBx_HC(hc_num)->HCCHAR &= ~USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 USBx_HC(hc_num)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 USBx_HC(hc_num)->HCCHAR &= ~USB_OTG_HCCHAR_EPDIR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 if (++count > 1000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 while ((USBx_HC(hc_num)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571 USBx_HC(hc_num)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576 USBx_HC(hc_num)->HCCHAR |= USB_OTG_HCCHAR_CHDIS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 if ((USBx_HOST->HPTXSTS & 0xFFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 USBx_HC(hc_num)->HCCHAR &= ~USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 USBx_HC(hc_num)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582 USBx_HC(hc_num)->HCCHAR &= ~USB_OTG_HCCHAR_EPDIR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 if (++count > 1000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 while ((USBx_HC(hc_num)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 USBx_HC(hc_num)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 * @brief Initiate Do Ping protocol
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604 * @param hc_num : Host Channel number
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605 * This parameter can be a value from 1 to 15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx , uint8_t ch_num)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610 uint8_t num_packets = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612 USBx_HC(ch_num)->HCTSIZ = ((num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 USB_OTG_HCTSIZ_DOPING;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 /* Set host channel enable */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616 USBx_HC(ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_CHDIS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 USBx_HC(ch_num)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623 * @brief Stop Host Core
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624 * @param USBx : Selected device
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 * @retval HAL state
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629 uint8_t i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 uint32_t count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 uint32_t value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 USB_DisableGlobalInt(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 /* Flush FIFO */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636 USB_FlushTxFifo(USBx, 0x10);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 USB_FlushRxFifo(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 /* Flush out any leftover queued requests. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 for (i = 0; i <= 15; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 value = USBx_HC(i)->HCCHAR ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644 value |= USB_OTG_HCCHAR_CHDIS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 value &= ~USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 value &= ~USB_OTG_HCCHAR_EPDIR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 USBx_HC(i)->HCCHAR = value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 /* Halt all channels to put them into a known state. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 for (i = 0; i <= 15; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 value = USBx_HC(i)->HCCHAR ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 value |= USB_OTG_HCCHAR_CHDIS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 value |= USB_OTG_HCCHAR_CHENA;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 value &= ~USB_OTG_HCCHAR_EPDIR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660 USBx_HC(i)->HCCHAR = value;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663 if (++count > 1000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 while ((USBx_HC(i)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671 /* Clear any pending Host interrupts */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672 USBx_HOST->HAINT = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 USBx->GINTSTS = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 USB_EnableGlobalInt(USBx);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 #endif /* defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/