Go Down

Topic: Forcing bootloader startup through program (Read 266 times) previous topic - next topic

tolis81

Hello,
I am trying to find out if it is possible to trigger programmatically the double-tap on reset button function, implemented in modified version of Atmel's SAM-BA bootloader. In case this is not possible using the stock board setup, if this can be achieved by hardware or bootloader modifications.

MartinL

Hi tolis81,

Here's some code that will programmatically place the board into bootloader mode after a system reset:

Code: [Select]
// Code to programmatically initiate bootloader mode after reset
#define BOOT_DOUBLE_TAP_ADDRESS           (0x20007FFCul)
#define BOOT_DOUBLE_TAP_DATA              (*((volatile uint32_t *) BOOT_DOUBLE_TAP_ADDRESS))
#define DOUBLE_TAP_MAGIC 0x07738135

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);               // Initialise the LED as an OUTPUT
}

void loop()
{
  for (uint8_t i = 0; i < 5; i++)             // Blink the built-in LED for 5 seconds before reset
  {
    digitalWrite(LED_BUILTIN, HIGH);          // Turn LED on
    delay(500);                               // Wait half a second
    digitalWrite(LED_BUILTIN, LOW);           // turn the LED off by making the voltage LOW
    delay(500);                               // Wait for a second
  }
  BOOT_DOUBLE_TAP_DATA = DOUBLE_TAP_MAGIC;    // Start in bootloader mode after reset
  NVIC_SystemReset();                         // Reset the microcontroller
}

qniens

For (Adafruit) SAMD51 devices (Feather M4, ItsyBitsy M4, etc) the 'magic' code is:

Code: [Select]
#define DOUBLE_TAP_MAGIC 0xf01669efUL
#define BOOT_DOUBLE_TAP_ADDRESS     (HSRAM_ADDR + HSRAM_SIZE - 4)

unsigned long *a = (unsigned long *)BOOT_DOUBLE_TAP_ADDRESS;
*a = DOUBLE_TAP_MAGIC;
NVIC_SystemReset();

MartinL

Hi qniens,

Thanks, good to know that the magic works on the SAMD51 as well.

MartinL

tolis81

#4
Feb 20, 2021, 05:08 pm Last Edit: Feb 20, 2021, 05:36 pm by tolis81
Hi MartinL and qniens. Thank you both for the answers. Hopefully I'll get my board this week for testing. The post delays are awful.

tolis81

Go Up