chipKIT32 / chipKIT32-MAX

Multi-platform IDE derived version from Arduino 0022 for the chipKit.
http://chipkit.net
Other
108 stars 76 forks source link

USB CDC-ACM (USB for Serial) Interrupt Starvation #478

Open JacobChrist opened 10 years ago

JacobChrist commented 10 years ago

I was using attachCoreTimerService to add an interrupt to my sketch.

The attached interrupt appears to be starving the USB interrupt. To see the effect add a delayMicroseconds(350); into your attached interrupt. This delay is so big that the USB will not get a chance to be serviced.

Next (at the suggestion of Mike S.) we tried a different interrupt (Timer3). The sample code Mike gave me was IPL3, we ran it fast and the USB did not crash.

Next we bumped the IPL on Timer3 up to 7 and reran. Sure enough USB broke with heavy communications.

I don't understand PIC32, USB or the chipKIT core enough to full grasp what is going on but here is my theory.

  1. USB has to be serviced within a certain amount of time or it breaks.
  2. The CoreTimerService has a higher or equal interrupt priority as USB.
  3. Attaching an interrupt to the CoreTimerService that has significant delay (100us) starves the USB interrupt.

Since attaching an interrupt to the core timer is an advertised feature (as it USB) and one can break the other I think this needs to be addressed.

My suggested solution would be to make the CoreTimerService slightly lower priority than USB.

EmbeddedMan commented 9 years ago

Jacob, I'd like to fix this. Could you post a MPIDE version that this fails with, along with a test sketch that shows it failing?

ricklon commented 9 years ago

Any news?

JacobChrist commented 9 years ago

My guess is that this is still an issue. If I can find some time I will put together a sample sketches.