Skip to content

Commit fcd6091

Browse files
committed
atmel-samd: Turn on stack checking so infinite recursion doesn't completely crash.
1 parent 0f78eea commit fcd6091

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

atmel-samd/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "py/runtime.h"
88
#include "py/repl.h"
99
#include "py/gc.h"
10+
#include "py/stackctrl.h"
1011

1112
#include "lib/fatfs/ff.h"
1213
#include "lib/fatfs/diskio.h"
@@ -503,6 +504,9 @@ void samd21_init(void) {
503504
nvm_set_config(&config_nvm);
504505
}
505506

507+
extern uint32_t _estack;
508+
extern uint32_t _ebss;
509+
506510
int main(void) {
507511
// initialise the cpu and peripherals
508512
samd21_init();
@@ -513,6 +517,11 @@ int main(void) {
513517
// stack between here and where gc_collect is called.
514518
stack_top = (char*)&stack_dummy;
515519

520+
// Stack limit should be less than real stack size, so we have a chance
521+
// to recover from limit hit. (Limit is measured in bytes.)
522+
mp_stack_ctrl_init();
523+
mp_stack_set_limit((char*)&_estack - (char*)&_ebss - 1024);
524+
516525
// Initialise the local flash filesystem after the gc in case we need to
517526
// grab memory from it. Create it if needed, mount in on /flash, and set it
518527
// as current dir.

atmel-samd/mpconfigport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100

101101
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void*)((mp_uint_t)(p) | 1))
102102

103+
#define MICROPY_STACK_CHECK (1)
104+
103105
// This port is intended to be 32-bit, but unfortunately, int32_t for
104106
// different targets may be defined in different ways - either as int
105107
// or as long. This requires different printf formatting specifiers

0 commit comments

Comments
 (0)