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

tuh_task() gets stuck when used for both device and host #2396

Open
1 task done
hrvach opened this issue Jan 5, 2024 · 0 comments
Open
1 task done

tuh_task() gets stuck when used for both device and host #2396

hrvach opened this issue Jan 5, 2024 · 0 comments
Labels

Comments

@hrvach
Copy link

hrvach commented Jan 5, 2024

Operating System

Linux

Board

RP2040 Pico

Firmware

Latest github branch (commit 86c416d (HEAD, tag: 0.15.0))

What happened ?

Hi!

First please allow me to thank you for making and maintaining this library, it's incredible!

The issue is a small one - I've noticed tusb_inited() does:

bool tusb_inited(void)
{
  bool ret = false;

#if CFG_TUD_ENABLED
  ret = ret || tud_inited();
#endif

#if CFG_TUH_ENABLED
  ret = ret || tuh_inited();
#endif

  return ret;
}

Which is essentially tuh_inited || tud_inited; it's tricky when both host and device are used simultaneously - tuh_task_ext() does:

void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
{
  (void) in_isr; // not implemented yet

  // Skip if stack is not initialized
  if ( !tusb_inited() ) return;

  // Loop until there is no more events in the queue
  while (1)
  {

In this case, tusb_inited() will be true due to tud_inited() being true, but tuh_inited() can still be false. This will do while(1) and block main loop that's e.g. resetting watchdog :)

Should tuh_task_ext do if(!tuh_inited()) return; instead?

How to reproduce ?

When using for both device and host, the tuh_task() blocks for too long initially. If I wrap tuh_task() in if(tuh_inited()) it works as expected.

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

Have no easy way to fetch logs from device atm, apologies.

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@hrvach hrvach added the Bug 🐞 label Jan 5, 2024
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