tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

USBTMC: EP not busy should not bail from tud_usbtmc_transmit_notification_data

Open hinxx opened this issue 1 year ago • 0 comments

Operating System

Linux

Board

RPI Pico

Firmware

tinyusb/src/class/usbtmc/usbtmc_device.c tinyusb/examples/device/usbtmc/src/usbtmc_app.c

What happened ?

PR #2494 introduced tud_usbtmc_transmit_notification_data() function. The check if EP is not busy bails out of the function if the EP is NOT busy:

https://github.com/hathach/tinyusb/blob/cfbdc44a8d099240ad5ef208bd639487c2f28153/src/class/usbtmc/usbtmc_device.c#L256

I believe it should be the opposite; bail if the EP IS busy and continue if not busy like so:

TU_VERIFY(usbd_edpt_busy(usbtmc_state.rhport, usbtmc_state.ep_int_in) == false);

How to reproduce ?

Original code:

  1. Add the following to usbtmc_app.c:
bool tud_usbtmc_notification_complete_cb(void) {
  usbtmc_srq_interrupt_488_t intMsg =
  {
    .bNotify1 = USB488_bNOTIFY1_SRQ,
    .StatusByte = 0xa5
  };
  bool ret = tud_usbtmc_transmit_notification_data((void*)&intMsg, sizeof(intMsg));
  (void)ret;

  return true;
}
  1. Use the following python script to poll for interrupt condition: poll-interrupt-in.txt

  2. Observe No data available (timeout) being printed out by python script.

  3. Change the https://github.com/hathach/tinyusb/blob/cfbdc44a8d099240ad5ef208bd639487c2f28153/src/class/usbtmc/usbtmc_device.c#L256 to

TU_VERIFY(usbd_edpt_busy(usbtmc_state.rhport, usbtmc_state.ep_int_in) == false);
  1. Using the same script will now continuously print :
Data received: array('B', [129, 165])

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

I could not see any useful in the debug logs, I had to use the pico probe debugger to see that the interrupt EP is in fact not busy and the the code is wrong.

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked existing issues, dicussion and documentation.

hinxx avatar Jul 23 '24 14:07 hinxx