From 4c4f59d6381d3dd768b38c830e65a7595c4fd2e9 Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Thu, 22 Aug 2019 06:47:21 +1200 Subject: [PATCH] Delay GetMaxLUN command by 100ms. Conflicts: Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c --- .../Class/MSC/Inc/usbh_msc.h | 9 +++--- .../Class/MSC/Src/usbh_msc.c | 29 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h index 902ab7f..8580dea 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc/usbh_msc.h @@ -72,8 +72,9 @@ MSC_ErrorTypeDef; typedef enum { MSC_REQ_IDLE = 0, - MSC_REQ_RESET, - MSC_REQ_GET_MAX_LUN, + MSC_REQ_STARTUP_DELAY, + MSC_REQ_GET_MAX_LUN, + MSC_REQ_RESET, MSC_REQ_ERROR, } MSC_ReqStateTypeDef; @@ -138,8 +139,8 @@ MSC_HandleTypeDef; #define USB_REQ_BOT_RESET 0xFF #define USB_REQ_GET_MAX_LUN 0xFE -//#define MSC_TIMEOUT_FRAMES_PER_BLOCK 1000 -#define MSC_TIMEOUT_FIXED 10000 //Some flash drives take 2 seconds to write a single block! +#define MSC_TIMEOUT_FIXED_MS 10000 //Some flash drives take 2 seconds to write a single block! +#define MSC_SAMSUNG_STARTUP_DELAY_MS 100 //Samsung FIT Plus 32GB USB 3.1 flash drive was here /* MSC Class Codes */ diff --git a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c index b6b9130..bcbadb3 100644 --- a/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c +++ b/Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c @@ -277,12 +277,22 @@ static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost) { MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; USBH_StatusTypeDef status = USBH_BUSY; - uint8_t i; /* Switch MSC REQ state machine */ switch (MSC_Handle->req_state) { case MSC_REQ_IDLE: + MSC_Handle->timeout = HAL_GetTick(); + MSC_Handle->req_state = MSC_REQ_STARTUP_DELAY; + break; + + case MSC_REQ_STARTUP_DELAY: + if ((HAL_GetTick() - MSC_Handle->timeout) > MSC_SAMSUNG_STARTUP_DELAY_MS) + { + MSC_Handle->req_state = MSC_REQ_GET_MAX_LUN; + } + break; + case MSC_REQ_GET_MAX_LUN: /* Issue GetMaxLUN request */ status = USBH_MSC_BOT_REQ_GetMaxLUN(phost, (uint8_t *)&MSC_Handle->max_lun); @@ -303,12 +313,8 @@ static USBH_StatusTypeDef USBH_MSC_ClassRequest(USBH_HandleTypeDef *phost) if (MSC_Handle->max_lun > MAX_SUPPORTED_LUN) { MSC_Handle->max_lun = MAX_SUPPORTED_LUN; - } - for(i = 0; i < MSC_Handle->max_lun; i++) - { - MSC_Handle->unit[i].prev_ready_state = USBH_FAIL; - MSC_Handle->unit[i].state_changed = 0; - } + } + MSC_Handle->req_state = MSC_REQ_IDLE; } break; @@ -355,6 +361,7 @@ static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost) USBH_UsrLog ("LUN #%d: ", MSC_Handle->current_lun); MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_READ_INQUIRY; MSC_Handle->timeout = phost->Timer; + //Fallthrough case MSC_READ_INQUIRY: scsi_status = USBH_MSC_SCSI_Inquiry(phost, MSC_Handle->current_lun, &MSC_Handle->unit[MSC_Handle->current_lun].inquiry); @@ -751,8 +758,8 @@ USBH_StatusTypeDef USBH_MSC_Read(USBH_HandleTypeDef *phost, MSC_Handle->state = MSC_READ; MSC_Handle->unit[lun].state = MSC_READ; MSC_Handle->rw_lun = lun; - MSC_Handle->RdWrCompleteCallback = callback; - MSC_Handle->timeout = phost->Timer + MSC_TIMEOUT_FIXED; + MSC_Handle->RdWrCompleteCallback = callback; + MSC_Handle->timeout = HAL_GetTick() + MSC_TIMEOUT_FIXED_MS; USBH_MSC_SCSI_Read(phost, lun, @@ -793,8 +800,8 @@ USBH_StatusTypeDef USBH_MSC_Write(USBH_HandleTypeDef *phost, MSC_Handle->state = MSC_WRITE; MSC_Handle->unit[lun].state = MSC_WRITE; MSC_Handle->rw_lun = lun; - MSC_Handle->RdWrCompleteCallback = callback; - MSC_Handle->timeout = phost->Timer + MSC_TIMEOUT_FIXED; + MSC_Handle->RdWrCompleteCallback = callback; + MSC_Handle->timeout = HAL_GetTick() + MSC_TIMEOUT_FIXED_MS; USBH_MSC_SCSI_Write(phost, lun,