PaulStoffregen / USBHost_t36

USB Host Library for Teensy 3.6 and 4.0
165 stars 85 forks source link

ADK hangs sometimes on write - with fix proposition #79

Open hellmutbrudny opened 2 years ago

hellmutbrudny commented 2 years ago

I'm developing an app that is using Teensy 4.0 to connect with USB Host to Android powered tablet. With this library of course and ADK class. In my code I'm waiting with writing to the device until ADK.ready(). But it hangs the system sometimes (quite often). With some time I found out that:

  1. After the sequence requesting switching to accessory mode - in ADK::control case 7 - we change the state to 8...
  2. ... what makes ADK::ready() returning true.
  3. But we still need to wait for another enumeration starting with ISR: 408C Port Change - handled by USBHost::isr().
  4. So we have a race between IRQ and writing (happening because of ADK::ready).
  5. So I just have removed "state++" in ADK::control case 7 - and it works.

I'm just writing it to point a problem to be considered. Maybe my solution is OK or maybe I should wait with writing for something else.

PS. Thank you for a great job with the library nevertheless!