From fcd60915e2751a30c74b2f620a94ffd273dce386 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 9 Mar 2017 16:09:13 +0100 Subject: [PATCH] atmel-samd: Turn on stack checking so infinite recursion doesn't completely crash. --- atmel-samd/main.c | 9 +++++++++ atmel-samd/mpconfigport.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/atmel-samd/main.c b/atmel-samd/main.c index 5f99292eca..ad124b58a4 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 91ae2091f9..1d1abe21e6 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