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

hw/usb/tinyusb: usb cdc console and tinyusb library sysinit before console uses it #3090

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

vrahane
Copy link
Contributor

@vrahane vrahane commented Oct 5, 2023

hw/usb/tinyusb: Fix sysinit levels so that tinyusb gets initialized
before console uses it

  • Changing cdc_console sysinit to 502 adding a new syscfg
    CONSOLE_USB_CDC_SYSINIT_STAGE for CDC USB console
    and use that instead
  • Also add restrictions so that usbd is never inited after
    cdc_console

@vrahane vrahane requested review from benmccrea, sjanc, wes3 and kasjer October 5, 2023 23:10
@vrahane vrahane force-pushed the vipul/tinyusb_sysinit_fixes_ branch from 8bb257d to 124cbdc Compare October 5, 2023 23:13
@vrahane vrahane changed the title hw/usb/tinyusb: usb cdc console and tinyusb library sysinit fixes before console uses it hw/usb/tinyusb: usb cdc console and tinyusb library sysinit before console uses it Oct 6, 2023
@@ -33,7 +33,7 @@ syscfg.defs:
USBD_SYSINIT_STAGE:
description: >
Sysinit stage for USB device functionality.
value: 500
value: 21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add syscfg for this sysinit and change priority in your local target if needed

Copy link
Contributor Author

@vrahane vrahane Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONSOLE_SYSINIT_STAGE Is set to 20 by default and that same level(syscfg) is used for CDC console. Tinyusb needs to be initialized before the CDC console if we(mynewt) want the CDC console to work fine by default, else it is going to have race conditions which is what I am seeing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that but are you sure that changing default value for tinyusb from 500 to 21 will not introduce any side effects in other configurations (<- @kasjer)? You can add conditional restriction instead so newt will print error if CDC console is enabled and USBD_SYSINIT_STAGE >= CONSOLE_USB_CDC_SYSINIT_STAGE and then change USBD_SYSINIT_STAGE in your local config accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what will happen if we move USB initialization to 21. So maybe it is safer to keep default priority as @andrzej-kaczmarek suggested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I have tested it and seems to be working fine. @benmccrea can second me on that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding CONSOLE_USB_CDC_SYSINIT_STAGE still makes sense as otherwise you won't be able to set proper priority order in scenario you mentioned (correct me if I'm wrong). I'm just reluctant to change default configuration for all other cases as well if we're not sure what could be the side-effects.

Copy link
Contributor Author

@vrahane vrahane Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, if you guys feel nervous about initializing it that early, cdc_console will have to be initialized later which will be in the 500s which will be too late. I am fine either ways. Adding a restriction seems fine but the default does need to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing to consider is all hardware stuff gets initialized quite early and only tinyusb which in turn initializes the USB controller for da1469x in our specific case gets initialized in the 500s.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having said that I understand the concerns, I will just add CONSOLE_USB_CDC_SYSINIT_STAGE and set it to 500+ sysinit level. I will change our targets locally to initialize both early on. We (mynewt) can probably make a well tested change later to do it early on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

hw/usb/tinyusb/cdc_console/syscfg.yml Outdated Show resolved Hide resolved
@vrahane vrahane force-pushed the vipul/tinyusb_sysinit_fixes_ branch 2 times, most recently from eca5acf to ed7c3da Compare October 6, 2023 23:31
@andrzej-kaczmarek
Copy link
Contributor

lgtm, but please fix the commit message. also the same restriction added in two different places is redundant.

before console uses it

- Changing cdc_console sysinit to 502 adding a new syscfg
  CONSOLE_USB_CDC_SYSINIT_STAGE for CDC USB console
  and use that instead
- Also add restrictions so that usbd is never inited after
  cdc_console
@vrahane vrahane force-pushed the vipul/tinyusb_sysinit_fixes_ branch from ed7c3da to 1050fae Compare October 9, 2023 19:23
@vrahane
Copy link
Contributor Author

vrahane commented Oct 9, 2023

@andrzej-kaczmarek Done

@vrahane vrahane merged commit f0152ae into apache:master Oct 9, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants