File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
hardware/arduino/avr/cores/arduino Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -92,11 +92,25 @@ bool CDC_Setup(USBSetup& setup)
92
92
// with a relatively long period so it can finish housekeeping tasks
93
93
// like servicing endpoints before the sketch ends
94
94
95
+ #ifndef MAGIC_KEY
96
+ #define MAGIC_KEY 0x7777
97
+ #endif
98
+ #ifndef MAGIC_KEY_POS
99
+ #define MAGIC_KEY_POS (uint16_t *)0x0800
100
+ #endif
101
+ // NO_MAGIC_KEY_BACKUP can be used if you want to store the key in the safer RAMEND directly, so no backup is needed
102
+
95
103
// We check DTR state to determine if host port is open (bit 0 of lineState).
96
104
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01 ) == 0 )
97
105
{
98
- *(uint16_t *)(RAMEND-1 ) = *(uint16_t *)0x0800 ;
99
- *(uint16_t *)0x0800 = 0x7777 ;
106
+ #if !defined(NO_MAGIC_KEY_BACKUP)
107
+ *(uint16_t *)(RAMEND-1 ) = *MAGIC_KEY_POS;
108
+ *MAGIC_KEY_POS = MAGIC_KEY;
109
+ #else
110
+ // for future boards save the key in the inproblematic RAMEND
111
+ // which is reserved for the main() return value (which will never return)
112
+ *MAGIC_KEY_POS = MAGIC_KEY;
113
+ #endif
100
114
wdt_enable (WDTO_120MS);
101
115
}
102
116
else
@@ -108,7 +122,11 @@ bool CDC_Setup(USBSetup& setup)
108
122
109
123
wdt_disable ();
110
124
wdt_reset ();
111
- *(uint16_t *)0x0800 = *(uint16_t *)(RAMEND-1 );
125
+ #if !defined(NO_MAGIC_KEY_BACKUP)
126
+ *MAGIC_KEY_POS = *(uint16_t *)(RAMEND-1 );
127
+ #else
128
+ *MAGIC_KEY_POS = 0x0000 ;
129
+ #endif
112
130
}
113
131
}
114
132
return true ;
You can’t perform that action at this time.
0 commit comments