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

Stopping and de-init #428

Open
senilix opened this issue Jun 10, 2020 · 5 comments
Open

Stopping and de-init #428

senilix opened this issue Jun 10, 2020 · 5 comments

Comments

@senilix
Copy link

senilix commented Jun 10, 2020

Hi,

First, thanks for a great project. However, I have a question. I have a project where I would like to be able to stop and de-init the tinyusb stack and restart later on.

I could of course just hack it and stop calling the tud_task function and de-initialize the hardware. But, it would be nice if one was able to do it without resorting to this. I run the tinyusb stack in a thread and my initial idea was that it would be nice if one could inject a stop-event into the tud_task queue requesting it to stop and perhaps the tud_task function could return a value that indicated the stack was stopped?

Any thoughts?

Thanks

@hathach
Copy link
Owner

hathach commented Jun 10, 2020

This is thing I plan to do but haven't yet. Meanwhile you could try to call tud_disconnect() and/or adding your specific platform suspend task, turn off usb phy etc ... and do the opposite when calling tud_connect()

@senilix
Copy link
Author

senilix commented Jun 11, 2020

Thanks, I will take a look. Can see I use a older version of tinyusb and will upgrade. But, it would be great if there were some structured way of closing down.

@hathach hathach removed the Q&A label Dec 9, 2020
@hathach hathach moved this to 🆕 New in TinyUSB Mar 9, 2023
@hathach hathach added this to TinyUSB Mar 9, 2023
@MarekRyn
Copy link

MarekRyn commented Aug 5, 2024

After calling tud_disconnect() it is not possible to restart connection with tud_init(). The reason is that global flag _usbd_rhport remains in valid state and function tud_init() returns on lines:

// skip if already initialized
if ( tud_inited() ) return true

The solution is to modify 'tud_disconnect()', as below:

bool tud_disconnect(void)
{
  TU_VERIFY(dcd_disconnect);
  dcd_disconnect(_usbd_rhport);
  _usbd_rhport = RHPORT_INVALID;
  return true;
}

@JeffCalwood
Copy link

Isn't the counterpart to tud_disconnect() simply tud_connect()? Adding _usbd_rhport = RHPORT_INVALID; to tud_disconnect() would break this pair of functions.
If you want to tud_init() after tud_disconnect(), shouldn't you call tud_deinit()?

@roma-jam
Copy link
Contributor

Hi,
full tusb_teardown() implementation could be found in this PR: #2904

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 New
Development

No branches or pull requests

5 participants