From 050fa2fd394912775994d4171774adb475eaf531 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 21 Dec 2019 19:33:41 +0700 Subject: able to response to scsi inquiry, but failed to response to test unit ready --- src/class/msc/msc_device.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/class') diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index bf2b5bb8c..190252265 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -378,6 +378,9 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t TU_ASSERT( event == XFER_RESULT_SUCCESS && xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE ); + TU_LOG2(" Command Block Wrapper\n"); + TU_LOG2_MEM(p_cbw, xferred_bytes, 2); + p_csw->signature = MSC_CSW_SIGNATURE; p_csw->tag = p_cbw->tag; p_csw->data_residue = 0; @@ -448,6 +451,9 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t break; case MSC_STAGE_DATA: + //TU_LOG2(" SCSI Data\n"); + //TU_LOG2_MEM(_mscd_buf, xferred_bytes, 2); + // OUT transfer, invoke callback if needed if ( !tu_bit_test(p_cbw->dir, 7) ) { @@ -538,6 +544,9 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t // Wait for the command status wrapper complete event if( (ep_addr == p_msc->ep_in) && (xferred_bytes == sizeof(msc_csw_t)) ) { + TU_LOG2(" Command Status Wrapper\n"); + TU_LOG2_MEM(p_csw, xferred_bytes, 2); + // Move to default CMD stage p_msc->stage = MSC_STAGE_CMD; -- cgit v1.3.1 From 421221baa5b8509b705f76def43fd684c5fe06df Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 21 Dec 2019 23:51:57 +0700 Subject: making more progress, but failed with WRITE10 incorrect queue 448 bytes instead of 512 --- src/class/msc/msc_device.c | 6 +++--- src/portable/microchip/samg/dcd_samg.c | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src/class') diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 190252265..84fe5a194 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -379,7 +379,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE ); TU_LOG2(" Command Block Wrapper\n"); - TU_LOG2_MEM(p_cbw, xferred_bytes, 2); + // TU_LOG2_MEM(p_cbw, xferred_bytes, 2); p_csw->signature = MSC_CSW_SIGNATURE; p_csw->tag = p_cbw->tag; @@ -451,7 +451,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t break; case MSC_STAGE_DATA: - //TU_LOG2(" SCSI Data\n"); + TU_LOG2(" SCSI Data\n"); //TU_LOG2_MEM(_mscd_buf, xferred_bytes, 2); // OUT transfer, invoke callback if needed @@ -545,7 +545,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t if( (ep_addr == p_msc->ep_in) && (xferred_bytes == sizeof(msc_csw_t)) ) { TU_LOG2(" Command Status Wrapper\n"); - TU_LOG2_MEM(p_csw, xferred_bytes, 2); + // TU_LOG2_MEM(p_csw, xferred_bytes, 2); // Move to default CMD stage p_msc->stage = MSC_STAGE_CMD; diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c index 96cd775c4..fd50237dc 100644 --- a/src/portable/microchip/samg/dcd_samg.c +++ b/src/portable/microchip/samg/dcd_samg.c @@ -63,6 +63,13 @@ void xfer_begin(xfer_desc_t* xfer, uint8_t * buffer, uint16_t total_bytes) xfer->actual_len = 0; } +void xfer_end(xfer_desc_t* xfer) +{ + xfer->buffer = NULL; + xfer->total_len = 0; + xfer->actual_len = 0; +} + uint16_t xfer_packet_len(xfer_desc_t* xfer) { // also cover zero-length packet @@ -258,10 +265,12 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t // OUT Data may already received and acked by hardware // Read it as 1st packet then continue with transfer if needed -// uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos); -// -// if ( xact_len ) -// { + if ( UDP->UDP_CSR[epnum] & (UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk) ) + { + uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos); + + TU_LOG2("xact_len = %d\r", xact_len); + // // Read from EP fifo // xact_ep_read(epnum, xfer->buffer, xact_len); // xfer_packet_done(xfer); @@ -277,10 +286,10 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t // dcd_event_xfer_complete(rhport, epnum, xact_len, XFER_RESULT_SUCCESS, false); // return true; // complete // } -// } + } // Enable interrupt when starting OUT transfer - UDP->UDP_IER |= (1 << epnum); + if (epnum != 0) UDP->UDP_IER |= (1 << epnum); } return true; @@ -397,10 +406,13 @@ void dcd_isr(uint8_t rhport) } // Endpoint OUT - if (UDP->UDP_CSR[epnum] & UDP_CSR_RX_DATA_BK0_Msk) + // When both Bank0 and Bank1 are both set, there is not way to know which one comes first + if (UDP->UDP_CSR[epnum] & (UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk)) { uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos); + //if (epnum != 0) TU_LOG2("xact_len = %d\r", xact_len); + // Read from EP fifo xact_ep_read(epnum, xfer->buffer, xact_len); xfer_packet_done(xfer); @@ -408,13 +420,14 @@ void dcd_isr(uint8_t rhport) if ( 0 == xfer_packet_len(xfer) ) { // Disable OUT EP interrupt when transfer is complete - UDP->UDP_IER &= ~(1 << epnum); + if (epnum != 0) UDP->UDP_IDR |= (1 << epnum); dcd_event_xfer_complete(rhport, epnum, xact_len, XFER_RESULT_SUCCESS, true); +// xfer_end(xfer); } // Clear DATA Bank0 bit - UDP->UDP_CSR[epnum] &= ~UDP_CSR_RX_DATA_BK0_Msk; + UDP->UDP_CSR[epnum] &= ~(UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk); } // Stall sent to host -- cgit v1.3.1 From bbada1d3e6dba5b339c7cd4129e5df7b3203c11b Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 23 Dec 2019 18:54:06 +0700 Subject: adding lookup table for debugging add msc scsi command list --- src/class/msc/msc_device.c | 32 ++++++++++++++++++++++++++++++-- src/common/tusb_common.h | 23 +++++++++++++++++++++++ src/device/usbd.c | 2 +- src/portable/microchip/samg/dcd_samg.c | 5 +++-- 4 files changed, 57 insertions(+), 5 deletions(-) (limited to 'src/class') diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 84fe5a194..93167bc6d 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -97,6 +97,34 @@ static inline uint16_t rdwr10_get_blockcount(uint8_t const command[]) return tu_ntohs(block_count); } +//--------------------------------------------------------------------+ +// Debug +//--------------------------------------------------------------------+ +#if CFG_TUSB_DEBUG >= 2 + +static lookup_entry_t const _msc_scsi_cmd_lookup[] = +{ + { .key = SCSI_CMD_TEST_UNIT_READY , .data = "Test Unit Ready" }, + { .key = SCSI_CMD_INQUIRY , .data = "Inquiry" }, + { .key = SCSI_CMD_MODE_SELECT_6 , .data = "Mode_Select 6" }, + { .key = SCSI_CMD_MODE_SENSE_6 , .data = "Mode_Sense 6" }, + { .key = SCSI_CMD_START_STOP_UNIT , .data = "Start Stop Unit" }, + { .key = SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL , .data = "Prevent Allow Medium Removal" }, + { .key = SCSI_CMD_READ_CAPACITY_10 , .data = "Read Capacity10" }, + { .key = SCSI_CMD_REQUEST_SENSE , .data = "Request Sense" }, + { .key = SCSI_CMD_READ_FORMAT_CAPACITY , .data = "Read Format Capacity" }, + { .key = SCSI_CMD_READ_10 , .data = "Read10" }, + { .key = SCSI_CMD_WRITE_10 , .data = "Write10" } +}; + +static lookup_table_t const _msc_scsi_cmd_table = +{ + .count = TU_ARRAY_SIZE(_msc_scsi_cmd_lookup), + .items = _msc_scsi_cmd_lookup +}; + +#endif + //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ @@ -378,7 +406,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t TU_ASSERT( event == XFER_RESULT_SUCCESS && xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE ); - TU_LOG2(" Command Block Wrapper\n"); + TU_LOG2(" SCSI Command: %s\n", lookup_find(&_msc_scsi_cmd_table, p_cbw->command[0])); // TU_LOG2_MEM(p_cbw, xferred_bytes, 2); p_csw->signature = MSC_CSW_SIGNATURE; @@ -544,7 +572,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t // Wait for the command status wrapper complete event if( (ep_addr == p_msc->ep_in) && (xferred_bytes == sizeof(msc_csw_t)) ) { - TU_LOG2(" Command Status Wrapper\n"); + TU_LOG2(" SCSI Status: %u\n", p_csw->status); // TU_LOG2_MEM(p_csw, xferred_bytes, 2); // Move to default CMD stage diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index f76abca88..5700c1282 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -231,6 +231,29 @@ void tu_print_mem(void const *buf, uint16_t count, uint8_t indent); #define TU_LOG2_LOCATION() TU_LOG1_LOCATION() #endif + +typedef struct +{ + uint32_t key; + char const * data; +}lookup_entry_t; + +typedef struct +{ + uint16_t count; + lookup_entry_t const* items; +} lookup_table_t; + +static inline char const* lookup_find(lookup_table_t const* p_table, uint32_t key) +{ + for(uint16_t i=0; icount; i++) + { + if (p_table->items[i].key == key) return p_table->items[i].data; + } + + return NULL; +} + #endif // CFG_TUSB_DEBUG #ifndef TU_LOG1 diff --git a/src/device/usbd.c b/src/device/usbd.c index 5832f2353..949e14096 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -211,7 +211,7 @@ bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, //--------------------------------------------------------------------+ // Debugging //--------------------------------------------------------------------+ -#if CFG_TUSB_DEBUG > 1 +#if CFG_TUSB_DEBUG >= 2 static char const* const _usbd_event_str[DCD_EVENT_COUNT] = { "INVALID" , diff --git a/src/portable/microchip/samg/dcd_samg.c b/src/portable/microchip/samg/dcd_samg.c index fd50237dc..a93b26caa 100644 --- a/src/portable/microchip/samg/dcd_samg.c +++ b/src/portable/microchip/samg/dcd_samg.c @@ -267,9 +267,9 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t // Read it as 1st packet then continue with transfer if needed if ( UDP->UDP_CSR[epnum] & (UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk) ) { - uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos); +// uint16_t const xact_len = (uint16_t) ((UDP->UDP_CSR[epnum] & UDP_CSR_RXBYTECNT_Msk) >> UDP_CSR_RXBYTECNT_Pos); - TU_LOG2("xact_len = %d\r", xact_len); +// TU_LOG2("xact_len = %d\r", xact_len); // // Read from EP fifo // xact_ep_read(epnum, xfer->buffer, xact_len); @@ -406,6 +406,7 @@ void dcd_isr(uint8_t rhport) } // Endpoint OUT + // Ping-Pong is a must for Bulk/Iso // When both Bank0 and Bank1 are both set, there is not way to know which one comes first if (UDP->UDP_CSR[epnum] & (UDP_CSR_RX_DATA_BK0_Msk | UDP_CSR_RX_DATA_BK1_Msk)) { -- cgit v1.3.1