Skip to content

Commit

Permalink
WIP more logging tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tlyu committed Nov 30, 2022
1 parent 77e1190 commit 0d49037
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions cores/arduino/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}

Expand Down

0 comments on commit 0d49037

Please sign in to comment.