Skip to content

Commit 95963e6

Browse files
authored
Merge pull request #185 from facchinm/autoconf_sketch_start_banzai_mainline
Add method to automatically retrieve sketch start
2 parents 2f3b976 + 7ddb266 commit 95963e6

File tree

11 files changed

+38
-6
lines changed

11 files changed

+38
-6
lines changed

VARIANT_COMPLIANCE_CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
SAMD CORE 1.6.10
2+
3+
* the linker script is use should define __text_start__ symbol at the beginning of .text section
4+
15
SAMD CORE 1.6.6
26

37
* digitalPinToInterrupt #define moved to Arduino.h, variant.h must no longer define it

cores/arduino/Reset.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ extern "C" {
2424
#endif
2525

2626
#define NVM_MEMORY ((volatile uint16_t *)0x000000)
27+
28+
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10610)
29+
30+
extern const uint32_t __text_start__;
31+
#define APP_START ((volatile uint32_t)(&__text_start__) + 4)
32+
33+
#else
2734
#define APP_START 0x00002004
35+
#endif
2836

2937
static inline bool nvmReady(void) {
3038
return NVMCTRL->INTFLAG.reg & NVMCTRL_INTFLAG_READY;
@@ -35,6 +43,13 @@ static void banzai() {
3543
// Disable all interrupts
3644
__disable_irq();
3745

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+
3853
// Erase application
3954
while (!nvmReady())
4055
;
@@ -44,6 +59,7 @@ static void banzai() {
4459
while (!nvmReady())
4560
;
4661

62+
reset:
4763
// Reset the device
4864
NVIC_SystemReset() ;
4965

variants/arduino_zero/linker_scripts/gcc/flash_with_bootloader.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ SECTIONS
6565
{
6666
.text :
6767
{
68+
__text_start__ = .;
69+
6870
KEEP(*(.isr_vector))
6971
*(.text*)
7072

variants/arduino_zero/linker_scripts/gcc/flash_without_bootloader.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ SECTIONS
6666
{
6767
.text :
6868
{
69+
__text_start__ = .;
70+
6971
KEEP(*(.isr_vector))
7072
*(.text*)
7173

variants/arduino_zero/variant.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#ifndef _VARIANT_ARDUINO_ZERO_
2020
#define _VARIANT_ARDUINO_ZERO_
2121

22-
// The definitions here needs a SAMD core >=1.6.6
23-
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10606
22+
// The definitions here needs a SAMD core >=1.6.10
23+
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10610
2424

2525
/*----------------------------------------------------------------------------
2626
* Definitions

variants/mkr1000/linker_scripts/gcc/flash_with_bootloader.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ SECTIONS
6565
{
6666
.text :
6767
{
68+
__text_start__ = .;
69+
6870
KEEP(*(.isr_vector))
6971
*(.text*)
7072

variants/mkr1000/linker_scripts/gcc/flash_without_bootloader.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ SECTIONS
6666
{
6767
.text :
6868
{
69+
__text_start__ = .;
70+
6971
KEEP(*(.isr_vector))
7072
*(.text*)
7173

variants/mkr1000/variant.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
#pragma once
2020

21-
// The definitions here needs a SAMD core >=1.6.6
22-
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10606
21+
// The definitions here needs a SAMD core >=1.6.10
22+
#define ARDUINO_SAMD_VARIANT_COMPLIANCE 10610
2323

2424
#include <WVariant.h>
2525

variants/mkrzero/linker_scripts/gcc/flash_with_bootloader.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ SECTIONS
6565
{
6666
.text :
6767
{
68+
__text_start__ = .;
69+
6870
KEEP(*(.isr_vector))
6971
*(.text*)
7072

variants/mkrzero/linker_scripts/gcc/flash_without_bootloader.ld

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ SECTIONS
6666
{
6767
.text :
6868
{
69+
__text_start__ = .;
70+
6971
KEEP(*(.isr_vector))
7072
*(.text*)
7173

0 commit comments

Comments
 (0)