0

Stupid question: How does the Arduino IDE Reset SAMD via USB
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Stupid question: How does the Arduino IDE Reset SAMD via USB

by tinker_curt on Tue Jun 01, 2021 2:47 pm

I have looked high and low for this. Okay well high at least.

I occasionally have some lockups in the firmware I'm working on, where the USB interface becomes unresponsive because (I suspect) my code is stuck in loop().

Thing is, as long as interrupts are running, presumably allowing the USB stack to process.. the Arduino IDE CAN reset it and re-flash a new image.

My question is, what secret-magic value is it sending to do that? I assume it's some kind of magic firecode-reset codeword that the stack itself knows to kick off a NVIC_SystemReset(); when it sees.. but I have been unable to ferret it out.

I know it has to be USB D+/D- only because this is a custom board and that's all I ran out to the plug :)

Any help please?

tinker_curt
 
Posts: 4
Joined: Wed Mar 31, 2021 11:06 am

Re: Stupid question: How does the Arduino IDE Reset SAMD via

by tinker_curt on Tue Jun 01, 2021 3:25 pm

solved..

Figures I finally give up and post and then find the answer I was looking for. The reset is triggered if the USB port is touched at 1200 baud with DTR enabled.

Now I just gotta figure out what to send the bootloader to go back to the app! :)

tinker_curt
 
Posts: 4
Joined: Wed Mar 31, 2021 11:06 am

Re: Stupid question: How does the Arduino IDE Reset SAMD via

by tinker_curt on Tue Jun 01, 2021 3:38 pm

eek.

That erases the app! I just want a reset into the bootloader...

Guess I can rewrite that part to do a 0xF01669EF-style NVIC_SystemReset instead of a full-blown nuke/pave.

Sorry to be "posting out loud" but I think someone might want to have some info on this later, and that someone may be me.

tinker_curt
 
Posts: 4
Joined: Wed Mar 31, 2021 11:06 am

Re: Stupid question: How does the Arduino IDE Reset SAMD via

by tinker_curt on Tue Jun 01, 2021 4:50 pm

got it!

Arduino15/packages/..../cores/arduino/usb/CDC.cpp : 120

Amended the "erase app and reset" to be "reset to bootloader [once]" on 1200 baud touch, just reset and return to app on a 2400 baud touch:

Code: Select all | TOGGLE FULL SIZE
   // auto-reset into the bootloader is triggered when the port, already
   // open at 1200 bps, is closed. We check DTR state to determine if host
   // port is open (bit 0 of lineState).
   if (_usbLineInfo.dwDTERate == 1200 && (_usbLineInfo.lineState & 0x01) == 0)
   {
      // let the bootloader do the erasing, just pop over
      *(uint32_t *)(0x20000000 + (32768 - 4)) = 0xF01669EF; // do NOT enter app
      NVIC_SystemReset();
            
//      initiateReset(250);
   }
   // allow 2400 baud to just be a soft reset
   else if ( _usbLineInfo.dwDTERate == 2400 && (_usbLineInfo.lineState & 0x01) == 0)
   {
      NVIC_SystemReset(); // just reset
   }
   else
   {
      cancelReset();
   }

tinker_curt
 
Posts: 4
Joined: Wed Mar 31, 2021 11:06 am

Please be positive and constructive with your questions and comments.