Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve busprobe() #9

Open
tmk opened this issue Jul 24, 2021 · 2 comments
Open

Improve busprobe() #9

tmk opened this issue Jul 24, 2021 · 2 comments
Labels

Comments

@tmk
Copy link
Owner

tmk commented Jul 24, 2021

The library can miss plugin event and fails to enumerate recognize and initialize a device occasionally.

Seems like MAX3421e CONDETIRQ(Connect/Disconnect Interrupt) interrupt doesn't arise for all plugin events and we have to check bus state regularly.

I tried to catch INT pin change using ISR() with minimum code but it still failed to detect device insertion event occasionally. I believe that we cannot rely solely on the CONDETIRQ for plugin detection.

Meanwhile, I never seen the chip failed in detection of unpluging.

Branch for this topic:
https://github.com/tmk/USB_Host_Shield_2.0/tree/upstream_fix_busprobe

This fix seems like promising.

tmk added a commit that referenced this issue Jul 24, 2021
CONDETIRQ can't catch all changes on bus in time,
we have to check bus status regularly also.
#9
@tmk
Copy link
Owner Author

tmk commented Jul 24, 2021

And these issues are related probably. felis#425 felis#452

tmk added a commit that referenced this issue Jul 25, 2021
MAX3421E CONDETIRQ fails to detect device plugging sometimes,
we have to check bus lines regularly during bus state is SE0
to know device insertion.
#9
@tmk
Copy link
Owner Author

tmk commented Jul 25, 2021

The problem and the fix were confirmed with this sketch.

You will see it fails and stays in usb_state: WAIT_FOR_DEVICE(12) occasionally even when device is plugged.
This is happened likely when you plug-in and unplug a device quickly several times.

In case a device is recognized and goes to usb_state RUNNING(90).

usb_state: 12
usb_state: 20
usb_state: 40
usb_state: 50
usb_state: 51
usb_state: 90
.....

In case it fails

usb_state: 12
.....................

test sketch

test.ino:

#include <Usb.h>
#include <usbhub.h>



USB     Usb;

// Driver registry
//USBHub  hub1(&Usb);
//USBHub  hub2(&Usb);



void setup()
{
  Serial.begin( 115200 );
#if !defined(__MIPSEL__)
  while (!Serial);
#endif

  Serial.println("Start");

  Usb.Init();
}


static uint8_t prev_state = 0;
static uint32_t next_timer = 0;

void loop()
{
  Usb.Task();

  // USB state
  if (prev_state != Usb.getUsbTaskState()) {
    prev_state = Usb.getUsbTaskState();
    Serial.print(F("usb_state: ")); Serial.print(Usb.getUsbTaskState(), HEX); Serial.println();
  }

  if (next_timer < millis()) {
    Serial.print('.');
    next_timer = millis() + 1500;
  }
}
// vim: tabstop=2 softtabstop=2 shiftwidth=2 expandtab

tmk added a commit that referenced this issue Jul 25, 2021
MAX3421E CONDETIRQ fails to detect device plugging sometimes,
we have to check bus lines regularly during bus state is SE0
to know device insertion.
#9
@tmk tmk added the SOLVED label Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant