diff --git a/Upstream/.cproject b/Upstream/.cproject index b1c7159..cb9c94f 100755 --- a/Upstream/.cproject +++ b/Upstream/.cproject @@ -104,6 +104,7 @@ diff --git a/Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h b/Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h index 82a4f08..597a521 100755 --- a/Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h +++ b/Upstream/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h @@ -70,18 +70,6 @@ /** @defgroup USB_CORE_Exported_Types * @{ */ -typedef struct _USBD_STORAGE -{ - int8_t (* Init) (uint8_t lun); - int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint16_t *block_size); - int8_t (* IsReady) (uint8_t lun); - int8_t (* IsWriteProtected) (uint8_t lun); - int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); - int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len); - int8_t (* GetMaxLun)(void); - int8_t *pInquiry; - -}USBD_StorageTypeDef; typedef struct @@ -113,8 +101,6 @@ USBD_MSC_BOT_HandleTypeDef; extern USBD_ClassTypeDef USBD_MSC; #define USBD_MSC_CLASS &USBD_MSC -uint8_t USBD_MSC_RegisterStorage (USBD_HandleTypeDef *pdev, - USBD_StorageTypeDef *fops); /** * @} */ diff --git a/Upstream/Src/downstream_interface_msc.c b/Upstream/Src/downstream_interface_msc.c index 4e7d347..7db5484 100644 --- a/Upstream/Src/downstream_interface_msc.c +++ b/Upstream/Src/downstream_interface_msc.c @@ -20,6 +20,7 @@ uint64_t BlockStart; uint32_t BlockCount; uint32_t ByteCount; DownstreamPacketTypeDef* ReadStreamPacket; +uint8_t ReadStreamBusy; static void DownstreamInterface_TestReadyReplyCallback(DownstreamPacketTypeDef* replyPacket); @@ -109,10 +110,9 @@ HAL_StatusTypeDef DownstreamInterface_BeginRead(DownstreamInterfaceMSCCallbackTy { DownstreamPacketTypeDef* freePacket; HAL_StatusTypeDef tempResult; - uint64_t* workDammit; - uint32_t* prettyPlease; ReadStreamPacket = NULL; //Prepare for GetStreamDataPacket's use + ReadStreamBusy = 0; TestReadyCallback = callback; BlockStart = readBlockStart; @@ -123,10 +123,9 @@ HAL_StatusTypeDef DownstreamInterface_BeginRead(DownstreamInterfaceMSCCallbackTy freePacket->Length = DOWNSTREAM_PACKET_HEADER_LEN + (4 * 3); freePacket->CommandClass = COMMAND_CLASS_MASS_STORAGE; freePacket->Command = COMMAND_MSC_BEGIN_READ; - workDammit = (uint64_t*)&(freePacket->Data[0]); - *workDammit = BlockStart; - prettyPlease = (uint32_t*)&(freePacket->Data[8]); - *prettyPlease = BlockCount; + *(uint64_t*)&(freePacket->Data[0]) = BlockStart; + *(uint32_t*)&(freePacket->Data[8]) = BlockCount; + tempResult = Downstream_SendPacket(freePacket); if (tempResult != HAL_OK) { @@ -140,8 +139,13 @@ HAL_StatusTypeDef DownstreamInterface_GetStreamDataPacket(DownstreamInterfaceMSC { GetStreamDataCallback = callback; - //We have a callback address. Do we have a stored packet? - if (ReadStreamPacket) + if (ReadStreamBusy != 0) + { + return HAL_OK; + } + ReadStreamBusy = 1; + + if (ReadStreamPacket && GetStreamDataCallback) //Do we have a stored packet and an address to send it? { DownstreamInterface_GetStreamDataPacketCallback(ReadStreamPacket); //Send it now! ReadStreamPacket = NULL; @@ -152,6 +156,7 @@ HAL_StatusTypeDef DownstreamInterface_GetStreamDataPacket(DownstreamInterfaceMSC void DownstreamInterface_GetStreamDataPacketCallback(DownstreamPacketTypeDef* replyPacket) { + ReadStreamBusy = 0; if (GetStreamDataCallback == NULL) { ReadStreamPacket = replyPacket; //We used up our callback already, so save this one for later. @@ -163,11 +168,14 @@ void DownstreamInterface_GetStreamDataPacketCallback(DownstreamPacketTypeDef* re (replyPacket->Length > ByteCount)) { GetStreamDataCallback(HAL_ERROR, NULL); + return; } - else + + ByteCount -= replyPacket->Length; + GetStreamDataCallback(HAL_OK, replyPacket); //usb_msc_scsi will use this packet, so don't release now + if (ByteCount > 0) { - ByteCount -= replyPacket->Length; - GetStreamDataCallback(HAL_OK, replyPacket); //usb_msc_scsi will use this packet, so don't release now + DownstreamInterface_GetStreamDataPacket(NULL); //Try to get the next packet now, before USB asks for it } }