Skip to content

Commit 3448973

Browse files
committed
Made Magic Key Settings more flexible
1 parent bd93add commit 3448973

File tree

1 file changed

+20
-3
lines changed
  • hardware/arduino/avr/cores/arduino

1 file changed

+20
-3
lines changed

hardware/arduino/avr/cores/arduino/CDC.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,24 @@ bool CDC_Setup(USBSetup& setup)
9292
// with a relatively long period so it can finish housekeeping tasks
9393
// like servicing endpoints before the sketch ends
9494

95+
#ifndef MAGIC_KEY
96+
#define MAGIC_KEY 0x7777
97+
#endif
98+
#ifndef MAGIC_KEY_POS
99+
#define MAGIC_KEY_POS 0x0800
100+
#endif
101+
95102
// We check DTR state to determine if host port is open (bit 0 of lineState).
96103
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
97104
{
98-
*(uint16_t *)(RAMEND-1) = *(uint16_t *)0x0800;
99-
*(uint16_t *)0x0800 = 0x7777;
105+
#if MAGIC_KEY_POS != (RAMEND-1)
106+
*(uint16_t *)(RAMEND-1) = *(uint16_t *)MAGIC_KEY_POS;
107+
*(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY;
108+
#else
109+
// for future boards save the key in the inproblematic RAMEND
110+
// which is reserved for the main() return value (which will never return)
111+
*(uint16_t *)MAGIC_KEY_POS = MAGIC_KEY;
112+
#endif
100113
wdt_enable(WDTO_120MS);
101114
}
102115
else
@@ -108,7 +121,11 @@ bool CDC_Setup(USBSetup& setup)
108121

109122
wdt_disable();
110123
wdt_reset();
111-
*(uint16_t *)0x0800 = *(uint16_t *)(RAMEND-1);
124+
#if MAGIC_KEY_POS != (RAMEND-1)
125+
*(uint16_t *)MAGIC_KEY_POS = *(uint16_t *)(RAMEND-1);
126+
#else
127+
*(uint16_t *)MAGIC_KEY_POS = 0x0000;
128+
#endif
112129
}
113130
}
114131
return true;

0 commit comments

Comments
 (0)