Skip to content

Commit

Permalink
fix msc device with transfer len > 65k bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Jun 23, 2018
1 parent 84ef486 commit 6b2b6aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 11 additions & 7 deletions src/class/msc/msc_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ typedef struct {
uint8_t ep_out;

uint8_t stage;
uint16_t data_len;
uint16_t xferred_len; // numbered of bytes transferred so far in the Data Stage
uint32_t data_len;
uint32_t xferred_len; // numbered of bytes transferred so far in the Data Stage
}mscd_interface_t;

CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf;
Expand Down Expand Up @@ -225,8 +225,10 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u
}
else
{
p_msc->data_len = tud_msc_scsi_cb(rhport, p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->data_len);
p_csw->status = (p_msc->data_len >= 0) ? MSC_CSW_STATUS_PASSED : MSC_CSW_STATUS_FAILED;
int32_t const cb_result = tud_msc_scsi_cb(rhport, p_cbw->lun, p_cbw->command, _mscd_buf, p_msc->data_len);

p_csw->status = (cb_result >= 0) ? MSC_CSW_STATUS_PASSED : MSC_CSW_STATUS_FAILED;
p_msc->data_len = (uint32_t) cb_result;

TU_ASSERT( p_cbw->xfer_bytes >= p_msc->data_len, TUSB_ERROR_INVALID_PARA ); // cannot return more than host expect

Expand Down Expand Up @@ -329,14 +331,16 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u

if ( p_msc->stage == MSC_STAGE_STATUS )
{
// Invoke Complete Callback if defined
// Invoke complete callback if defined
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
{
if ( tud_msc_read10_complete_cb ) tud_msc_read10_complete_cb(rhport, p_cbw->lun);
}else if ( SCSI_CMD_WRITE_10 == p_cbw->command[0] )
}
else if ( SCSI_CMD_WRITE_10 == p_cbw->command[0] )
{
if ( tud_msc_write10_complete_cb ) tud_msc_write10_complete_cb(rhport, p_cbw->lun);
}else
}
else
{
if ( tud_msc_scsi_complete_cb ) tud_msc_scsi_complete_cb(rhport, p_cbw->lun, p_cbw->command);
}
Expand Down
8 changes: 5 additions & 3 deletions src/portable/nordic/nrf5x/dcd_nrf5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static void xact_out_dma(uint8_t epnum)
/*------------- Bulk/Int IN transfer -------------*/

/**
* Prepare Bulk/Int in transaction, transfer data from Memory -> Endpoint
* Prepare Bulk/Int in transaction, use DMA to transfer data from Memory -> Endpoint
* @param epnum
*/
static void xact_in_prepare(uint8_t epnum)
Expand Down Expand Up @@ -415,8 +415,8 @@ void USBD_IRQHandler(void)
if ( int_status & USBD_INTEN_EP0SETUP_Msk )
{
uint8_t setup[8] = {
NRF_USBD->BMREQUESTTYPE, NRF_USBD->BREQUEST, NRF_USBD->WVALUEL, NRF_USBD->WVALUEH,
NRF_USBD->WINDEXL, NRF_USBD->WINDEXH, NRF_USBD->WLENGTHL, NRF_USBD->WLENGTHH
NRF_USBD->BMREQUESTTYPE , NRF_USBD->BREQUEST, NRF_USBD->WVALUEL , NRF_USBD->WVALUEH,
NRF_USBD->WINDEXL , NRF_USBD->WINDEXH , NRF_USBD->WLENGTHL, NRF_USBD->WLENGTHH
};

dcd_setup_received(0, setup);
Expand Down Expand Up @@ -486,6 +486,8 @@ void USBD_IRQHandler(void)
dcd_xfer_complete(0, epnum, xfer->actual_len, true);
}
}

// Ended event for Bulk/Int : nothing to do
}

if ( int_status & USBD_INTEN_EPDATA_Msk)
Expand Down

0 comments on commit 6b2b6aa

Please sign in to comment.