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

Added "double-tap" feature to bootloader

Bootloader is activated by quickly double tapping to the reset button
parent 5a6dafaf
No related branches found
No related tags found
No related merge requests found
......@@ -97,6 +97,32 @@ static void check_start_application(void)
led_port->DIRSET.reg = (1<<30);
led_port->OUTCLR.reg = (1<<30);
#if defined(BOOT_DOUBLE_TAP_ADDRESS)
if (PM->RCAUSE.bit.POR)
{
/* On power-on initialize double-tap */
BOOT_DOUBLE_TAP_DATA = 0;
}
else
{
if (BOOT_DOUBLE_TAP_DATA == 0) {
/* First tap */
BOOT_DOUBLE_TAP_DATA = 1;
for (uint32_t i=0; i<50000; i++) /* 200ms */
/* force compiler to not optimize this... */
__asm__ __volatile__("");
/* Timeout happened, continue boot... */
BOOT_DOUBLE_TAP_DATA = 0;
} else {
/* Second tap, stay in bootloader */
BOOT_DOUBLE_TAP_DATA = 0;
return;
}
}
#endif
uint32_t app_start_address;
/* Load the Reset Handler address of the application */
......
......@@ -34,6 +34,16 @@
#define CPU_FREQUENCY 8000000
#define APP_START_ADDRESS 0x00002000
/*
* If BOOT_DOUBLE_TAP_ADDRESS is defined the bootloader is started by
* quickly tapping two times on the reset button.
* BOOT_DOUBLE_TAP_ADDRESS must point to a free SRAM cell that must not
* be touched from the loaded application.
*/
#define BOOT_DOUBLE_TAP_ADDRESS 0x20007FFC
#define BOOT_DOUBLE_TAP_DATA (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
#define BOOT_LOAD_PIN PIN_PA21 //Pin 7
//#define BOOT_LOAD_PIN PIN_PA15 //Pin 5
#define BOOT_PIN_MASK (1U << (BOOT_LOAD_PIN & 0x1f))
......
No preview for this file type
......@@ -50,7 +50,7 @@ SEARCH_DIR(.)
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000-0x0004 /* 4 bytes used by bootloader to keep data between resets */
}
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
......
......@@ -25,8 +25,8 @@
*/
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
FLASH (rx) : ORIGIN = 0x00000000+0x2000, LENGTH = 0x00040000-0x2000 /* First 8KB used by bootloader */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000-0x0004 /* Last 4B used by bootloader */
}
/* Linker script to place sections and symbol values. Should be used together
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment