Fixed Mass Storage Host Class driver and Low Level demo not clearing the error condit...
[pub/USBasp.git] / Demos / Host / LowLevel / MassStorageHost / Lib / MassStoreCommands.c
index ff01dc0..edd1425 100644 (file)
@@ -287,13 +287,17 @@ uint8_t MassStore_MassStorageReset(void)
 /** Issues a Mass Storage class specific request to determine the index of the highest numbered Logical\r
  *  Unit in the attached device.\r
  *\r
+ *  \note Some devices do not support this request, and will STALL it when issued. To get around this,\r
+ *        on unsupported devices the max LUN index will be reported as zero and no error will be returned\r
+ *        if the device STALLs the request.\r
+ *\r
  *  \param[out] MaxLUNIndex  Pointer to the location that the maximum LUN index value should be stored\r
  *\r
  *  \return A value from the USB_Host_SendControlErrorCodes_t enum, or MASS_STORE_SCSI_COMMAND_FAILED if the SCSI command fails\r
  */\r
 uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex)\r
 {\r
-       uint8_t ErrorCode;\r
+       uint8_t ErrorCode = HOST_SENDCONTROL_Successful;\r
 \r
        USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
@@ -313,7 +317,10 @@ uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex)
                Pipe_ClearStall();\r
        \r
                /* Some faulty Mass Storage devices don't implement the GET_MAX_LUN request, so assume a single LUN */\r
-               *MaxLUNIndex = 0;       \r
+               *MaxLUNIndex = 0;\r
+               \r
+               /* Clear the error, and pretend the request executed correctly if the device STALLed it */\r
+               ErrorCode = HOST_SENDCONTROL_Successful;\r
        }\r
        \r
        return ErrorCode;\r