a
This commit is contained in:
128
USB_HOST/App/usb_host.c
Normal file
128
USB_HOST/App/usb_host.c
Normal file
@ -0,0 +1,128 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usb_host.c
|
||||
* @version : v1.0_Cube
|
||||
* @brief : This file implements the USB Host
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "usb_host.h"
|
||||
#include "usbh_core.h"
|
||||
#include "usbh_cdc.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* USER CODE BEGIN PFP */
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* USB Host core handle declaration */
|
||||
USBH_HandleTypeDef hUsbHostHS;
|
||||
ApplicationTypeDef Appli_state = APPLICATION_IDLE;
|
||||
|
||||
/*
|
||||
* -- Insert your variables declaration here --
|
||||
*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/*
|
||||
* user callback declaration
|
||||
*/
|
||||
static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id);
|
||||
|
||||
/*
|
||||
* -- Insert your external function declaration here --
|
||||
*/
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/**
|
||||
* Init USB host library, add supported class and start the library
|
||||
* @retval None
|
||||
*/
|
||||
void MX_USB_HOST_Init(void)
|
||||
{
|
||||
/* USER CODE BEGIN USB_HOST_Init_PreTreatment */
|
||||
|
||||
/* USER CODE END USB_HOST_Init_PreTreatment */
|
||||
|
||||
/* Init host Library, add supported class and start the library. */
|
||||
if (USBH_Init(&hUsbHostHS, USBH_UserProcess, HOST_HS) != USBH_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (USBH_RegisterClass(&hUsbHostHS, USBH_CDC_CLASS) != USBH_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (USBH_Start(&hUsbHostHS) != USBH_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN USB_HOST_Init_PostTreatment */
|
||||
|
||||
/* USER CODE END USB_HOST_Init_PostTreatment */
|
||||
}
|
||||
|
||||
/*
|
||||
* user callback definition
|
||||
*/
|
||||
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
|
||||
{
|
||||
/* USER CODE BEGIN CALL_BACK_1 */
|
||||
switch(id)
|
||||
{
|
||||
case HOST_USER_SELECT_CONFIGURATION:
|
||||
break;
|
||||
|
||||
case HOST_USER_DISCONNECTION:
|
||||
Appli_state = APPLICATION_DISCONNECT;
|
||||
break;
|
||||
|
||||
case HOST_USER_CLASS_ACTIVE:
|
||||
Appli_state = APPLICATION_READY;
|
||||
break;
|
||||
|
||||
case HOST_USER_CONNECTION:
|
||||
Appli_state = APPLICATION_START;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* USER CODE END CALL_BACK_1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
90
USB_HOST/App/usb_host.h
Normal file
90
USB_HOST/App/usb_host.h
Normal file
@ -0,0 +1,90 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : usb_host.h
|
||||
* @version : v1.0_Cube
|
||||
* @brief : Header for usb_host.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_HOST__H__
|
||||
#define __USB_HOST__H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
/* USER CODE END INCLUDE */
|
||||
|
||||
/** @addtogroup USBH_OTG_DRIVER
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HOST USBH_HOST
|
||||
* @brief Host file for Usb otg low level driver.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBH_HOST_Exported_Variables USBH_HOST_Exported_Variables
|
||||
* @brief Public variables.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** Status of the application. */
|
||||
typedef enum {
|
||||
APPLICATION_IDLE = 0,
|
||||
APPLICATION_START,
|
||||
APPLICATION_READY,
|
||||
APPLICATION_DISCONNECT
|
||||
}ApplicationTypeDef;
|
||||
|
||||
/** @defgroup USBH_HOST_Exported_FunctionsPrototype USBH_HOST_Exported_FunctionsPrototype
|
||||
* @brief Declaration of public functions for Usb host.
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Exported functions -------------------------------------------------------*/
|
||||
|
||||
/** @brief USB Host initialization function. */
|
||||
void MX_USB_HOST_Init(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_HOST__H__ */
|
||||
|
Reference in New Issue
Block a user