Skip to content

Commit 1160635

Browse files
committed
Enable PYSTACK to keep function state out of the heap
1 parent 9cdf5e1 commit 1160635

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
9797
}
9898
}
9999

100+
#if MICROPY_ENABLE_PYSTACK
101+
static size_t PLACE_IN_DTCM_BSS(_pystack)[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)];
102+
#endif
103+
100104
void start_mp(supervisor_allocation* heap) {
101105
reset_status_led();
102106
autoreload_stop();
@@ -125,6 +129,10 @@ void start_mp(supervisor_allocation* heap) {
125129
// Clear the readline history. It references the heap we're about to destroy.
126130
readline_init0();
127131

132+
#if MICROPY_ENABLE_PYSTACK
133+
mp_pystack_init(_pystack, _pystack + sizeof(_pystack));
134+
#endif
135+
128136
#if MICROPY_ENABLE_GC
129137
gc_init(heap->ptr, heap->ptr + heap->length / 4);
130138
#endif

py/circuitpy_mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
#define MICROPY_QSTR_BYTES_IN_HASH (1)
120120
#define MICROPY_REPL_AUTO_INDENT (1)
121121
#define MICROPY_REPL_EVENT_DRIVEN (0)
122+
#define MICROPY_ENABLE_PYSTACK (1)
122123
#define MICROPY_STACK_CHECK (1)
123124
#define MICROPY_STREAMS_NON_BLOCK (1)
124125
#ifndef MICROPY_USE_INTERNAL_PRINTF
@@ -785,6 +786,10 @@ void supervisor_run_background_tasks_if_tick(void);
785786
#define CIRCUITPY_FILESYSTEM_FLUSH_INTERVAL_MS 1000
786787
#endif
787788

789+
#ifndef CIRCUITPY_PYSTACK_SIZE
790+
#define CIRCUITPY_PYSTACK_SIZE 1024
791+
#endif
792+
788793
#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt"
789794

790795
#define CIRCUITPY_VERBOSE_BLE 0

0 commit comments

Comments
 (0)