From a3c26e677d076181e28231740e3f0376088eabb6 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Tue, 29 Nov 2022 17:35:13 -0600 Subject: [PATCH] WIP more logging tweaks --- cores/arduino/USBCore.cpp | 49 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index 96be5519..0c567916 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -511,12 +511,25 @@ static void handleErr(uint8_t len) if (len == 0xff) { USBCore().logStatus("Error"); } else { - Serial1.println((uint16_t)USBD_EPxCS(0), 16); - uint8_t buf[64] = {0}; + // Serial1.println((uint16_t)USBD_EPxCS(0), 16); USBCore().logEP('!', 0, '<', len); - len = USBCore().usbDev().drv_handler->ep_read(buf, 0, (uint8_t)EP_BUF_SNG); - USBCore().hexDump('!', buf, 64); - USBCore().logEP('.', 0, '!', len); + usbd_ep_ram *btable_ep = (usbd_ep_ram *)(USBD_RAM + 2 * (BTABLE_OFFSET & 0xFFF8)); + uint32_t *p = (uint32_t *)(USBD_RAM + 2U * EP0_RX_ADDR); + Serial1.print('!'); + for (int i = 0; i < USBD_EP0_MAX_SIZE/2; i++) { + uint16_t x = p[i]; + Serial1.print((x >> 4) & 0x0f, 16); + Serial1.print(x & 0x0f, 16); + // Serial1.print(' '); + Serial1.print((x >> 12) & 0x0f, 16); + Serial1.print((x >> 8) & 0x0f, 16); + // Serial1.print(' '); + } + Serial1.println(); + // len = USBCore().usbDev().drv_handler->ep_read(buf, 0, (uint8_t)EP_BUF_SNG); + // USBCore().hexDump('!', buf, 64); + auto bytes = (uint16_t)(btable_ep[0].rx_count & EPRCNT_CNT); + USBCore().logEP('.', 0, '!', bytes); } } @@ -569,11 +582,14 @@ USBCore_::USBCore_() void USBCore_::logEP(char kind, uint8_t ep, char dir, size_t len) { + Serial1.print(USBD_EPxCS(ep), 16); Serial1.print(kind); Serial1.print(ep); Serial1.print(dir); - Serial1.println(len); - // Serial1.flush(); + Serial1.print(len); + Serial1.print(' '); + Serial1.println(USBD_EPxCS(ep), 16); + Serial1.flush(); } void USBCore_::hexDump(char prefix, const uint8_t *buf, size_t len) @@ -585,13 +601,13 @@ void USBCore_::hexDump(char prefix, const uint8_t *buf, size_t len) Serial1.print(' '); } Serial1.println(); - // Serial1.flush(); + Serial1.flush(); } void USBCore_::logStatus(const char *status) { Serial1.println(status); - // Serial1.flush(); + Serial1.flush(); } void USBCore_::connect() @@ -666,6 +682,7 @@ int USBCore_::recvControl(void* data, int len) this->ctlOutBuf = (uint8_t *)data; this->ctlOutLen = len; usb_transc_config(&USBCore().usbDev().transc_out[0], this->ctlBuf, len, 0); + // Serial1.println((uint16_t)USBD_EPxCS(0), 16); USBCore().logEP('_', 0, '<', len); return len; } @@ -723,7 +740,7 @@ int USBCore_::send(uint8_t ep, const void* data, int len) auto usbd = &USBCore().usbDev(); usb_disable_interrupts(); - USBCore().logEP('+', ep, '>', len); + // USBCore().logEP('+', ep, '>', len); usb_enable_interrupts(); #ifdef USBD_REMOTE_WAKEUP usb_disable_interrupts(); @@ -791,7 +808,7 @@ int USBCore_::flush(uint8_t ep) usbd->transc_in[0].xfer_buf = ctlBuf; usbd->transc_in[0].xfer_len = ctlIdx; USBCore().logEP('_', 0, '>', ctlIdx); - USBCore().hexDump('>', ctlBuf, ctlIdx); + // USBCore().hexDump('>', ctlBuf, ctlIdx); } else { EPBuffers().buf(ep).flush(); } @@ -838,6 +855,7 @@ void USBCore_::transcOut(usb_dev* usbd, uint8_t ep) { auto transc = &usbd->transc_out[ep]; auto count = transc->xfer_count; + USBCore().logEP(':', ep, '<', count); if (ep == 0) { this->oldTranscOut(usbd, ep); } else { @@ -850,13 +868,16 @@ void USBCore_::transcOut(usb_dev* usbd, uint8_t ep) void USBCore_::transcIn(usb_dev* usbd, uint8_t ep) { auto transc = &usbd->transc_in[ep]; - USBCore().logEP('.', ep, '>', transc->xfer_count); - - if (ep == 0) { + auto count = transc->xfer_count; + USBCore().logEP(':', ep, '>', transc->xfer_count); + if (ep == 0) { this->oldTranscIn(usbd, ep); } else { EPBuffers().buf(ep).transcIn(); } + if (usbd->control.ctl_state != USBD_CTL_STATUS_OUT) { + USBCore().logEP('.', ep, '>', transc->xfer_count); + } transc->xfer_count = 0; }