Skip to content

Commit 7ddb266

Browse files
committed
Avoid erasing the chip if the sketch doesn't contain a bootloader
Use the information retrieved from the linker script in use to simply call a reset without any erase
1 parent be280ec commit 7ddb266

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cores/arduino/Reset.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ static void banzai() {
4343
// Disable all interrupts
4444
__disable_irq();
4545

46+
// Avoid erasing the application if APP_START is < than the minimum bootloader size
47+
// This could happen if without_bootloader linker script was chosen
48+
// Minimum bootloader size in SAMD21 family is 512bytes (RM section 22.6.5)
49+
if (APP_START < (0x200 + 4)) {
50+
goto reset;
51+
}
52+
4653
// Erase application
4754
while (!nvmReady())
4855
;
@@ -52,6 +59,7 @@ static void banzai() {
5259
while (!nvmReady())
5360
;
5461

62+
reset:
5563
// Reset the device
5664
NVIC_SystemReset() ;
5765

0 commit comments

Comments
 (0)