summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-03-09 16:09:13 +0100
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-03-09 16:09:13 +0100
commitfcd60915e2751a30c74b2f620a94ffd273dce386 (patch)
tree32f2a3cfdcfb7766f368a57d59c7765f0b0c8df7
parent0f78eea5d8059c1dbb3924c19cfa682fc615ab6a (diff)
atmel-samd: Turn on stack checking so infinite recursion doesn't completely crash.
-rw-r--r--atmel-samd/main.c9
-rw-r--r--atmel-samd/mpconfigport.h2
2 files changed, 11 insertions, 0 deletions
diff --git a/atmel-samd/main.c b/atmel-samd/main.c
index 5f99292ec..ad124b58a 100644
--- a/atmel-samd/main.c
+++ b/atmel-samd/main.c
@@ -7,6 +7,7 @@
#include "py/runtime.h"
#include "py/repl.h"
#include "py/gc.h"
+#include "py/stackctrl.h"
#include "lib/fatfs/ff.h"
#include "lib/fatfs/diskio.h"
@@ -503,6 +504,9 @@ void samd21_init(void) {
nvm_set_config(&config_nvm);
}
+extern uint32_t _estack;
+extern uint32_t _ebss;
+
int main(void) {
// initialise the cpu and peripherals
samd21_init();
@@ -513,6 +517,11 @@ int main(void) {
// stack between here and where gc_collect is called.
stack_top = (char*)&stack_dummy;
+ // Stack limit should be less than real stack size, so we have a chance
+ // to recover from limit hit. (Limit is measured in bytes.)
+ mp_stack_ctrl_init();
+ mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024);
+
// Initialise the local flash filesystem after the gc in case we need to
// grab memory from it. Create it if needed, mount in on /flash, and set it
// as current dir.
diff --git a/atmel-samd/mpconfigport.h b/atmel-samd/mpconfigport.h
index 91ae2091f..1d1abe21e 100644
--- a/atmel-samd/mpconfigport.h
+++ b/atmel-samd/mpconfigport.h
@@ -100,6 +100,8 @@
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
+#define MICROPY_STACK_CHECK (1)
+
// This port is intended to be 32-bit, but unfortunately, int32_t for
// different targets may be defined in different ways - either as int
// or as long. This requires different printf formatting specifiers