Skip to content

[Bootloader] Check sketch vectors before waiting for double tap #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions bootloaders/zero/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,6 @@ static void check_start_application(void)
// LED_init();
// LED_off();

#if defined(BOOT_DOUBLE_TAP_ADDRESS)
#define DOUBLE_TAP_MAGIC 0x07738135
if (PM->RCAUSE.bit.POR)
{
/* On power-on initialize double-tap */
BOOT_DOUBLE_TAP_DATA = 0;
}
else
{
if (BOOT_DOUBLE_TAP_DATA == DOUBLE_TAP_MAGIC)
{
/* Second tap, stay in bootloader */
BOOT_DOUBLE_TAP_DATA = 0;
return;
}

/* First tap */
BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;

/* Wait 0.5sec to see if the user tap reset again.
* The loop value is based on SAMD21 default 1MHz clock @ reset.
*/
for (uint32_t i=0; i<125000; i++) /* 500ms */
/* force compiler to not optimize this... */
__asm__ __volatile__("");

/* Timeout happened, continue boot... */
BOOT_DOUBLE_TAP_DATA = 0;
}
#endif

#if (!defined DEBUG) || ((defined DEBUG) && (DEBUG == 0))
uint32_t* pulSketch_Start_Address;
#endif
Expand Down Expand Up @@ -108,6 +77,37 @@ uint32_t* pulSketch_Start_Address;
return;
}

#if defined(BOOT_DOUBLE_TAP_ADDRESS)
#define DOUBLE_TAP_MAGIC 0x07738135
if (PM->RCAUSE.bit.POR)
{
/* On power-on initialize double-tap */
BOOT_DOUBLE_TAP_DATA = 0;
}
else
{
if (BOOT_DOUBLE_TAP_DATA == DOUBLE_TAP_MAGIC)
{
/* Second tap, stay in bootloader */
BOOT_DOUBLE_TAP_DATA = 0;
return;
}

/* First tap */
BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;

/* Wait 0.5sec to see if the user tap reset again.
* The loop value is based on SAMD21 default 1MHz clock @ reset.
*/
for (uint32_t i=0; i<125000; i++) /* 500ms */
/* force compiler to not optimize this... */
__asm__ __volatile__("");

/* Timeout happened, continue boot... */
BOOT_DOUBLE_TAP_DATA = 0;
}
#endif

/*
#if defined(BOOT_LOAD_PIN)
volatile PortGroup *boot_port = (volatile PortGroup *)(&(PORT->Group[BOOT_LOAD_PIN / 32]));
Expand Down