34
34
35
35
#include "msc_device.h"
36
36
37
+ // Level where CFG_TUSB_DEBUG must be at least for this driver is logged
38
+ #ifndef CFG_TUD_MSC_LOG_LEVEL
39
+ #define CFG_TUD_MSC_LOG_LEVEL 2
40
+ #endif
41
+
42
+ #define TU_LOG_DRV (...) TU_LOG(CFG_TUD_MSC_LOG_LEVEL, __VA_ARGS__)
43
+
37
44
//--------------------------------------------------------------------+
38
45
// MACRO CONSTANT TYPEDEF
39
46
//--------------------------------------------------------------------+
40
-
41
- // Can be selectively disabled to reduce logging when troubleshooting other driver
42
- #define MSC_DEBUG 2
43
-
44
47
enum
45
48
{
46
49
MSC_STAGE_CMD = 0 ,
@@ -164,7 +167,7 @@ uint8_t rdwr10_validate_cmd(msc_cbw_t const* cbw)
164
167
{
165
168
if ( block_count )
166
169
{
167
- TU_LOG ( MSC_DEBUG , " SCSI case 2 (Hn < Di) or case 3 (Hn < Do) \r\n" );
170
+ TU_LOG_DRV ( " SCSI case 2 (Hn < Di) or case 3 (Hn < Do) \r\n" );
168
171
status = MSC_CSW_STATUS_PHASE_ERROR ;
169
172
}else
170
173
{
@@ -174,22 +177,22 @@ uint8_t rdwr10_validate_cmd(msc_cbw_t const* cbw)
174
177
{
175
178
if ( SCSI_CMD_READ_10 == cbw -> command [0 ] && !is_data_in (cbw -> dir ) )
176
179
{
177
- TU_LOG ( MSC_DEBUG , " SCSI case 10 (Ho <> Di)\r\n" );
180
+ TU_LOG_DRV ( " SCSI case 10 (Ho <> Di)\r\n" );
178
181
status = MSC_CSW_STATUS_PHASE_ERROR ;
179
182
}
180
183
else if ( SCSI_CMD_WRITE_10 == cbw -> command [0 ] && is_data_in (cbw -> dir ) )
181
184
{
182
- TU_LOG ( MSC_DEBUG , " SCSI case 8 (Hi <> Do)\r\n" );
185
+ TU_LOG_DRV ( " SCSI case 8 (Hi <> Do)\r\n" );
183
186
status = MSC_CSW_STATUS_PHASE_ERROR ;
184
187
}
185
188
else if ( 0 == block_count )
186
189
{
187
- TU_LOG ( MSC_DEBUG , " SCSI case 4 Hi > Dn (READ10) or case 9 Ho > Dn (WRITE10) \r\n" );
190
+ TU_LOG_DRV ( " SCSI case 4 Hi > Dn (READ10) or case 9 Ho > Dn (WRITE10) \r\n" );
188
191
status = MSC_CSW_STATUS_FAILED ;
189
192
}
190
193
else if ( cbw -> total_bytes / block_count == 0 )
191
194
{
192
- TU_LOG ( MSC_DEBUG , " Computed block size = 0. SCSI case 7 Hi < Di (READ10) or case 13 Ho < Do (WRIT10)\r\n" );
195
+ TU_LOG_DRV ( " Computed block size = 0. SCSI case 7 Hi < Di (READ10) or case 13 Ho < Do (WRIT10)\r\n" );
193
196
status = MSC_CSW_STATUS_PHASE_ERROR ;
194
197
}
195
198
}
@@ -352,7 +355,7 @@ bool mscd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
352
355
switch ( request -> bRequest )
353
356
{
354
357
case MSC_REQ_RESET :
355
- TU_LOG ( MSC_DEBUG , " MSC BOT Reset\r\n" );
358
+ TU_LOG_DRV ( " MSC BOT Reset\r\n" );
356
359
TU_VERIFY (request -> wValue == 0 && request -> wLength == 0 );
357
360
358
361
// driver state reset
@@ -363,7 +366,7 @@ bool mscd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
363
366
364
367
case MSC_REQ_GET_MAX_LUN :
365
368
{
366
- TU_LOG ( MSC_DEBUG , " MSC Get Max Lun\r\n" );
369
+ TU_LOG_DRV ( " MSC Get Max Lun\r\n" );
367
370
TU_VERIFY (request -> wValue == 0 && request -> wLength == 1 );
368
371
369
372
uint8_t maxlun = 1 ;
@@ -400,7 +403,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
400
403
401
404
if ( !(xferred_bytes == sizeof (msc_cbw_t ) && p_cbw -> signature == MSC_CBW_SIGNATURE ) )
402
405
{
403
- TU_LOG ( MSC_DEBUG , " SCSI CBW is not valid\r\n" );
406
+ TU_LOG_DRV ( " SCSI CBW is not valid\r\n" );
404
407
405
408
// BOT 6.6.1 If CBW is not valid stall both endpoints until reset recovery
406
409
p_msc -> stage = MSC_STAGE_NEED_RESET ;
@@ -412,7 +415,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
412
415
return false;
413
416
}
414
417
415
- TU_LOG ( MSC_DEBUG , " SCSI Command [Lun%u]: %s\r\n" , p_cbw -> lun , tu_lookup_find (& _msc_scsi_cmd_table , p_cbw -> command [0 ]));
418
+ TU_LOG_DRV ( " SCSI Command [Lun%u]: %s\r\n" , p_cbw -> lun , tu_lookup_find (& _msc_scsi_cmd_table , p_cbw -> command [0 ]));
416
419
//TU_LOG_MEM(MSC_DEBUG, p_cbw, xferred_bytes, 2);
417
420
418
421
p_csw -> signature = MSC_CSW_SIGNATURE ;
@@ -457,7 +460,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
457
460
{
458
461
if (p_cbw -> total_bytes > sizeof (_mscd_buf ))
459
462
{
460
- TU_LOG ( MSC_DEBUG , " SCSI reject non READ10/WRITE10 with large data\r\n" );
463
+ TU_LOG_DRV ( " SCSI reject non READ10/WRITE10 with large data\r\n" );
461
464
fail_scsi_op (rhport , p_msc , MSC_CSW_STATUS_FAILED );
462
465
}else
463
466
{
@@ -479,7 +482,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
479
482
if ( resplen < 0 )
480
483
{
481
484
// unsupported command
482
- TU_LOG ( MSC_DEBUG , " SCSI unsupported or failed command\r\n" );
485
+ TU_LOG_DRV ( " SCSI unsupported or failed command\r\n" );
483
486
fail_scsi_op (rhport , p_msc , MSC_CSW_STATUS_FAILED );
484
487
}
485
488
else if (resplen == 0 )
@@ -514,7 +517,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
514
517
break ;
515
518
516
519
case MSC_STAGE_DATA :
517
- TU_LOG ( MSC_DEBUG , " SCSI Data [Lun%u]\r\n" , p_cbw -> lun );
520
+ TU_LOG_DRV ( " SCSI Data [Lun%u]\r\n" , p_cbw -> lun );
518
521
//TU_LOG_MEM(MSC_DEBUG, _mscd_buf, xferred_bytes, 2);
519
522
520
523
if (SCSI_CMD_READ_10 == p_cbw -> command [0 ])
@@ -546,7 +549,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
546
549
if ( cb_result < 0 )
547
550
{
548
551
// unsupported command
549
- TU_LOG ( MSC_DEBUG , " SCSI unsupported command\r\n" );
552
+ TU_LOG_DRV ( " SCSI unsupported command\r\n" );
550
553
fail_scsi_op (rhport , p_msc , MSC_CSW_STATUS_FAILED );
551
554
}else
552
555
{
@@ -575,7 +578,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
575
578
// Wait for the Status phase to complete
576
579
if ( (ep_addr == p_msc -> ep_in ) && (xferred_bytes == sizeof (msc_csw_t )) )
577
580
{
578
- TU_LOG ( MSC_DEBUG , " SCSI Status [Lun%u] = %u\r\n" , p_cbw -> lun , p_csw -> status );
581
+ TU_LOG_DRV ( " SCSI Status [Lun%u] = %u\r\n" , p_cbw -> lun , p_csw -> status );
579
582
// TU_LOG_MEM(MSC_DEBUG, p_csw, xferred_bytes, 2);
580
583
581
584
// Invoke complete callback if defined
@@ -845,7 +848,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
845
848
if ( nbytes < 0 )
846
849
{
847
850
// negative means error -> endpoint is stalled & status in CSW set to failed
848
- TU_LOG ( MSC_DEBUG , " tud_msc_read10_cb() return -1\r\n" );
851
+ TU_LOG_DRV ( " tud_msc_read10_cb() return -1\r\n" );
849
852
850
853
// set sense
851
854
set_sense_medium_not_present (p_cbw -> lun );
@@ -907,7 +910,7 @@ static void proc_write10_new_data(uint8_t rhport, mscd_interface_t* p_msc, uint3
907
910
if ( nbytes < 0 )
908
911
{
909
912
// negative means error -> failed this scsi op
910
- TU_LOG ( MSC_DEBUG , " tud_msc_write10_cb() return -1\r\n" );
913
+ TU_LOG_DRV ( " tud_msc_write10_cb() return -1\r\n" );
911
914
912
915
// update actual byte before failed
913
916
p_msc -> xferred_len += xferred_bytes ;
0 commit comments