Skip to content
Snippets Groups Projects
Commit d5df8c09 authored by Cristian Maglie's avatar Cristian Maglie Committed by Cristian Maglie
Browse files

bootloader: bootloader start is triggered by magic number

To improve stability if the sketch overwrite the last SRAM location
(in this case the double tap doesn't work but at least the sketch
starts without problems)
parent 2c0b856c
No related branches found
No related tags found
No related merge requests found
......@@ -98,6 +98,7 @@ static void check_start_application(void)
led_port->OUTCLR.reg = (1<<30);
#if defined(BOOT_DOUBLE_TAP_ADDRESS)
#define DOUBLE_TAP_MAGIC 0x07738135
if (PM->RCAUSE.bit.POR)
{
/* On power-on initialize double-tap */
......@@ -105,9 +106,10 @@ static void check_start_application(void)
}
else
{
if (BOOT_DOUBLE_TAP_DATA == 0) {
switch (BOOT_DOUBLE_TAP_DATA) {
case 0:
/* First tap */
BOOT_DOUBLE_TAP_DATA = 1;
BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;
for (uint32_t i=0; i<50000; i++) /* 200ms */
/* force compiler to not optimize this... */
......@@ -115,10 +117,14 @@ static void check_start_application(void)
/* Timeout happened, continue boot... */
BOOT_DOUBLE_TAP_DATA = 0;
} else {
break;
case DOUBLE_TAP_MAGIC:
/* Second tap, stay in bootloader */
BOOT_DOUBLE_TAP_DATA = 0;
return;
default:
/* Fallback... reset counter and continue boot */
BOOT_DOUBLE_TAP_DATA = 0;
}
}
#endif
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment