From f0fcead7180bd3ec48356e967fea6162b13f0c51 Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Mon, 19 Aug 2019 13:15:36 +1200 Subject: [PATCH] Don't spam device while waiting for MSC unit ready Conflicts: Downstream/Middlewares/ST/STM32_USB_Host_Library/Class/MSC/Src/usbh_msc.c --- .../Class/MSC/Inc/usbh_msc.h | 6 ++++++ .../Class/MSC/Src/usbh_msc.c | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 5 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 0118c89..4729f9f 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 @@ -52,6 +52,7 @@ typedef enum MSC_READ_CAPACITY10, MSC_READ_INQUIRY, MSC_REQUEST_SENSE, + MSC_REQUEST_SENSE_WAIT_RETRY, MSC_READ, MSC_WRITE, MSC_UNRECOVERED_ERROR, @@ -118,6 +119,7 @@ typedef struct _MSC_Process uint16_t current_lun; uint16_t rw_lun; uint32_t timeout; + uint32_t retry_timeout; MSC_RdWrCompleteCallback RdWrCompleteCallback; } MSC_HandleTypeDef; @@ -145,6 +147,10 @@ MSC_HandleTypeDef; /* Interface Descriptor field values for MSC Protocol */ #define MSC_BOT 0x50 #define MSC_TRANSPARENT 0x06 + +#define MSC_STARTUP_TIMEOUT_MS 15000 +#define MSC_STARTUP_RETRY_TIME_MS 100 + /** * @} */ 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 af5b214..b6b9130 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 @@ -452,11 +452,11 @@ static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost) { if((MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_UNIT_ATTENTION) || (MSC_Handle->unit[MSC_Handle->current_lun].sense.key == SCSI_SENSE_KEY_NOT_READY) ) - { - - if((phost->Timer - MSC_Handle->timeout) < 10000) + { + if((HAL_GetTick() - MSC_Handle->timeout) < MSC_STARTUP_TIMEOUT_MS) { - MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY; + MSC_Handle->retry_timeout = HAL_GetTick(); + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_REQUEST_SENSE_WAIT_RETRY; break; } } @@ -477,7 +477,14 @@ static USBH_StatusTypeDef USBH_MSC_Process(USBH_HandleTypeDef *phost) MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_IDLE; MSC_Handle->unit[MSC_Handle->current_lun].error = MSC_ERROR; } - break; + break; + + case MSC_REQUEST_SENSE_WAIT_RETRY: + if ((HAL_GetTick() - MSC_Handle->retry_timeout) > MSC_STARTUP_RETRY_TIME_MS) + { + MSC_Handle->unit[MSC_Handle->current_lun].state = MSC_TEST_UNIT_READY; + } + break; case MSC_UNRECOVERED_ERROR: MSC_Handle->current_lun++;