Skip to content

Commit

Permalink
improved hex debug print, improved USBH debug prints, added pid/vid d…
Browse files Browse the repository at this point in the history
…ebug print
  • Loading branch information
heikokue committed Dec 26, 2023
1 parent 804f671 commit a39be99
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/common/tusb_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static inline void tu_print_buf(uint8_t const* buf, uint32_t bufsize) {
#define TU_LOG1_MEM tu_print_mem
#define TU_LOG1_BUF(_x, _n) tu_print_buf((uint8_t const*)(_x), _n)
#define TU_LOG1_INT(_x) tu_printf(#_x " = %ld\r\n", (unsigned long) (_x) )
#define TU_LOG1_HEX(_x) tu_printf(#_x " = %lX\r\n", (unsigned long) (_x) )
#define TU_LOG1_HEX(_x) tu_printf(#_x " = 0x%lX\r\n", (unsigned long) (_x) )

// Log Level 2: Warn
#if CFG_TUSB_DEBUG >= 2
Expand Down
29 changes: 16 additions & 13 deletions src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ bool tuh_vid_pid_get(uint8_t dev_addr, uint16_t *vid, uint16_t *pid) {
*vid = dev->vid;
*pid = dev->pid;

TU_LOG_HEX_USBH(*vid);
TU_LOG_HEX_USBH(*pid);

return true;
}

Expand Down Expand Up @@ -340,12 +343,12 @@ bool tuh_init(uint8_t controller_id) {
if ( tuh_inited() ) return true;

TU_LOG_USBH("USBH init on controller %u\r\n", controller_id);
TU_LOG_INT(CFG_TUH_LOG_LEVEL, sizeof(usbh_device_t));
TU_LOG_INT(CFG_TUH_LOG_LEVEL, sizeof(hcd_event_t));
TU_LOG_INT(CFG_TUH_LOG_LEVEL, sizeof(_ctrl_xfer));
TU_LOG_INT(CFG_TUH_LOG_LEVEL, sizeof(tuh_xfer_t));
TU_LOG_INT(CFG_TUH_LOG_LEVEL, sizeof(tu_fifo_t));
TU_LOG_INT(CFG_TUH_LOG_LEVEL, sizeof(tu_edpt_stream_t));
TU_LOG_INT_USBH(sizeof(usbh_device_t));
TU_LOG_INT_USBH(sizeof(hcd_event_t));
TU_LOG_INT_USBH(sizeof(_ctrl_xfer));
TU_LOG_INT_USBH(sizeof(tuh_xfer_t));
TU_LOG_INT_USBH(sizeof(tu_fifo_t));
TU_LOG_INT_USBH(sizeof(tu_edpt_stream_t));

// Event queue
_usbh_q = osal_queue_create( &_usbh_qdef );
Expand Down Expand Up @@ -589,7 +592,7 @@ bool tuh_control_xfer (tuh_xfer_t* xfer) {
TU_LOG_USBH("[%u:%u] %s: ", rhport, daddr,
(xfer->setup->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD && xfer->setup->bRequest <= TUSB_REQ_SYNCH_FRAME) ?
tu_str_std_request[xfer->setup->bRequest] : "Class Request");
TU_LOG_BUF(CFG_TUH_LOG_LEVEL, xfer->setup, 8);
TU_LOG_BUF_USBH(xfer->setup, 8);
TU_LOG_USBH("\r\n");

if (xfer->complete_cb) {
Expand Down Expand Up @@ -665,9 +668,9 @@ static bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result
tusb_control_request_t const * request = &_ctrl_xfer.request;

if (XFER_RESULT_SUCCESS != result) {
TU_LOG1("[%u:%u] Control %s, xferred_bytes = %lu\r\n", rhport, dev_addr, result == XFER_RESULT_STALLED ? "STALLED" : "FAILED", xferred_bytes);
TU_LOG1_BUF(request, 8);
TU_LOG1("\r\n");
TU_LOG_USBH("[%u:%u] Control %s, xferred_bytes = %lu\r\n", rhport, dev_addr, result == XFER_RESULT_STALLED ? "STALLED" : "FAILED", xferred_bytes);
TU_LOG_BUF_USBH(request, 8);
TU_LOG_USBH("\r\n");

// terminate transfer if any stage failed
_xfer_complete(dev_addr, result);
Expand All @@ -685,7 +688,7 @@ static bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result
case CONTROL_STAGE_DATA:
if (request->wLength) {
TU_LOG_USBH("[%u:%u] Control data:\r\n", rhport, dev_addr);
TU_LOG_MEM(CFG_TUH_LOG_LEVEL, _ctrl_xfer.buffer, xferred_bytes, 2);
TU_LOG_MEM_USBH(_ctrl_xfer.buffer, xferred_bytes, 2);
}

_ctrl_xfer.actual_len = (uint16_t) xferred_bytes;
Expand Down Expand Up @@ -860,7 +863,7 @@ bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * b
// HCD error, mark endpoint as ready to allow next transfer
ep_state->busy = 0;
ep_state->claimed = 0;
TU_LOG1("Failed\r\n");
TU_LOG_USBH("Failed\r\n");
// TU_BREAKPOINT();
return false;
}
Expand Down Expand Up @@ -1318,7 +1321,7 @@ static void process_enumeration(tuh_xfer_t* xfer) {
if ( retry ) {
failed_count++;
osal_task_delay(ATTEMPT_DELAY_MS); // delay a bit
TU_LOG1("Enumeration attempt %u\r\n", failed_count);
TU_LOG_USBH("Enumeration attempt %u\r\n", failed_count);
retry = tuh_control_xfer(xfer);
}

Expand Down
6 changes: 5 additions & 1 deletion src/host/usbh_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
extern "C" {
#endif

#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
#define TU_LOG_MEM_USBH(...) TU_LOG_MEM(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
#define TU_LOG_BUF_USBH(...) TU_LOG_BUF(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
#define TU_LOG_INT_USBH(...) TU_LOG_INT(CFG_TUH_LOG_LEVEL, __VA_ARGS__)
#define TU_LOG_HEX_USBH(...) TU_LOG_HEX(CFG_TUH_LOG_LEVEL, __VA_ARGS__)

enum {
USBH_EPSIZE_BULK_MAX = (TUH_OPT_HIGH_SPEED ? TUSB_EPSIZE_BULK_HS : TUSB_EPSIZE_BULK_FS)
Expand Down

0 comments on commit a39be99

Please sign in to comment.