arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.22k stars 1.04k forks source link

Caterina USB bootloader executes SPM operations with interrupts enabled. #122

Open aweatherguy opened 6 years ago

aweatherguy commented 6 years ago

The sequence of writing to SPMCSR/SPMCR followed by the SPM instruction must occur within four MCU clock cycles or it will fail. Caterina appears to performing all SPM sequences with USB interrupts enabled. With the execption of block write sequences, Timer 1 interrupts are also enabled. If an interrupt occurs after writing SPMCSR/SPMCR and before the SPM instruction, the SPM operation will fail

These failures will be rare but they WILL happen. All of these sequences should be performed with global interrupts disabled.

Perhaps I missed something...but this certainly appears to be a problem.

NicoHood commented 6 years ago

I remember I had those rarely fails over time. Might be the reason.