目录
1入口函数
1.1 初始化函数
//文件:STM32F723E-Discovery\Applications\USB_Host\MSC_RTOS\Src\main.c
static void MSC_InitApplication(void)
{
/* Configure Key Button */
BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);
/* Initialize the LCD */
BSP_LCD_Init();
/* Initialize the TS in IT mode if not already initialized */
if (TouchScreen_IsCalibrationDone() == 0)
{
Touchscreen_Calibration();
}
BSP_TS_ITConfig();
/* Init the LCD Log module */
LCD_LOG_Init();
#ifdef USE_USB_HS
LCD_LOG_SetHeader((uint8_t *) " USB OTG HS MSC Host");
#else
LCD_LOG_SetHeader((uint8_t *) " USB OTG FS MSC Host");
#endif
LCD_UsrLog("USB Host library started.\n");
/* Start MSC Interface */
USBH_UsrLog("Starting MSC Demo");
Menu_Init(); //初始化menu
}
void Menu_Init(void)
{
USBH_UsrLog("Starting MSC Demo");
/* Create Menu Semaphore */
osSemaphoreDef(osSem);
MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1);
/* Force menu to show Item 0 by default */
osSemaphoreRelease(MenuEvent);
/* Menu task */
osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0,
8 * configMINIMAL_STACK_SIZE);
osThreadCreate(osThread(Menu_Thread), NULL);
}
1.2 USB初始化
static void StartThread(void const *argument)
{
osEvent event;
/* Init MSC Application */
MSC_InitApplication();
/* Start Host Library */
USBH_Init(&hUSBHost, USBH_UserProcess, 0);
/* Add Supported Class */
USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
/* Start Host Process */
USBH_Start(&hUSBHost);
}
1.3 注册函数
// 文件:STM32CubeF7_V1.14.0\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c
USBH_ClassTypeDef USBH_msc =
{
"MSC",
USB_MSC_CLASS,
USBH_MSC_InterfaceInit,
USBH_MSC_InterfaceDeInit,
USBH_MSC_ClassRequest,
USBH_MSC_Process,
USBH_MSC_SOFProcess,
NULL,
};
/* Add Supported Class */
USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);
// STM32CubeF7_V1.14.0\Projects\STM32F723E-Discovery\Applications\USB_Host\MSC_RTOS\Src\main.c
//初始化结构体 phost->pClass
USBH_StatusTypeDef USBH_RegisterClass(USBH_HandleTypeDef *phost, USBH_ClassTypeDef *pclass)
{
USBH_StatusTypeDef status = USBH_OK;
if (pclass != 0)
{
if (phost->ClassNumber < USBH_MAX_NUM_SUPPORTED_CLASS)
{
/* link the class to the USB Host handle */
phost->pClass[phost->ClassNumber++] = pclass;
status = USBH_OK;
}
else
{
USBH_ErrLog("Max Class Number reached");
status = USBH_FAIL;
}
}
..... //省略
}
1.4 创建 USBH_Process_OS
#if (USBH_USE_OS == 1U)
/* Create USB Host Queue */
osMessageQDef(USBH_Queue, 10, uint16_t);
phost->os_event = osMessageCreate(osMessageQ(USBH_Queue), NULL);
/*Create USB Host Task */
#if defined (USBH_PROCESS_STACK_SIZE)
osThreadDef(USBH_Thread, USBH_Process_OS, USBH_PROCESS_PRIO, 0, USBH_PROCESS_STACK_SIZE);
#else
osThreadDef(USBH_Thread, USBH_Process_OS, USBH_PROCESS_PRIO, 0, 8 * configMINIMAL_STACK_SIZE);
#endif
phost->thread = osThreadCreate(osThread(USBH_Th