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

SAMD21 USBDeviceClass::ISRHandler() called continuously. #65

Open
studiohsoftware opened this issue Dec 13, 2020 · 3 comments
Open

SAMD21 USBDeviceClass::ISRHandler() called continuously. #65

studiohsoftware opened this issue Dec 13, 2020 · 3 comments
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@studiohsoftware
Copy link

Running the MKR1000, I discovered with a debug statement in USBDeviceClass::ISRHandler() within USBCore.cpp, the handler is called continuously.

Executing this statement after enumeration seems to solve the problem.
USB->DEVICE.INTENCLR.reg = 0xFF;

@facchinm
Copy link
Contributor

Hi @studiohsoftware ,
thanks for spotting this. Would you mind creating a PR for https://github.com/arduino/ArduinoCore-samd targeting this issue? Thanks!

@studiohsoftware
Copy link
Author

studiohsoftware commented Dec 14, 2020

I don't have a solution though. You can show the problem with a print statement in the first line within USBDeviceClass::ISRHandler().

Successful enumeration depends on interrupts being enabled on DEVICE.INTFLAG. I am just not sure which ones are needed, why it is firing continuously (maybe we have an interrupt enabled on DEVICE.INTFLAG unnecessarily) or when, if we need to wait until after enumeration to disable interrupts, disabling can safely occur.

Apparently disabling everything within PluggableUSB().handleEndpoint(ep) works, but this seems like something to do in MIDIUSB.h. I am not sure the correct place to apply the fix.

So I don't have a PR ready, but I posted the same issue over there in case that helps.
arduino/ArduinoCore-samd#575

@studiohsoftware
Copy link
Author

studiohsoftware commented Dec 16, 2020

Okay final thoughts after having submitted the issue to the core team.

It seems the interrupt is happening due to the start-of-frame interrupt (SOF) and I think that the SAMD requires the user code to ACK the SOF whenever a pipe of type interrupt or iso is in use. So disabling that interrupt prevents the ACK programmed within USBDeviceClass::ISRHandler(), and enumeration on ep 0 leads to a stall condition.

Since MIDIUSB does not use interrupt or iso ep's, it means that this library unnecessarily visits USBDeviceClass::ISRHandler() every 1ms because of the SOF interrupt. It would be nice to have this interrupt disabled after enumeration, if possible. It seems that the interrupt can safely disabled once PluggableUSB.handleEndpoint is called by the core.

In other words, this request comes down to implementing handleEndpoint within MIDIUSB.h and disabling the interrupt there.

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants