diff options
Diffstat (limited to 'ports/zephyr/main.c')
| -rw-r--r-- | ports/zephyr/main.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c index c4a135aa5..47c954622 100644 --- a/ports/zephyr/main.c +++ b/ports/zephyr/main.c @@ -114,14 +114,20 @@ static void vfs_init(void) { #endif // MICROPY_VFS int real_main(void) { - mp_stack_ctrl_init(); - // Make MicroPython's stack limit somewhat smaller than full stack available - mp_stack_set_limit(CONFIG_MAIN_STACK_SIZE - 512); + volatile int stack_dummy = 0; + + #if MICROPY_PY_THREAD + struct k_thread *z_thread = (struct k_thread *)k_current_get(); + mp_thread_init((void *)z_thread->stack_info.start, z_thread->stack_info.size / sizeof(uintptr_t)); + #endif init_zephyr(); mp_hal_init(); soft_reset: + mp_stack_set_top((void *)&stack_dummy); + // Make MicroPython's stack limit somewhat smaller than full stack available + mp_stack_set_limit(CONFIG_MAIN_STACK_SIZE - 512); #if MICROPY_ENABLE_GC gc_init(heap, heap + sizeof(heap)); #endif @@ -160,6 +166,14 @@ soft_reset: machine_pin_deinit(); #endif + #if MICROPY_PY_THREAD + mp_thread_deinit(); + gc_collect(); + #endif + + gc_sweep_all(); + mp_deinit(); + goto soft_reset; return 0; @@ -171,6 +185,9 @@ void gc_collect(void) { void *dummy; gc_collect_start(); gc_collect_root(&dummy, ((mp_uint_t)MP_STATE_THREAD(stack_top) - (mp_uint_t)&dummy) / sizeof(mp_uint_t)); + #if MICROPY_PY_THREAD + mp_thread_gc_others(); + #endif gc_collect_end(); } |
