@@ -80,35 +80,39 @@ bool WEAK CDC_Setup(Setup& setup)
8080 if (CDC_SET_LINE_CODING == r)
8181 {
8282 USB_RecvControl ((void *)&_usbLineInfo,7 );
83- return true ;
8483 }
8584
8685 if (CDC_SET_CONTROL_LINE_STATE == r)
8786 {
8887 _usbLineInfo.lineState = setup.wValueL ;
88+ }
8989
90+ if (CDC_SET_LINE_CODING == r || CDC_SET_CONTROL_LINE_STATE == r)
91+ {
9092 // auto-reset into the bootloader is triggered when the port, already
9193 // open at 1200 bps, is closed. this is the signal to start the watchdog
9294 // with a relatively long period so it can finish housekeeping tasks
9395 // like servicing endpoints before the sketch ends
94- if (1200 == _usbLineInfo.dwDTERate ) {
95- // We check DTR state to determine if host port is open (bit 0 of lineState).
96- if ((_usbLineInfo.lineState & 0x01 ) == 0 ) {
97- *(uint16_t *)0x0800 = 0x7777 ;
98- wdt_enable (WDTO_120MS);
99- } else {
100- // Most OSs do some intermediate steps when configuring ports and DTR can
101- // twiggle more than once before stabilizing.
102- // To avoid spurious resets we set the watchdog to 250ms and eventually
103- // cancel if DTR goes back high.
104-
105- wdt_disable ();
106- wdt_reset ();
107- *(uint16_t *)0x0800 = 0x0 ;
108- }
96+
97+ // We check DTR state to determine if host port is open (bit 0 of lineState).
98+ if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01 ) == 0 )
99+ {
100+ *(uint16_t *)0x0800 = 0x7777 ;
101+ wdt_enable (WDTO_120MS);
102+ }
103+ else
104+ {
105+ // Most OSs do some intermediate steps when configuring ports and DTR can
106+ // twiggle more than once before stabilizing.
107+ // To avoid spurious resets we set the watchdog to 250ms and eventually
108+ // cancel if DTR goes back high.
109+
110+ wdt_disable ();
111+ wdt_reset ();
112+ *(uint16_t *)0x0800 = 0x0 ;
109113 }
110- return true ;
111114 }
115+ return true ;
112116 }
113117 return false ;
114118}
0 commit comments