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

USB initialization fails sometimes #112

Open
davepruitt opened this issue Feb 13, 2023 · 0 comments
Open

USB initialization fails sometimes #112

davepruitt opened this issue Feb 13, 2023 · 0 comments

Comments

@davepruitt
Copy link

On occasion USB initialization will fail, and I am trying to figure out why this is happening. I am currently using a custom board with a SAMD51P19A. I've adjusted the linker files in the bootloader to take into account the difference in memory/program space for the SAMD51P19A compared to the SAMD51P20A.

It seems that USB initialization is failing under the following circumstances:

  1. Immediately after I flash the bootloader onto the chip. I am using the "Device Programming" screen in Microchip Studio in combination with an Atmel ICE to get the bootloader onto the chip. The USB won't be recognized unless I completely power cycle the chip by unplugging the USB cable and plugging it back in.
  2. If I have an Arduino sketch loaded onto the board, and then I try to upload a new sketch (this should enter bootloader mode using the 1200 bps method, and it does indeed enter the bootloader, but the USB initialization of the bootloader is failing under this circumstance, and thus it fails to upload a new Arduino sketch).

Circumstances in which USB initialization is succeeding in the bootloader:

  1. If I unplug the USB cable and plug it back in (assuming no Arduino sketch is loaded onto the board, because then it would jump to the sketch of course)

The function usb_init seems to be running fine as far as I can tell. When I get to the loop which polls USB_Ok, this is where I am running into issues.

while (1) {
        if (USB_Ok()) {
            /* code */

So I've been looking at what's happening in the USB_Ok function. This function essentially has 3 code paths:

  1. Path A if this if-statement on line 553 is true: if (USB->DEVICE.INTFLAG.reg & USB_DEVICE_INTFLAG_EORST)
  2. Path B if this if-statement on line 579 is true: else if (USB->DEVICE.DeviceEndpoint[0].EPINTFLAG.reg & USB_DEVICE_EPINTFLAG_RXSTP)
  3. Path C: do nothing if neither of the above if-statements are true

Upon debugging, it seems like when the bootloader is successful this function first goes through code path "A", and then later it will go through code path "B". When the bootloader is unsuccessful, it never enters either of these code paths. So basically it seems like th EORST bit of the INTFLAG register is never getting set sometimes.

Any ideas on why this could be?

My computer that I have the board connected to is a Windows 10 machine.

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

No branches or pull requests

1 participant