1*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN Header */
2*a8f7f3fcSMatthias Ringwald /**
3*a8f7f3fcSMatthias Ringwald ******************************************************************************
4*a8f7f3fcSMatthias Ringwald * @file : Target/usbh_conf.c
5*a8f7f3fcSMatthias Ringwald * @version : v1.0_Cube
6*a8f7f3fcSMatthias Ringwald * @brief : This file implements the board support package for the USB host library
7*a8f7f3fcSMatthias Ringwald ******************************************************************************
8*a8f7f3fcSMatthias Ringwald * @attention
9*a8f7f3fcSMatthias Ringwald *
10*a8f7f3fcSMatthias Ringwald * <h2><center>© Copyright (c) 2021 STMicroelectronics.
11*a8f7f3fcSMatthias Ringwald * All rights reserved.</center></h2>
12*a8f7f3fcSMatthias Ringwald *
13*a8f7f3fcSMatthias Ringwald * This software component is licensed by ST under Ultimate Liberty license
14*a8f7f3fcSMatthias Ringwald * SLA0044, the "License"; You may not use this file except in compliance with
15*a8f7f3fcSMatthias Ringwald * the License. You may obtain a copy of the License at:
16*a8f7f3fcSMatthias Ringwald * www.st.com/SLA0044
17*a8f7f3fcSMatthias Ringwald *
18*a8f7f3fcSMatthias Ringwald ******************************************************************************
19*a8f7f3fcSMatthias Ringwald */
20*a8f7f3fcSMatthias Ringwald /* USER CODE END Header */
21*a8f7f3fcSMatthias Ringwald
22*a8f7f3fcSMatthias Ringwald /* Includes ------------------------------------------------------------------*/
23*a8f7f3fcSMatthias Ringwald #include "usbh_core.h"
24*a8f7f3fcSMatthias Ringwald #include "usbh_platform.h"
25*a8f7f3fcSMatthias Ringwald
26*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN Includes */
27*a8f7f3fcSMatthias Ringwald
28*a8f7f3fcSMatthias Ringwald /* USER CODE END Includes */
29*a8f7f3fcSMatthias Ringwald
30*a8f7f3fcSMatthias Ringwald /* Private typedef -----------------------------------------------------------*/
31*a8f7f3fcSMatthias Ringwald /* Private define ------------------------------------------------------------*/
32*a8f7f3fcSMatthias Ringwald /* Private macro -------------------------------------------------------------*/
33*a8f7f3fcSMatthias Ringwald
34*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN PV */
35*a8f7f3fcSMatthias Ringwald /* Private variables ---------------------------------------------------------*/
36*a8f7f3fcSMatthias Ringwald
37*a8f7f3fcSMatthias Ringwald /* USER CODE END PV */
38*a8f7f3fcSMatthias Ringwald
39*a8f7f3fcSMatthias Ringwald HCD_HandleTypeDef hhcd_USB_OTG_FS;
40*a8f7f3fcSMatthias Ringwald void Error_Handler(void);
41*a8f7f3fcSMatthias Ringwald
42*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN 0 */
43*a8f7f3fcSMatthias Ringwald
44*a8f7f3fcSMatthias Ringwald /* USER CODE END 0 */
45*a8f7f3fcSMatthias Ringwald
46*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN PFP */
47*a8f7f3fcSMatthias Ringwald /* Private function prototypes -----------------------------------------------*/
48*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_Get_USB_Status(HAL_StatusTypeDef hal_status);
49*a8f7f3fcSMatthias Ringwald
50*a8f7f3fcSMatthias Ringwald /* USER CODE END PFP */
51*a8f7f3fcSMatthias Ringwald
52*a8f7f3fcSMatthias Ringwald /* Private functions ---------------------------------------------------------*/
53*a8f7f3fcSMatthias Ringwald
54*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN 1 */
55*a8f7f3fcSMatthias Ringwald
56*a8f7f3fcSMatthias Ringwald /* USER CODE END 1 */
57*a8f7f3fcSMatthias Ringwald
58*a8f7f3fcSMatthias Ringwald /*******************************************************************************
59*a8f7f3fcSMatthias Ringwald LL Driver Callbacks (HCD -> USB Host Library)
60*a8f7f3fcSMatthias Ringwald *******************************************************************************/
61*a8f7f3fcSMatthias Ringwald /* MSP Init */
62*a8f7f3fcSMatthias Ringwald
HAL_HCD_MspInit(HCD_HandleTypeDef * hcdHandle)63*a8f7f3fcSMatthias Ringwald void HAL_HCD_MspInit(HCD_HandleTypeDef* hcdHandle)
64*a8f7f3fcSMatthias Ringwald {
65*a8f7f3fcSMatthias Ringwald GPIO_InitTypeDef GPIO_InitStruct = {0};
66*a8f7f3fcSMatthias Ringwald if(hcdHandle->Instance==USB_OTG_FS)
67*a8f7f3fcSMatthias Ringwald {
68*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
69*a8f7f3fcSMatthias Ringwald
70*a8f7f3fcSMatthias Ringwald /* USER CODE END USB_OTG_FS_MspInit 0 */
71*a8f7f3fcSMatthias Ringwald
72*a8f7f3fcSMatthias Ringwald __HAL_RCC_GPIOA_CLK_ENABLE();
73*a8f7f3fcSMatthias Ringwald /**USB_OTG_FS GPIO Configuration
74*a8f7f3fcSMatthias Ringwald PA9 ------> USB_OTG_FS_VBUS
75*a8f7f3fcSMatthias Ringwald PA10 ------> USB_OTG_FS_ID
76*a8f7f3fcSMatthias Ringwald PA11 ------> USB_OTG_FS_DM
77*a8f7f3fcSMatthias Ringwald PA12 ------> USB_OTG_FS_DP
78*a8f7f3fcSMatthias Ringwald */
79*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Pin = VBUS_FS_Pin;
80*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
81*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Pull = GPIO_NOPULL;
82*a8f7f3fcSMatthias Ringwald HAL_GPIO_Init(VBUS_FS_GPIO_Port, &GPIO_InitStruct);
83*a8f7f3fcSMatthias Ringwald
84*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Pin = OTG_FS_ID_Pin|OTG_FS_DM_Pin|OTG_FS_DP_Pin;
85*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
86*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Pull = GPIO_NOPULL;
87*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
88*a8f7f3fcSMatthias Ringwald GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
89*a8f7f3fcSMatthias Ringwald HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
90*a8f7f3fcSMatthias Ringwald
91*a8f7f3fcSMatthias Ringwald /* Peripheral clock enable */
92*a8f7f3fcSMatthias Ringwald __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
93*a8f7f3fcSMatthias Ringwald
94*a8f7f3fcSMatthias Ringwald /* Peripheral interrupt init */
95*a8f7f3fcSMatthias Ringwald HAL_NVIC_SetPriority(OTG_FS_IRQn, 0, 0);
96*a8f7f3fcSMatthias Ringwald HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
97*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
98*a8f7f3fcSMatthias Ringwald
99*a8f7f3fcSMatthias Ringwald /* USER CODE END USB_OTG_FS_MspInit 1 */
100*a8f7f3fcSMatthias Ringwald }
101*a8f7f3fcSMatthias Ringwald }
102*a8f7f3fcSMatthias Ringwald
HAL_HCD_MspDeInit(HCD_HandleTypeDef * hcdHandle)103*a8f7f3fcSMatthias Ringwald void HAL_HCD_MspDeInit(HCD_HandleTypeDef* hcdHandle)
104*a8f7f3fcSMatthias Ringwald {
105*a8f7f3fcSMatthias Ringwald if(hcdHandle->Instance==USB_OTG_FS)
106*a8f7f3fcSMatthias Ringwald {
107*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
108*a8f7f3fcSMatthias Ringwald
109*a8f7f3fcSMatthias Ringwald /* USER CODE END USB_OTG_FS_MspDeInit 0 */
110*a8f7f3fcSMatthias Ringwald /* Peripheral clock disable */
111*a8f7f3fcSMatthias Ringwald __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
112*a8f7f3fcSMatthias Ringwald
113*a8f7f3fcSMatthias Ringwald /**USB_OTG_FS GPIO Configuration
114*a8f7f3fcSMatthias Ringwald PA9 ------> USB_OTG_FS_VBUS
115*a8f7f3fcSMatthias Ringwald PA10 ------> USB_OTG_FS_ID
116*a8f7f3fcSMatthias Ringwald PA11 ------> USB_OTG_FS_DM
117*a8f7f3fcSMatthias Ringwald PA12 ------> USB_OTG_FS_DP
118*a8f7f3fcSMatthias Ringwald */
119*a8f7f3fcSMatthias Ringwald HAL_GPIO_DeInit(GPIOA, VBUS_FS_Pin|OTG_FS_ID_Pin|OTG_FS_DM_Pin|OTG_FS_DP_Pin);
120*a8f7f3fcSMatthias Ringwald
121*a8f7f3fcSMatthias Ringwald /* Peripheral interrupt Deinit*/
122*a8f7f3fcSMatthias Ringwald HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
123*a8f7f3fcSMatthias Ringwald
124*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
125*a8f7f3fcSMatthias Ringwald
126*a8f7f3fcSMatthias Ringwald /* USER CODE END USB_OTG_FS_MspDeInit 1 */
127*a8f7f3fcSMatthias Ringwald }
128*a8f7f3fcSMatthias Ringwald }
129*a8f7f3fcSMatthias Ringwald
130*a8f7f3fcSMatthias Ringwald /**
131*a8f7f3fcSMatthias Ringwald * @brief SOF callback.
132*a8f7f3fcSMatthias Ringwald * @param hhcd: HCD handle
133*a8f7f3fcSMatthias Ringwald * @retval None
134*a8f7f3fcSMatthias Ringwald */
HAL_HCD_SOF_Callback(HCD_HandleTypeDef * hhcd)135*a8f7f3fcSMatthias Ringwald void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
136*a8f7f3fcSMatthias Ringwald {
137*a8f7f3fcSMatthias Ringwald USBH_LL_IncTimer(hhcd->pData);
138*a8f7f3fcSMatthias Ringwald }
139*a8f7f3fcSMatthias Ringwald
140*a8f7f3fcSMatthias Ringwald /**
141*a8f7f3fcSMatthias Ringwald * @brief SOF callback.
142*a8f7f3fcSMatthias Ringwald * @param hhcd: HCD handle
143*a8f7f3fcSMatthias Ringwald * @retval None
144*a8f7f3fcSMatthias Ringwald */
HAL_HCD_Connect_Callback(HCD_HandleTypeDef * hhcd)145*a8f7f3fcSMatthias Ringwald void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
146*a8f7f3fcSMatthias Ringwald {
147*a8f7f3fcSMatthias Ringwald USBH_LL_Connect(hhcd->pData);
148*a8f7f3fcSMatthias Ringwald }
149*a8f7f3fcSMatthias Ringwald
150*a8f7f3fcSMatthias Ringwald /**
151*a8f7f3fcSMatthias Ringwald * @brief SOF callback.
152*a8f7f3fcSMatthias Ringwald * @param hhcd: HCD handle
153*a8f7f3fcSMatthias Ringwald * @retval None
154*a8f7f3fcSMatthias Ringwald */
HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef * hhcd)155*a8f7f3fcSMatthias Ringwald void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
156*a8f7f3fcSMatthias Ringwald {
157*a8f7f3fcSMatthias Ringwald USBH_LL_Disconnect(hhcd->pData);
158*a8f7f3fcSMatthias Ringwald }
159*a8f7f3fcSMatthias Ringwald
160*a8f7f3fcSMatthias Ringwald /**
161*a8f7f3fcSMatthias Ringwald * @brief Notify URB state change callback.
162*a8f7f3fcSMatthias Ringwald * @param hhcd: HCD handle
163*a8f7f3fcSMatthias Ringwald * @param chnum: channel number
164*a8f7f3fcSMatthias Ringwald * @param urb_state: state
165*a8f7f3fcSMatthias Ringwald * @retval None
166*a8f7f3fcSMatthias Ringwald */
HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef * hhcd,uint8_t chnum,HCD_URBStateTypeDef urb_state)167*a8f7f3fcSMatthias Ringwald void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
168*a8f7f3fcSMatthias Ringwald {
169*a8f7f3fcSMatthias Ringwald /* To be used with OS to sync URB state with the global state machine */
170*a8f7f3fcSMatthias Ringwald #if (USBH_USE_OS == 1)
171*a8f7f3fcSMatthias Ringwald USBH_LL_NotifyURBChange(hhcd->pData);
172*a8f7f3fcSMatthias Ringwald #endif
173*a8f7f3fcSMatthias Ringwald }
174*a8f7f3fcSMatthias Ringwald /**
175*a8f7f3fcSMatthias Ringwald * @brief Port Port Enabled callback.
176*a8f7f3fcSMatthias Ringwald * @param hhcd: HCD handle
177*a8f7f3fcSMatthias Ringwald * @retval None
178*a8f7f3fcSMatthias Ringwald */
HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef * hhcd)179*a8f7f3fcSMatthias Ringwald void HAL_HCD_PortEnabled_Callback(HCD_HandleTypeDef *hhcd)
180*a8f7f3fcSMatthias Ringwald {
181*a8f7f3fcSMatthias Ringwald USBH_LL_PortEnabled(hhcd->pData);
182*a8f7f3fcSMatthias Ringwald }
183*a8f7f3fcSMatthias Ringwald
184*a8f7f3fcSMatthias Ringwald /**
185*a8f7f3fcSMatthias Ringwald * @brief Port Port Disabled callback.
186*a8f7f3fcSMatthias Ringwald * @param hhcd: HCD handle
187*a8f7f3fcSMatthias Ringwald * @retval None
188*a8f7f3fcSMatthias Ringwald */
HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef * hhcd)189*a8f7f3fcSMatthias Ringwald void HAL_HCD_PortDisabled_Callback(HCD_HandleTypeDef *hhcd)
190*a8f7f3fcSMatthias Ringwald {
191*a8f7f3fcSMatthias Ringwald USBH_LL_PortDisabled(hhcd->pData);
192*a8f7f3fcSMatthias Ringwald }
193*a8f7f3fcSMatthias Ringwald
194*a8f7f3fcSMatthias Ringwald /*******************************************************************************
195*a8f7f3fcSMatthias Ringwald LL Driver Interface (USB Host Library --> HCD)
196*a8f7f3fcSMatthias Ringwald *******************************************************************************/
197*a8f7f3fcSMatthias Ringwald
198*a8f7f3fcSMatthias Ringwald /**
199*a8f7f3fcSMatthias Ringwald * @brief Initialize the low level portion of the host driver.
200*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
201*a8f7f3fcSMatthias Ringwald * @retval USBH status
202*a8f7f3fcSMatthias Ringwald */
USBH_LL_Init(USBH_HandleTypeDef * phost)203*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost)
204*a8f7f3fcSMatthias Ringwald {
205*a8f7f3fcSMatthias Ringwald /* Init USB_IP */
206*a8f7f3fcSMatthias Ringwald if (phost->id == HOST_FS) {
207*a8f7f3fcSMatthias Ringwald /* Link the driver to the stack. */
208*a8f7f3fcSMatthias Ringwald hhcd_USB_OTG_FS.pData = phost;
209*a8f7f3fcSMatthias Ringwald phost->pData = &hhcd_USB_OTG_FS;
210*a8f7f3fcSMatthias Ringwald
211*a8f7f3fcSMatthias Ringwald hhcd_USB_OTG_FS.Instance = USB_OTG_FS;
212*a8f7f3fcSMatthias Ringwald hhcd_USB_OTG_FS.Init.Host_channels = 8;
213*a8f7f3fcSMatthias Ringwald hhcd_USB_OTG_FS.Init.speed = HCD_SPEED_FULL;
214*a8f7f3fcSMatthias Ringwald hhcd_USB_OTG_FS.Init.dma_enable = DISABLE;
215*a8f7f3fcSMatthias Ringwald hhcd_USB_OTG_FS.Init.phy_itface = HCD_PHY_EMBEDDED;
216*a8f7f3fcSMatthias Ringwald hhcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
217*a8f7f3fcSMatthias Ringwald if (HAL_HCD_Init(&hhcd_USB_OTG_FS) != HAL_OK)
218*a8f7f3fcSMatthias Ringwald {
219*a8f7f3fcSMatthias Ringwald Error_Handler( );
220*a8f7f3fcSMatthias Ringwald }
221*a8f7f3fcSMatthias Ringwald
222*a8f7f3fcSMatthias Ringwald USBH_LL_SetTimer(phost, HAL_HCD_GetCurrentFrame(&hhcd_USB_OTG_FS));
223*a8f7f3fcSMatthias Ringwald }
224*a8f7f3fcSMatthias Ringwald return USBH_OK;
225*a8f7f3fcSMatthias Ringwald }
226*a8f7f3fcSMatthias Ringwald
227*a8f7f3fcSMatthias Ringwald /**
228*a8f7f3fcSMatthias Ringwald * @brief De-Initialize the low level portion of the host driver.
229*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
230*a8f7f3fcSMatthias Ringwald * @retval USBH status
231*a8f7f3fcSMatthias Ringwald */
USBH_LL_DeInit(USBH_HandleTypeDef * phost)232*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost)
233*a8f7f3fcSMatthias Ringwald {
234*a8f7f3fcSMatthias Ringwald HAL_StatusTypeDef hal_status = HAL_OK;
235*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
236*a8f7f3fcSMatthias Ringwald
237*a8f7f3fcSMatthias Ringwald hal_status = HAL_HCD_DeInit(phost->pData);
238*a8f7f3fcSMatthias Ringwald
239*a8f7f3fcSMatthias Ringwald usb_status = USBH_Get_USB_Status(hal_status);
240*a8f7f3fcSMatthias Ringwald
241*a8f7f3fcSMatthias Ringwald return usb_status;
242*a8f7f3fcSMatthias Ringwald }
243*a8f7f3fcSMatthias Ringwald
244*a8f7f3fcSMatthias Ringwald /**
245*a8f7f3fcSMatthias Ringwald * @brief Start the low level portion of the host driver.
246*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
247*a8f7f3fcSMatthias Ringwald * @retval USBH status
248*a8f7f3fcSMatthias Ringwald */
USBH_LL_Start(USBH_HandleTypeDef * phost)249*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_Start(USBH_HandleTypeDef *phost)
250*a8f7f3fcSMatthias Ringwald {
251*a8f7f3fcSMatthias Ringwald HAL_StatusTypeDef hal_status = HAL_OK;
252*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
253*a8f7f3fcSMatthias Ringwald
254*a8f7f3fcSMatthias Ringwald hal_status = HAL_HCD_Start(phost->pData);
255*a8f7f3fcSMatthias Ringwald
256*a8f7f3fcSMatthias Ringwald usb_status = USBH_Get_USB_Status(hal_status);
257*a8f7f3fcSMatthias Ringwald
258*a8f7f3fcSMatthias Ringwald return usb_status;
259*a8f7f3fcSMatthias Ringwald }
260*a8f7f3fcSMatthias Ringwald
261*a8f7f3fcSMatthias Ringwald /**
262*a8f7f3fcSMatthias Ringwald * @brief Stop the low level portion of the host driver.
263*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
264*a8f7f3fcSMatthias Ringwald * @retval USBH status
265*a8f7f3fcSMatthias Ringwald */
USBH_LL_Stop(USBH_HandleTypeDef * phost)266*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_Stop(USBH_HandleTypeDef *phost)
267*a8f7f3fcSMatthias Ringwald {
268*a8f7f3fcSMatthias Ringwald HAL_StatusTypeDef hal_status = HAL_OK;
269*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
270*a8f7f3fcSMatthias Ringwald
271*a8f7f3fcSMatthias Ringwald hal_status = HAL_HCD_Stop(phost->pData);
272*a8f7f3fcSMatthias Ringwald
273*a8f7f3fcSMatthias Ringwald usb_status = USBH_Get_USB_Status(hal_status);
274*a8f7f3fcSMatthias Ringwald
275*a8f7f3fcSMatthias Ringwald return usb_status;
276*a8f7f3fcSMatthias Ringwald }
277*a8f7f3fcSMatthias Ringwald
278*a8f7f3fcSMatthias Ringwald /**
279*a8f7f3fcSMatthias Ringwald * @brief Return the USB host speed from the low level driver.
280*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
281*a8f7f3fcSMatthias Ringwald * @retval USBH speeds
282*a8f7f3fcSMatthias Ringwald */
USBH_LL_GetSpeed(USBH_HandleTypeDef * phost)283*a8f7f3fcSMatthias Ringwald USBH_SpeedTypeDef USBH_LL_GetSpeed(USBH_HandleTypeDef *phost)
284*a8f7f3fcSMatthias Ringwald {
285*a8f7f3fcSMatthias Ringwald USBH_SpeedTypeDef speed = USBH_SPEED_FULL;
286*a8f7f3fcSMatthias Ringwald
287*a8f7f3fcSMatthias Ringwald switch (HAL_HCD_GetCurrentSpeed(phost->pData))
288*a8f7f3fcSMatthias Ringwald {
289*a8f7f3fcSMatthias Ringwald case 0 :
290*a8f7f3fcSMatthias Ringwald speed = USBH_SPEED_HIGH;
291*a8f7f3fcSMatthias Ringwald break;
292*a8f7f3fcSMatthias Ringwald
293*a8f7f3fcSMatthias Ringwald case 1 :
294*a8f7f3fcSMatthias Ringwald speed = USBH_SPEED_FULL;
295*a8f7f3fcSMatthias Ringwald break;
296*a8f7f3fcSMatthias Ringwald
297*a8f7f3fcSMatthias Ringwald case 2 :
298*a8f7f3fcSMatthias Ringwald speed = USBH_SPEED_LOW;
299*a8f7f3fcSMatthias Ringwald break;
300*a8f7f3fcSMatthias Ringwald
301*a8f7f3fcSMatthias Ringwald default:
302*a8f7f3fcSMatthias Ringwald speed = USBH_SPEED_FULL;
303*a8f7f3fcSMatthias Ringwald break;
304*a8f7f3fcSMatthias Ringwald }
305*a8f7f3fcSMatthias Ringwald return speed;
306*a8f7f3fcSMatthias Ringwald }
307*a8f7f3fcSMatthias Ringwald
308*a8f7f3fcSMatthias Ringwald /**
309*a8f7f3fcSMatthias Ringwald * @brief Reset the Host port of the low level driver.
310*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
311*a8f7f3fcSMatthias Ringwald * @retval USBH status
312*a8f7f3fcSMatthias Ringwald */
USBH_LL_ResetPort(USBH_HandleTypeDef * phost)313*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_ResetPort(USBH_HandleTypeDef *phost)
314*a8f7f3fcSMatthias Ringwald {
315*a8f7f3fcSMatthias Ringwald HAL_StatusTypeDef hal_status = HAL_OK;
316*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
317*a8f7f3fcSMatthias Ringwald
318*a8f7f3fcSMatthias Ringwald hal_status = HAL_HCD_ResetPort(phost->pData);
319*a8f7f3fcSMatthias Ringwald
320*a8f7f3fcSMatthias Ringwald usb_status = USBH_Get_USB_Status(hal_status);
321*a8f7f3fcSMatthias Ringwald
322*a8f7f3fcSMatthias Ringwald return usb_status;
323*a8f7f3fcSMatthias Ringwald }
324*a8f7f3fcSMatthias Ringwald
325*a8f7f3fcSMatthias Ringwald /**
326*a8f7f3fcSMatthias Ringwald * @brief Return the last transfered packet size.
327*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
328*a8f7f3fcSMatthias Ringwald * @param pipe: Pipe index
329*a8f7f3fcSMatthias Ringwald * @retval Packet size
330*a8f7f3fcSMatthias Ringwald */
USBH_LL_GetLastXferSize(USBH_HandleTypeDef * phost,uint8_t pipe)331*a8f7f3fcSMatthias Ringwald uint32_t USBH_LL_GetLastXferSize(USBH_HandleTypeDef *phost, uint8_t pipe)
332*a8f7f3fcSMatthias Ringwald {
333*a8f7f3fcSMatthias Ringwald return HAL_HCD_HC_GetXferCount(phost->pData, pipe);
334*a8f7f3fcSMatthias Ringwald }
335*a8f7f3fcSMatthias Ringwald
336*a8f7f3fcSMatthias Ringwald /**
337*a8f7f3fcSMatthias Ringwald * @brief Open a pipe of the low level driver.
338*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
339*a8f7f3fcSMatthias Ringwald * @param pipe_num: Pipe index
340*a8f7f3fcSMatthias Ringwald * @param epnum: Endpoint number
341*a8f7f3fcSMatthias Ringwald * @param dev_address: Device USB address
342*a8f7f3fcSMatthias Ringwald * @param speed: Device Speed
343*a8f7f3fcSMatthias Ringwald * @param ep_type: Endpoint type
344*a8f7f3fcSMatthias Ringwald * @param mps: Endpoint max packet size
345*a8f7f3fcSMatthias Ringwald * @retval USBH status
346*a8f7f3fcSMatthias Ringwald */
USBH_LL_OpenPipe(USBH_HandleTypeDef * phost,uint8_t pipe_num,uint8_t epnum,uint8_t dev_address,uint8_t speed,uint8_t ep_type,uint16_t mps)347*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_OpenPipe(USBH_HandleTypeDef *phost, uint8_t pipe_num, uint8_t epnum,
348*a8f7f3fcSMatthias Ringwald uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
349*a8f7f3fcSMatthias Ringwald {
350*a8f7f3fcSMatthias Ringwald HAL_StatusTypeDef hal_status = HAL_OK;
351*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
352*a8f7f3fcSMatthias Ringwald
353*a8f7f3fcSMatthias Ringwald hal_status = HAL_HCD_HC_Init(phost->pData, pipe_num, epnum,
354*a8f7f3fcSMatthias Ringwald dev_address, speed, ep_type, mps);
355*a8f7f3fcSMatthias Ringwald
356*a8f7f3fcSMatthias Ringwald usb_status = USBH_Get_USB_Status(hal_status);
357*a8f7f3fcSMatthias Ringwald
358*a8f7f3fcSMatthias Ringwald return usb_status;
359*a8f7f3fcSMatthias Ringwald }
360*a8f7f3fcSMatthias Ringwald
361*a8f7f3fcSMatthias Ringwald /**
362*a8f7f3fcSMatthias Ringwald * @brief Close a pipe of the low level driver.
363*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
364*a8f7f3fcSMatthias Ringwald * @param pipe: Pipe index
365*a8f7f3fcSMatthias Ringwald * @retval USBH status
366*a8f7f3fcSMatthias Ringwald */
USBH_LL_ClosePipe(USBH_HandleTypeDef * phost,uint8_t pipe)367*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_ClosePipe(USBH_HandleTypeDef *phost, uint8_t pipe)
368*a8f7f3fcSMatthias Ringwald {
369*a8f7f3fcSMatthias Ringwald HAL_StatusTypeDef hal_status = HAL_OK;
370*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
371*a8f7f3fcSMatthias Ringwald
372*a8f7f3fcSMatthias Ringwald hal_status = HAL_HCD_HC_Halt(phost->pData, pipe);
373*a8f7f3fcSMatthias Ringwald
374*a8f7f3fcSMatthias Ringwald usb_status = USBH_Get_USB_Status(hal_status);
375*a8f7f3fcSMatthias Ringwald
376*a8f7f3fcSMatthias Ringwald return usb_status;
377*a8f7f3fcSMatthias Ringwald }
378*a8f7f3fcSMatthias Ringwald
379*a8f7f3fcSMatthias Ringwald /**
380*a8f7f3fcSMatthias Ringwald * @brief Submit a new URB to the low level driver.
381*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
382*a8f7f3fcSMatthias Ringwald * @param pipe: Pipe index
383*a8f7f3fcSMatthias Ringwald * This parameter can be a value from 1 to 15
384*a8f7f3fcSMatthias Ringwald * @param direction : Channel number
385*a8f7f3fcSMatthias Ringwald * This parameter can be one of the these values:
386*a8f7f3fcSMatthias Ringwald * 0 : Output
387*a8f7f3fcSMatthias Ringwald * 1 : Input
388*a8f7f3fcSMatthias Ringwald * @param ep_type : Endpoint Type
389*a8f7f3fcSMatthias Ringwald * This parameter can be one of the these values:
390*a8f7f3fcSMatthias Ringwald * @arg EP_TYPE_CTRL: Control type
391*a8f7f3fcSMatthias Ringwald * @arg EP_TYPE_ISOC: Isochrounous type
392*a8f7f3fcSMatthias Ringwald * @arg EP_TYPE_BULK: Bulk type
393*a8f7f3fcSMatthias Ringwald * @arg EP_TYPE_INTR: Interrupt type
394*a8f7f3fcSMatthias Ringwald * @param token : Endpoint Type
395*a8f7f3fcSMatthias Ringwald * This parameter can be one of the these values:
396*a8f7f3fcSMatthias Ringwald * @arg 0: PID_SETUP
397*a8f7f3fcSMatthias Ringwald * @arg 1: PID_DATA
398*a8f7f3fcSMatthias Ringwald * @param pbuff : pointer to URB data
399*a8f7f3fcSMatthias Ringwald * @param length : Length of URB data
400*a8f7f3fcSMatthias Ringwald * @param do_ping : activate do ping protocol (for high speed only)
401*a8f7f3fcSMatthias Ringwald * This parameter can be one of the these values:
402*a8f7f3fcSMatthias Ringwald * 0 : do ping inactive
403*a8f7f3fcSMatthias Ringwald * 1 : do ping active
404*a8f7f3fcSMatthias Ringwald * @retval Status
405*a8f7f3fcSMatthias Ringwald */
USBH_LL_SubmitURB(USBH_HandleTypeDef * phost,uint8_t pipe,uint8_t direction,uint8_t ep_type,uint8_t token,uint8_t * pbuff,uint16_t length,uint8_t do_ping)406*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_SubmitURB(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t direction,
407*a8f7f3fcSMatthias Ringwald uint8_t ep_type, uint8_t token, uint8_t *pbuff, uint16_t length,
408*a8f7f3fcSMatthias Ringwald uint8_t do_ping)
409*a8f7f3fcSMatthias Ringwald {
410*a8f7f3fcSMatthias Ringwald HAL_StatusTypeDef hal_status = HAL_OK;
411*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
412*a8f7f3fcSMatthias Ringwald
413*a8f7f3fcSMatthias Ringwald hal_status = HAL_HCD_HC_SubmitRequest(phost->pData, pipe, direction ,
414*a8f7f3fcSMatthias Ringwald ep_type, token, pbuff, length,
415*a8f7f3fcSMatthias Ringwald do_ping);
416*a8f7f3fcSMatthias Ringwald usb_status = USBH_Get_USB_Status(hal_status);
417*a8f7f3fcSMatthias Ringwald
418*a8f7f3fcSMatthias Ringwald return usb_status;
419*a8f7f3fcSMatthias Ringwald }
420*a8f7f3fcSMatthias Ringwald
421*a8f7f3fcSMatthias Ringwald /**
422*a8f7f3fcSMatthias Ringwald * @brief Get a URB state from the low level driver.
423*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
424*a8f7f3fcSMatthias Ringwald * @param pipe: Pipe index
425*a8f7f3fcSMatthias Ringwald * This parameter can be a value from 1 to 15
426*a8f7f3fcSMatthias Ringwald * @retval URB state
427*a8f7f3fcSMatthias Ringwald * This parameter can be one of the these values:
428*a8f7f3fcSMatthias Ringwald * @arg URB_IDLE
429*a8f7f3fcSMatthias Ringwald * @arg URB_DONE
430*a8f7f3fcSMatthias Ringwald * @arg URB_NOTREADY
431*a8f7f3fcSMatthias Ringwald * @arg URB_NYET
432*a8f7f3fcSMatthias Ringwald * @arg URB_ERROR
433*a8f7f3fcSMatthias Ringwald * @arg URB_STALL
434*a8f7f3fcSMatthias Ringwald */
USBH_LL_GetURBState(USBH_HandleTypeDef * phost,uint8_t pipe)435*a8f7f3fcSMatthias Ringwald USBH_URBStateTypeDef USBH_LL_GetURBState(USBH_HandleTypeDef *phost, uint8_t pipe)
436*a8f7f3fcSMatthias Ringwald {
437*a8f7f3fcSMatthias Ringwald return (USBH_URBStateTypeDef)HAL_HCD_HC_GetURBState (phost->pData, pipe);
438*a8f7f3fcSMatthias Ringwald }
439*a8f7f3fcSMatthias Ringwald
440*a8f7f3fcSMatthias Ringwald /**
441*a8f7f3fcSMatthias Ringwald * @brief Drive VBUS.
442*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
443*a8f7f3fcSMatthias Ringwald * @param state : VBUS state
444*a8f7f3fcSMatthias Ringwald * This parameter can be one of the these values:
445*a8f7f3fcSMatthias Ringwald * 0 : VBUS Inactive
446*a8f7f3fcSMatthias Ringwald * 1 : VBUS Active
447*a8f7f3fcSMatthias Ringwald * @retval Status
448*a8f7f3fcSMatthias Ringwald */
USBH_LL_DriverVBUS(USBH_HandleTypeDef * phost,uint8_t state)449*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state)
450*a8f7f3fcSMatthias Ringwald {
451*a8f7f3fcSMatthias Ringwald if (phost->id == HOST_FS) {
452*a8f7f3fcSMatthias Ringwald MX_DriverVbusFS(state);
453*a8f7f3fcSMatthias Ringwald }
454*a8f7f3fcSMatthias Ringwald
455*a8f7f3fcSMatthias Ringwald /* USER CODE BEGIN 0 */
456*a8f7f3fcSMatthias Ringwald
457*a8f7f3fcSMatthias Ringwald /* USER CODE END 0*/
458*a8f7f3fcSMatthias Ringwald
459*a8f7f3fcSMatthias Ringwald HAL_Delay(200);
460*a8f7f3fcSMatthias Ringwald return USBH_OK;
461*a8f7f3fcSMatthias Ringwald }
462*a8f7f3fcSMatthias Ringwald
463*a8f7f3fcSMatthias Ringwald /**
464*a8f7f3fcSMatthias Ringwald * @brief Set toggle for a pipe.
465*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
466*a8f7f3fcSMatthias Ringwald * @param pipe: Pipe index
467*a8f7f3fcSMatthias Ringwald * @param toggle: toggle (0/1)
468*a8f7f3fcSMatthias Ringwald * @retval Status
469*a8f7f3fcSMatthias Ringwald */
USBH_LL_SetToggle(USBH_HandleTypeDef * phost,uint8_t pipe,uint8_t toggle)470*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_LL_SetToggle(USBH_HandleTypeDef *phost, uint8_t pipe, uint8_t toggle)
471*a8f7f3fcSMatthias Ringwald {
472*a8f7f3fcSMatthias Ringwald HCD_HandleTypeDef *pHandle;
473*a8f7f3fcSMatthias Ringwald pHandle = phost->pData;
474*a8f7f3fcSMatthias Ringwald
475*a8f7f3fcSMatthias Ringwald if(pHandle->hc[pipe].ep_is_in)
476*a8f7f3fcSMatthias Ringwald {
477*a8f7f3fcSMatthias Ringwald pHandle->hc[pipe].toggle_in = toggle;
478*a8f7f3fcSMatthias Ringwald }
479*a8f7f3fcSMatthias Ringwald else
480*a8f7f3fcSMatthias Ringwald {
481*a8f7f3fcSMatthias Ringwald pHandle->hc[pipe].toggle_out = toggle;
482*a8f7f3fcSMatthias Ringwald }
483*a8f7f3fcSMatthias Ringwald
484*a8f7f3fcSMatthias Ringwald return USBH_OK;
485*a8f7f3fcSMatthias Ringwald }
486*a8f7f3fcSMatthias Ringwald
487*a8f7f3fcSMatthias Ringwald /**
488*a8f7f3fcSMatthias Ringwald * @brief Return the current toggle of a pipe.
489*a8f7f3fcSMatthias Ringwald * @param phost: Host handle
490*a8f7f3fcSMatthias Ringwald * @param pipe: Pipe index
491*a8f7f3fcSMatthias Ringwald * @retval toggle (0/1)
492*a8f7f3fcSMatthias Ringwald */
USBH_LL_GetToggle(USBH_HandleTypeDef * phost,uint8_t pipe)493*a8f7f3fcSMatthias Ringwald uint8_t USBH_LL_GetToggle(USBH_HandleTypeDef *phost, uint8_t pipe)
494*a8f7f3fcSMatthias Ringwald {
495*a8f7f3fcSMatthias Ringwald uint8_t toggle = 0;
496*a8f7f3fcSMatthias Ringwald HCD_HandleTypeDef *pHandle;
497*a8f7f3fcSMatthias Ringwald pHandle = phost->pData;
498*a8f7f3fcSMatthias Ringwald
499*a8f7f3fcSMatthias Ringwald if(pHandle->hc[pipe].ep_is_in)
500*a8f7f3fcSMatthias Ringwald {
501*a8f7f3fcSMatthias Ringwald toggle = pHandle->hc[pipe].toggle_in;
502*a8f7f3fcSMatthias Ringwald }
503*a8f7f3fcSMatthias Ringwald else
504*a8f7f3fcSMatthias Ringwald {
505*a8f7f3fcSMatthias Ringwald toggle = pHandle->hc[pipe].toggle_out;
506*a8f7f3fcSMatthias Ringwald }
507*a8f7f3fcSMatthias Ringwald return toggle;
508*a8f7f3fcSMatthias Ringwald }
509*a8f7f3fcSMatthias Ringwald
510*a8f7f3fcSMatthias Ringwald /**
511*a8f7f3fcSMatthias Ringwald * @brief Delay routine for the USB Host Library
512*a8f7f3fcSMatthias Ringwald * @param Delay: Delay in ms
513*a8f7f3fcSMatthias Ringwald * @retval None
514*a8f7f3fcSMatthias Ringwald */
USBH_Delay(uint32_t Delay)515*a8f7f3fcSMatthias Ringwald void USBH_Delay(uint32_t Delay)
516*a8f7f3fcSMatthias Ringwald {
517*a8f7f3fcSMatthias Ringwald HAL_Delay(Delay);
518*a8f7f3fcSMatthias Ringwald }
519*a8f7f3fcSMatthias Ringwald
520*a8f7f3fcSMatthias Ringwald /**
521*a8f7f3fcSMatthias Ringwald * @brief Retuns the USB status depending on the HAL status:
522*a8f7f3fcSMatthias Ringwald * @param hal_status: HAL status
523*a8f7f3fcSMatthias Ringwald * @retval USB status
524*a8f7f3fcSMatthias Ringwald */
USBH_Get_USB_Status(HAL_StatusTypeDef hal_status)525*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef USBH_Get_USB_Status(HAL_StatusTypeDef hal_status)
526*a8f7f3fcSMatthias Ringwald {
527*a8f7f3fcSMatthias Ringwald USBH_StatusTypeDef usb_status = USBH_OK;
528*a8f7f3fcSMatthias Ringwald
529*a8f7f3fcSMatthias Ringwald switch (hal_status)
530*a8f7f3fcSMatthias Ringwald {
531*a8f7f3fcSMatthias Ringwald case HAL_OK :
532*a8f7f3fcSMatthias Ringwald usb_status = USBH_OK;
533*a8f7f3fcSMatthias Ringwald break;
534*a8f7f3fcSMatthias Ringwald case HAL_ERROR :
535*a8f7f3fcSMatthias Ringwald usb_status = USBH_FAIL;
536*a8f7f3fcSMatthias Ringwald break;
537*a8f7f3fcSMatthias Ringwald case HAL_BUSY :
538*a8f7f3fcSMatthias Ringwald usb_status = USBH_BUSY;
539*a8f7f3fcSMatthias Ringwald break;
540*a8f7f3fcSMatthias Ringwald case HAL_TIMEOUT :
541*a8f7f3fcSMatthias Ringwald usb_status = USBH_FAIL;
542*a8f7f3fcSMatthias Ringwald break;
543*a8f7f3fcSMatthias Ringwald default :
544*a8f7f3fcSMatthias Ringwald usb_status = USBH_FAIL;
545*a8f7f3fcSMatthias Ringwald break;
546*a8f7f3fcSMatthias Ringwald }
547*a8f7f3fcSMatthias Ringwald return usb_status;
548*a8f7f3fcSMatthias Ringwald }
549*a8f7f3fcSMatthias Ringwald
550*a8f7f3fcSMatthias Ringwald /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
551