Skip to content

Commit e89b863

Browse files
committed
update tinyusb, fix usbd clear stall, clear data toogle
1 parent eb5f8d5 commit e89b863

File tree

6 files changed

+40
-15
lines changed

6 files changed

+40
-15
lines changed

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc_device.c

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,31 @@ int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_t* buff
219219

220220
case SCSI_CMD_READ_CAPACITY_10:
221221
{
222-
scsi_read_capacity10_resp_t read_capa10;
223-
224222
uint32_t block_count;
225223
uint32_t block_size;
226224
uint16_t block_size_u16;
227225

228226
tud_msc_capacity_cb(lun, &block_count, &block_size_u16);
229227
block_size = (uint32_t) block_size_u16;
230228

231-
read_capa10.last_lba = ENDIAN_BE(block_count-1);
232-
read_capa10.block_size = ENDIAN_BE(block_size);
229+
// Invalid block size/count from callback, possibly unit is not ready
230+
// stall this request, set sense key to NOT READY
231+
if (block_count == 0 || block_size == 0)
232+
{
233+
resplen = -1;
234+
235+
// If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
236+
if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
237+
}else
238+
{
239+
scsi_read_capacity10_resp_t read_capa10;
240+
241+
read_capa10.last_lba = ENDIAN_BE(block_count-1);
242+
read_capa10.block_size = ENDIAN_BE(block_size);
233243

234-
resplen = sizeof(read_capa10);
235-
memcpy(buffer, &read_capa10, resplen);
244+
resplen = sizeof(read_capa10);
245+
memcpy(buffer, &read_capa10, resplen);
246+
}
236247
}
237248
break;
238249

@@ -250,11 +261,23 @@ int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_t* buff
250261
uint16_t block_size;
251262

252263
tud_msc_capacity_cb(lun, &block_count, &block_size);
253-
read_fmt_capa.block_num = ENDIAN_BE(block_count);
254-
read_fmt_capa.block_size_u16 = ENDIAN_BE16(block_size);
255264

256-
resplen = sizeof(read_fmt_capa);
257-
memcpy(buffer, &read_fmt_capa, resplen);
265+
// Invalid block size/count from callback, possibly unit is not ready
266+
// stall this request, set sense key to NOT READY
267+
if (block_count == 0 || block_size == 0)
268+
{
269+
resplen = -1;
270+
271+
// If sense key is not set by callback, default to Logical Unit Not Ready, Cause Not Reportable
272+
if ( _mscd_itf.sense_key == 0 ) tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x04, 0x00);
273+
}else
274+
{
275+
read_fmt_capa.block_num = ENDIAN_BE(block_count);
276+
read_fmt_capa.block_size_u16 = ENDIAN_BE16(block_size);
277+
278+
resplen = sizeof(read_fmt_capa);
279+
memcpy(buffer, &read_fmt_capa, resplen);
280+
}
258281
}
259282
break;
260283

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/dcd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void dcd_remote_wakeup(uint8_t rhport);
107107
* must be called to notify the stack
108108
* - busy : Check if endpoint transferring is complete (TODO remove)
109109
* - stall : stall endpoint
110-
* - clear_stall : clear stall
110+
* - clear_stall : clear stall, data toggle is also reset to DATA0
111111
*------------------------------------------------------------------*/
112112
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
113113
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/device/usbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
456456
case TUSB_REQ_CLEAR_FEATURE:
457457
if ( TUSB_REQ_FEATURE_EDPT_HALT == p_request->wValue )
458458
{
459-
dcd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex));
459+
usbd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex));
460460
}
461461
usbd_control_status(rhport, p_request);
462462
break;

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,12 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
322322

323323
if ( tu_edpt_number(ep_addr) )
324324
{
325+
// clear stall
325326
NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_UnStall << USBD_EPSTALL_STALL_Pos) | ep_addr;
327+
328+
// reset data toggle to DATA0
329+
NRF_USBD->DTOGGLE = (USBD_DTOGGLE_VALUE_Data0 << USBD_DTOGGLE_VALUE_Pos) | ep_addr;
330+
326331
__ISB(); __DSB();
327332
}
328333
}

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/tusb_option.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
*/
129129
#ifndef CFG_TUSB_DEBUG
130130
#define CFG_TUSB_DEBUG 0
131-
#warning CFG_TUSB_DEBUG is not defined, default value is 0
132131
#endif
133132

134133
// place data in accessible RAM for usb controller

cores/nRF5/Adafruit_TinyUSB_Core/tusb_config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#endif
4242

4343
#define CFG_TUSB_OS OPT_OS_FREERTOS
44-
#define CFG_TUSB_DEBUG 0
45-
4644
#define CFG_TUSB_MEM_SECTION
4745
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
4846

0 commit comments

Comments
 (0)