From a460410d6a6fed0493ca5b245b8e7d8e7f76f286 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 10 Feb 2023 22:45:25 +0200 Subject: [PATCH 01/35] First attempt at using alloc --- main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index d70e718b6d..8376e0b089 100644 --- a/main.c +++ b/main.c @@ -123,7 +123,8 @@ uint8_t value_out = 0; #endif #if MICROPY_ENABLE_PYSTACK -static size_t PLACE_IN_DTCM_BSS(_pystack[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)]); +size_t *_pystack; +int _pystack_size = CIRCUITPY_PYSTACK_SIZE; #endif static void reset_devices(void) { @@ -160,7 +161,7 @@ STATIC void start_mp(supervisor_allocation *heap) { readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(_pystack, _pystack + (sizeof(_pystack) / sizeof(size_t))); + mp_pystack_init(_pystack, _pystack + (_pystack_size / sizeof(size_t))); #endif #if MICROPY_ENABLE_GC @@ -912,6 +913,10 @@ STATIC int run_repl(void) { } int __attribute__((used)) main(void) { + + // allocate the pystack + _pystack = (size_t *)allocate_memory(_pystack_size, false, false); + // initialise the cpu and peripherals safe_mode_t safe_mode = port_init(); From 1f1a495e26a94873f7094a59400465171e5558ad Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Mon, 13 Feb 2023 20:57:54 +0200 Subject: [PATCH 02/35] rename _pystack -> pystack --- main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 8376e0b089..6f3f2820cd 100644 --- a/main.c +++ b/main.c @@ -123,8 +123,8 @@ uint8_t value_out = 0; #endif #if MICROPY_ENABLE_PYSTACK -size_t *_pystack; -int _pystack_size = CIRCUITPY_PYSTACK_SIZE; +size_t *pystack; +int pystack_size = CIRCUITPY_PYSTACK_SIZE; #endif static void reset_devices(void) { @@ -161,7 +161,7 @@ STATIC void start_mp(supervisor_allocation *heap) { readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(_pystack, _pystack + (_pystack_size / sizeof(size_t))); + mp_pystack_init(pystack, pystack + (pystack_size / sizeof(size_t))); #endif #if MICROPY_ENABLE_GC @@ -914,8 +914,10 @@ STATIC int run_repl(void) { int __attribute__((used)) main(void) { + #if MICROPY_ENABLE_PYSTACK // allocate the pystack - _pystack = (size_t *)allocate_memory(_pystack_size, false, false); + pystack = (size_t *)allocate_memory(pystack_size, false, false); + #endif // initialise the cpu and peripherals safe_mode_t safe_mode = port_init(); From 422098e1711259d18b4b26077f8435302d1fb1d7 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 12:30:42 +0200 Subject: [PATCH 03/35] pystack is now a valid supervisor allocation --- main.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 6f3f2820cd..7b9f10d1e3 100644 --- a/main.c +++ b/main.c @@ -122,18 +122,13 @@ uint8_t value_out = 0; #endif -#if MICROPY_ENABLE_PYSTACK -size_t *pystack; -int pystack_size = CIRCUITPY_PYSTACK_SIZE; -#endif - static void reset_devices(void) { #if CIRCUITPY_BLEIO_HCI bleio_reset(); #endif } -STATIC void start_mp(supervisor_allocation *heap) { +STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack, int pystack_size) { supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance @@ -161,7 +156,7 @@ STATIC void start_mp(supervisor_allocation *heap) { readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(pystack, pystack + (pystack_size / sizeof(size_t))); + mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); #endif #if MICROPY_ENABLE_GC @@ -364,7 +359,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } } -STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { +STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset, supervisor_allocation *pystack, int pystack_size) { bool serial_connected_at_start = serial_connected(); bool printed_safe_mode_message = false; #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 @@ -403,7 +398,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { supervisor_allocation *heap = allocate_remaining_memory(); // Prepare the VM state. - start_mp(heap); + start_mp(heap, pystack, pystack_size); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -731,7 +726,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { vstr_t *boot_output; -STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { +STATIC void run_boot_py(safe_mode_t safe_mode, supervisor_allocation *pystack, int pystack_size) { if (safe_mode == NO_HEAP) { return; } @@ -749,7 +744,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap); + start_mp(heap, pystack, pystack_size); #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -846,12 +841,12 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { #endif } -STATIC int run_repl(void) { +STATIC int run_repl(supervisor_allocation *pystack, int pystack_size) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap); + start_mp(heap, pystack, pystack_size); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -915,8 +910,11 @@ STATIC int run_repl(void) { int __attribute__((used)) main(void) { #if MICROPY_ENABLE_PYSTACK + supervisor_allocation *pystack; + int pystack_size = CIRCUITPY_PYSTACK_SIZE; + // allocate the pystack - pystack = (size_t *)allocate_memory(pystack_size, false, false); + pystack = allocate_memory(pystack_size, false, false); #endif // initialise the cpu and peripherals @@ -998,7 +996,7 @@ int __attribute__((used)) main(void) { filesystem_set_internal_concurrent_write_protection(true); filesystem_set_internal_writable_by_usb(CIRCUITPY_USB == 1); - run_boot_py(safe_mode); + run_boot_py(safe_mode, pystack, pystack_size); supervisor_workflow_start(); @@ -1012,7 +1010,7 @@ int __attribute__((used)) main(void) { bool simulate_reset = true; for (;;) { if (!skip_repl) { - exit_code = run_repl(); + exit_code = run_repl(pystack, pystack_size); supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); } if (exit_code == PYEXEC_FORCED_EXIT) { @@ -1023,7 +1021,7 @@ int __attribute__((used)) main(void) { // If code.py did a fake deep sleep, pretend that we // are running code.py for the first time after a hard // reset. This will preserve any alarm information. - skip_repl = run_code_py(safe_mode, &simulate_reset); + skip_repl = run_code_py(safe_mode, &simulate_reset, pystack, pystack_size); } else { skip_repl = false; } From 9e2235d7f716171f8cf1432b59d64edc914c9794 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 15:23:16 +0200 Subject: [PATCH 04/35] pystack works via settings.toml, stackless not working yet --- main.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 7b9f10d1e3..19bfe85973 100644 --- a/main.c +++ b/main.c @@ -122,6 +122,10 @@ uint8_t value_out = 0; #endif +#if MICROPY_ENABLE_PYSTACK +#include "shared-module/os/__init__.h" +#endif + static void reset_devices(void) { #if CIRCUITPY_BLEIO_HCI bleio_reset(); @@ -156,7 +160,9 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); + if (pystack_size > 0) { + mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); + } #endif #if MICROPY_ENABLE_GC @@ -398,7 +404,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset, supervisor_ supervisor_allocation *heap = allocate_remaining_memory(); // Prepare the VM state. + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // stackless doesn't want allocations. start_mp(heap, pystack, pystack_size); + #pragma GCC diagnostic pop #if CIRCUITPY_USB usb_setup_with_vm(); @@ -743,8 +752,10 @@ STATIC void run_boot_py(safe_mode_t safe_mode, supervisor_allocation *pystack, i // Do USB setup even if boot.py is not run. supervisor_allocation *heap = allocate_remaining_memory(); - + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // stackless doesn't want allocations. start_mp(heap, pystack, pystack_size); + #pragma GCC diagnostic pop #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -846,7 +857,10 @@ STATIC int run_repl(supervisor_allocation *pystack, int pystack_size) { stack_resize(); filesystem_flush(); supervisor_allocation *heap = allocate_remaining_memory(); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // stackless doesn't want allocations. start_mp(heap, pystack, pystack_size); + #pragma GCC diagnostic pop #if CIRCUITPY_USB usb_setup_with_vm(); @@ -909,14 +923,6 @@ STATIC int run_repl(supervisor_allocation *pystack, int pystack_size) { int __attribute__((used)) main(void) { - #if MICROPY_ENABLE_PYSTACK - supervisor_allocation *pystack; - int pystack_size = CIRCUITPY_PYSTACK_SIZE; - - // allocate the pystack - pystack = allocate_memory(pystack_size, false, false); - #endif - // initialise the cpu and peripherals safe_mode_t safe_mode = port_init(); @@ -974,6 +980,38 @@ int __attribute__((used)) main(void) { alarm_reset(); #endif + // Pystack variables have to exist even in stackless for the function calls + supervisor_allocation *pystack; + int pystack_size = CIRCUITPY_PYSTACK_SIZE; // Use build default for now. + #if MICROPY_ENABLE_PYSTACK + // Allocate default at least temporarily, needed for getenv + pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); + + // Fetch value if exists from settings.toml + #if CIRCUITPY_OS_GETENV + // Init needed. + supervisor_allocation *heap = allocate_remaining_memory(); + + // Leaves size to build default on any failure + (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); + free_memory(heap); + + // Check if value is valid multiple of size_t else revert + if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size > 0) && (pystack_size % sizeof(size_t) != 0)) { + pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default + // TODO: Find a way to inform the user about it. + // Perhaps safemode? + } + + if (CIRCUITPY_PYSTACK_SIZE != pystack_size) { + free_memory(pystack); // Free the temporary + if (pystack_size > 0) { // Allocate new if needed + pystack = allocate_memory(pystack_size, false, false); + } + } + #endif + #endif + // Reset everything and prep MicroPython to run boot.py. reset_port(); // Port-independent devices, like CIRCUITPY_BLEIO_HCI. From 0d5b400b331a05330b31ec29c57d11e5405371dc Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 16:08:22 +0200 Subject: [PATCH 05/35] swap int for mp_int_t --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 19bfe85973..55f464bc00 100644 --- a/main.c +++ b/main.c @@ -982,7 +982,7 @@ int __attribute__((used)) main(void) { // Pystack variables have to exist even in stackless for the function calls supervisor_allocation *pystack; - int pystack_size = CIRCUITPY_PYSTACK_SIZE; // Use build default for now. + mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; // Use build default for now. #if MICROPY_ENABLE_PYSTACK // Allocate default at least temporarily, needed for getenv pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); From 2077bb9da994c32008bf4b9ce14a7cf6a190b742 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 17:54:52 +0200 Subject: [PATCH 06/35] pystack_size as multiple of sizeof size_t, no more stackless via settings.toml --- main.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 55f464bc00..ffd5b80610 100644 --- a/main.c +++ b/main.c @@ -122,7 +122,7 @@ uint8_t value_out = 0; #endif -#if MICROPY_ENABLE_PYSTACK +#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV #include "shared-module/os/__init__.h" #endif @@ -160,9 +160,7 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack readline_init0(); #if MICROPY_ENABLE_PYSTACK - if (pystack_size > 0) { - mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); - } + mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); #endif #if MICROPY_ENABLE_GC @@ -995,9 +993,11 @@ int __attribute__((used)) main(void) { // Leaves size to build default on any failure (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); free_memory(heap); + // Convert frame count to allocation size, 384 is the default for 1536 bytes + pystack_size = pystack_size * sizeof(size_t); - // Check if value is valid multiple of size_t else revert - if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size > 0) && (pystack_size % sizeof(size_t) != 0)) { + // Check if value is valid + if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size < 1)) { pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default // TODO: Find a way to inform the user about it. // Perhaps safemode? @@ -1005,9 +1005,7 @@ int __attribute__((used)) main(void) { if (CIRCUITPY_PYSTACK_SIZE != pystack_size) { free_memory(pystack); // Free the temporary - if (pystack_size > 0) { // Allocate new if needed - pystack = allocate_memory(pystack_size, false, false); - } + pystack = allocate_memory(pystack_size, false, false); // Allocate new pystack } #endif #endif From fa302b2e29ff15095871d6cf01e0ad7f010a691e Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 21:54:53 +0200 Subject: [PATCH 07/35] Now works on reload. --- main.c | 102 +++++++++++++++++++++++++++------------------------------ 1 file changed, 48 insertions(+), 54 deletions(-) diff --git a/main.c b/main.c index ffd5b80610..3f9de99cd9 100644 --- a/main.c +++ b/main.c @@ -122,9 +122,13 @@ uint8_t value_out = 0; #endif -#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV +#if MICROPY_ENABLE_PYSTACK +supervisor_allocation *pystack; +mp_int_t pystack_size = 0; // 0 indicated 'not allocated' +#if CIRCUITPY_OS_GETENV #include "shared-module/os/__init__.h" #endif +#endif static void reset_devices(void) { #if CIRCUITPY_BLEIO_HCI @@ -132,7 +136,31 @@ static void reset_devices(void) { #endif } -STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack, int pystack_size) { +#if MICROPY_ENABLE_PYSTACK +STATIC void alloc_pystack(void) { + mp_int_t old_pystack_size = pystack_size; + pystack_size = CIRCUITPY_PYSTACK_SIZE; // Use build default for now. + // Fetch value if exists from settings.toml + #if CIRCUITPY_OS_GETENV + // Leaves size to build default on any failure + (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); + // Check if value is valid + if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 1) || (pystack_size % sizeof(size_t) != 0))) { + pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default + // TODO: Find a way to inform the user about it. + // Perhaps safemode? Or is it too much? + } + #endif + if (old_pystack_size != pystack_size) { + if (old_pystack_size != 0) { + free_memory(pystack); + } + pystack = allocate_memory(pystack_size, false, false); + } +} +#endif + +STATIC void start_mp(supervisor_allocation *heap) { supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance @@ -363,7 +391,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } } -STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset, supervisor_allocation *pystack, int pystack_size) { +STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { bool serial_connected_at_start = serial_connected(); bool printed_safe_mode_message = false; #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 @@ -399,13 +427,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset, supervisor_ }; #endif + #if MICROPY_ENABLE_PYSTACK + alloc_pystack(); + #endif supervisor_allocation *heap = allocate_remaining_memory(); - - // Prepare the VM state. - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // stackless doesn't want allocations. - start_mp(heap, pystack, pystack_size); - #pragma GCC diagnostic pop + start_mp(heap); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -733,7 +759,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset, supervisor_ vstr_t *boot_output; -STATIC void run_boot_py(safe_mode_t safe_mode, supervisor_allocation *pystack, int pystack_size) { +STATIC void run_boot_py(safe_mode_t safe_mode) { if (safe_mode == NO_HEAP) { return; } @@ -749,11 +775,11 @@ STATIC void run_boot_py(safe_mode_t safe_mode, supervisor_allocation *pystack, i // Do USB setup even if boot.py is not run. + #if MICROPY_ENABLE_PYSTACK + alloc_pystack(); + #endif supervisor_allocation *heap = allocate_remaining_memory(); - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // stackless doesn't want allocations. - start_mp(heap, pystack, pystack_size); - #pragma GCC diagnostic pop + start_mp(heap); #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -850,15 +876,15 @@ STATIC void run_boot_py(safe_mode_t safe_mode, supervisor_allocation *pystack, i #endif } -STATIC int run_repl(supervisor_allocation *pystack, int pystack_size) { +STATIC int run_repl(void) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); + #if MICROPY_ENABLE_PYSTACK + alloc_pystack(); + #endif supervisor_allocation *heap = allocate_remaining_memory(); - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // stackless doesn't want allocations. - start_mp(heap, pystack, pystack_size); - #pragma GCC diagnostic pop + start_mp(heap); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -978,38 +1004,6 @@ int __attribute__((used)) main(void) { alarm_reset(); #endif - // Pystack variables have to exist even in stackless for the function calls - supervisor_allocation *pystack; - mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; // Use build default for now. - #if MICROPY_ENABLE_PYSTACK - // Allocate default at least temporarily, needed for getenv - pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); - - // Fetch value if exists from settings.toml - #if CIRCUITPY_OS_GETENV - // Init needed. - supervisor_allocation *heap = allocate_remaining_memory(); - - // Leaves size to build default on any failure - (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); - free_memory(heap); - // Convert frame count to allocation size, 384 is the default for 1536 bytes - pystack_size = pystack_size * sizeof(size_t); - - // Check if value is valid - if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size < 1)) { - pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default - // TODO: Find a way to inform the user about it. - // Perhaps safemode? - } - - if (CIRCUITPY_PYSTACK_SIZE != pystack_size) { - free_memory(pystack); // Free the temporary - pystack = allocate_memory(pystack_size, false, false); // Allocate new pystack - } - #endif - #endif - // Reset everything and prep MicroPython to run boot.py. reset_port(); // Port-independent devices, like CIRCUITPY_BLEIO_HCI. @@ -1032,7 +1026,7 @@ int __attribute__((used)) main(void) { filesystem_set_internal_concurrent_write_protection(true); filesystem_set_internal_writable_by_usb(CIRCUITPY_USB == 1); - run_boot_py(safe_mode, pystack, pystack_size); + run_boot_py(safe_mode); supervisor_workflow_start(); @@ -1046,7 +1040,7 @@ int __attribute__((used)) main(void) { bool simulate_reset = true; for (;;) { if (!skip_repl) { - exit_code = run_repl(pystack, pystack_size); + exit_code = run_repl(); supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); } if (exit_code == PYEXEC_FORCED_EXIT) { @@ -1057,7 +1051,7 @@ int __attribute__((used)) main(void) { // If code.py did a fake deep sleep, pretend that we // are running code.py for the first time after a hard // reset. This will preserve any alarm information. - skip_repl = run_code_py(safe_mode, &simulate_reset, pystack, pystack_size); + skip_repl = run_code_py(safe_mode, &simulate_reset); } else { skip_repl = false; } From cf6afe250c6865671bfab20841729fc369a04cee Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 22:00:52 +0200 Subject: [PATCH 08/35] re-add attribute --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 3f9de99cd9..bc86d9182d 100644 --- a/main.c +++ b/main.c @@ -759,7 +759,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { vstr_t *boot_output; -STATIC void run_boot_py(safe_mode_t safe_mode) { +STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { if (safe_mode == NO_HEAP) { return; } From c3b9567641728000e617252559b7194012d2d449 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 22:27:37 +0200 Subject: [PATCH 09/35] using vm cleanup and no globals --- main.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/main.c b/main.c index bc86d9182d..fd1e508fc7 100644 --- a/main.c +++ b/main.c @@ -122,13 +122,9 @@ uint8_t value_out = 0; #endif -#if MICROPY_ENABLE_PYSTACK -supervisor_allocation *pystack; -mp_int_t pystack_size = 0; // 0 indicated 'not allocated' -#if CIRCUITPY_OS_GETENV +#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV #include "shared-module/os/__init__.h" #endif -#endif static void reset_devices(void) { #if CIRCUITPY_BLEIO_HCI @@ -137,30 +133,24 @@ static void reset_devices(void) { } #if MICROPY_ENABLE_PYSTACK -STATIC void alloc_pystack(void) { - mp_int_t old_pystack_size = pystack_size; - pystack_size = CIRCUITPY_PYSTACK_SIZE; // Use build default for now. - // Fetch value if exists from settings.toml +STATIC mp_int_t fetch_pystack_size(void) { + mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; #if CIRCUITPY_OS_GETENV + // Fetch value if exists from settings.toml // Leaves size to build default on any failure (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); // Check if value is valid if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 1) || (pystack_size % sizeof(size_t) != 0))) { - pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset to build default + pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset // TODO: Find a way to inform the user about it. // Perhaps safemode? Or is it too much? } #endif - if (old_pystack_size != pystack_size) { - if (old_pystack_size != 0) { - free_memory(pystack); - } - pystack = allocate_memory(pystack_size, false, false); - } + return pystack_size; } #endif -STATIC void start_mp(supervisor_allocation *heap) { +STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack, mp_int_t pystack_size) { supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance @@ -292,7 +282,7 @@ STATIC void count_strn(void *data, const char *str, size_t len) { *(size_t *)data += len; } -STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) { +STATIC void cleanup_after_vm(supervisor_allocation *heap, supervisor_allocation *pystack, mp_obj_t exception) { // Get the traceback of any exception from this run off the heap. // MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it" // MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback" @@ -373,6 +363,7 @@ STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) { filesystem_flush(); stop_mp(); free_memory(heap); + free_memory(pystack); supervisor_move_memory(); // Let the workflows know we've reset in case they want to restart. @@ -428,10 +419,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { #endif #if MICROPY_ENABLE_PYSTACK - alloc_pystack(); + mp_int_t pystack_size = fetch_pystack_size(); + supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); #endif supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap); + start_mp(heap, pystack, pystack_size); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -479,7 +471,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { // Finished executing python code. Cleanup includes filesystem flush and a board reset. - cleanup_after_vm(heap, _exec_result.exception); + cleanup_after_vm(heap, pystack, _exec_result.exception); _exec_result.exception = NULL; // If a new next code file was set, that is a reason to keep it (obviously). Stuff this into @@ -776,10 +768,11 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. #if MICROPY_ENABLE_PYSTACK - alloc_pystack(); + mp_int_t pystack_size = fetch_pystack_size(); + supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); #endif supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap); + start_mp(heap, pystack, pystack_size); #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -865,7 +858,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { port_post_boot_py(true); - cleanup_after_vm(heap, _exec_result.exception); + cleanup_after_vm(heap, pystack, _exec_result.exception); _exec_result.exception = NULL; port_post_boot_py(false); @@ -881,10 +874,11 @@ STATIC int run_repl(void) { stack_resize(); filesystem_flush(); #if MICROPY_ENABLE_PYSTACK - alloc_pystack(); + mp_int_t pystack_size = fetch_pystack_size(); + supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); #endif supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap); + start_mp(heap, pystack, pystack_size); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -927,7 +921,7 @@ STATIC int run_repl(void) { exit_code = PYEXEC_DEEP_SLEEP; } #endif - cleanup_after_vm(heap, MP_OBJ_SENTINEL); + cleanup_after_vm(heap, pystack, MP_OBJ_SENTINEL); // Also reset bleio. The above call omits it in case workflows should continue. In this case, // we're switching straight to another VM so we want to reset. From 818d1d4cb15832e90b79bc9f9f2f495fa68d3334 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 22:43:57 +0200 Subject: [PATCH 10/35] Discard pystack_size --- main.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index fd1e508fc7..599c80eb45 100644 --- a/main.c +++ b/main.c @@ -133,24 +133,25 @@ static void reset_devices(void) { } #if MICROPY_ENABLE_PYSTACK -STATIC mp_int_t fetch_pystack_size(void) { +STATIC supervisor_allocation __attribute__ ((noinline)) * alloc_pystack(void) { mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; #if CIRCUITPY_OS_GETENV // Fetch value if exists from settings.toml // Leaves size to build default on any failure (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); // Check if value is valid - if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 1) || (pystack_size % sizeof(size_t) != 0))) { + if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 384) || (pystack_size % sizeof(size_t) != 0))) { pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset // TODO: Find a way to inform the user about it. // Perhaps safemode? Or is it too much? } #endif - return pystack_size; + supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); + return pystack; } #endif -STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack, mp_int_t pystack_size) { +STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack) { supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance @@ -178,7 +179,7 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(pystack->ptr, pystack->ptr + (pystack_size / sizeof(size_t))); + mp_pystack_init(pystack->ptr, pystack->ptr + (get_allocation_length(pystack) / sizeof(size_t))); #endif #if MICROPY_ENABLE_GC @@ -419,11 +420,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { #endif #if MICROPY_ENABLE_PYSTACK - mp_int_t pystack_size = fetch_pystack_size(); - supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); + supervisor_allocation *pystack = alloc_pystack(); #endif supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap, pystack, pystack_size); + start_mp(heap, pystack); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -768,11 +768,10 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. #if MICROPY_ENABLE_PYSTACK - mp_int_t pystack_size = fetch_pystack_size(); - supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); + supervisor_allocation *pystack = alloc_pystack(); #endif supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap, pystack, pystack_size); + start_mp(heap, pystack); #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -874,11 +873,10 @@ STATIC int run_repl(void) { stack_resize(); filesystem_flush(); #if MICROPY_ENABLE_PYSTACK - mp_int_t pystack_size = fetch_pystack_size(); - supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); + supervisor_allocation *pystack = alloc_pystack(); #endif supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap, pystack, pystack_size); + start_mp(heap, pystack); #if CIRCUITPY_USB usb_setup_with_vm(); From 133045a95a74287206e62bb20900b8be699991b4 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 15 Feb 2023 23:15:21 +0200 Subject: [PATCH 11/35] Add error message and guardrail --- locale/circuitpython.pot | 14 ++++++++++++++ main.c | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 72ee60cc0c..299c1d5985 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -35,6 +35,20 @@ msgid "" "https://github.com/adafruit/circuitpython/issues\n" msgstr "" +#: main.c +msgid "" +"\n" +"WARNING: Allocating pystack failed, defaulting back to build value. \n" +"\n" +msgstr "" + +#: main.c +msgid "" +"\n" +"WARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n" +"\n" +msgstr "" + #: py/obj.c msgid " File \"%q\"" msgstr "" diff --git a/main.c b/main.c index 599c80eb45..64251e88a7 100644 --- a/main.c +++ b/main.c @@ -141,12 +141,15 @@ STATIC supervisor_allocation __attribute__ ((noinline)) * alloc_pystack(void) { (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); // Check if value is valid if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 384) || (pystack_size % sizeof(size_t) != 0))) { + serial_write_compressed(translate("\nWARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n\n")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset - // TODO: Find a way to inform the user about it. - // Perhaps safemode? Or is it too much? } #endif supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); + if (pystack == NULL) { + serial_write_compressed(translate("\nWARNING: Allocating pystack failed, defaulting back to build value. \n\n")); + pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); + } return pystack; } #endif From 8216aa48909b256417177173289f856971be3032 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 00:41:49 +0200 Subject: [PATCH 12/35] struct stacks --- main.c | 63 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/main.c b/main.c index 64251e88a7..1a85c01199 100644 --- a/main.c +++ b/main.c @@ -126,6 +126,13 @@ uint8_t value_out = 0; #include "shared-module/os/__init__.h" #endif +typedef struct { + #if MICROPY_ENABLE_PYSTACK + supervisor_allocation *pystack; + #endif + supervisor_allocation *heap; +} stacks; + static void reset_devices(void) { #if CIRCUITPY_BLEIO_HCI bleio_reset(); @@ -133,28 +140,33 @@ static void reset_devices(void) { } #if MICROPY_ENABLE_PYSTACK -STATIC supervisor_allocation __attribute__ ((noinline)) * alloc_pystack(void) { +STATIC stacks __attribute__ ((noinline)) alloc_stacks(void) { + stacks res; + #if MICROPY_ENABLE_PYSTACK mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; #if CIRCUITPY_OS_GETENV // Fetch value if exists from settings.toml // Leaves size to build default on any failure (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); // Check if value is valid - if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && ((pystack_size < 384) || (pystack_size % sizeof(size_t) != 0))) { + pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. + if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size < 384)) { serial_write_compressed(translate("\nWARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n\n")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset } #endif - supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); - if (pystack == NULL) { + res.pystack = allocate_memory(pystack_size, false, false); + if (res.pystack == NULL) { serial_write_compressed(translate("\nWARNING: Allocating pystack failed, defaulting back to build value. \n\n")); - pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); + res.pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); } - return pystack; + #endif + res.heap = allocate_remaining_memory(); + return res; } #endif -STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack) { +STATIC void start_mp(stacks combo) { supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance @@ -182,11 +194,11 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(pystack->ptr, pystack->ptr + (get_allocation_length(pystack) / sizeof(size_t))); + mp_pystack_init(combo.pystack->ptr, combo.pystack->ptr + get_allocation_length(combo.pystack) / sizeof(size_t)); #endif #if MICROPY_ENABLE_GC - gc_init(heap->ptr, heap->ptr + get_allocation_length(heap) / 4); + gc_init(combo.heap->ptr, combo.heap->ptr + get_allocation_length(combo.heap) / 4); #endif mp_init(); mp_obj_list_init((mp_obj_list_t *)mp_sys_path, 0); @@ -286,7 +298,7 @@ STATIC void count_strn(void *data, const char *str, size_t len) { *(size_t *)data += len; } -STATIC void cleanup_after_vm(supervisor_allocation *heap, supervisor_allocation *pystack, mp_obj_t exception) { +STATIC void cleanup_after_vm(stacks combo, mp_obj_t exception) { // Get the traceback of any exception from this run off the heap. // MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it" // MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback" @@ -366,8 +378,8 @@ STATIC void cleanup_after_vm(supervisor_allocation *heap, supervisor_allocation // Free the heap last because other modules may reference heap memory and need to shut down. filesystem_flush(); stop_mp(); - free_memory(heap); - free_memory(pystack); + free_memory(combo.heap); + free_memory(combo.pystack); supervisor_move_memory(); // Let the workflows know we've reset in case they want to restart. @@ -422,11 +434,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { }; #endif - #if MICROPY_ENABLE_PYSTACK - supervisor_allocation *pystack = alloc_pystack(); - #endif - supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap, pystack); + stacks combo = alloc_stacks(); + start_mp(combo); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -474,7 +483,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { // Finished executing python code. Cleanup includes filesystem flush and a board reset. - cleanup_after_vm(heap, pystack, _exec_result.exception); + cleanup_after_vm(combo, _exec_result.exception); _exec_result.exception = NULL; // If a new next code file was set, that is a reason to keep it (obviously). Stuff this into @@ -770,11 +779,8 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. - #if MICROPY_ENABLE_PYSTACK - supervisor_allocation *pystack = alloc_pystack(); - #endif - supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap, pystack); + stacks combo = alloc_stacks(); + start_mp(combo); #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -860,7 +866,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { port_post_boot_py(true); - cleanup_after_vm(heap, pystack, _exec_result.exception); + cleanup_after_vm(combo, _exec_result.exception); _exec_result.exception = NULL; port_post_boot_py(false); @@ -875,11 +881,8 @@ STATIC int run_repl(void) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); - #if MICROPY_ENABLE_PYSTACK - supervisor_allocation *pystack = alloc_pystack(); - #endif - supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap, pystack); + stacks combo = alloc_stacks(); + start_mp(combo); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -922,7 +925,7 @@ STATIC int run_repl(void) { exit_code = PYEXEC_DEEP_SLEEP; } #endif - cleanup_after_vm(heap, pystack, MP_OBJ_SENTINEL); + cleanup_after_vm(combo, MP_OBJ_SENTINEL); // Also reset bleio. The above call omits it in case workflows should continue. In this case, // we're switching straight to another VM so we want to reset. From 659adb717235cd841738da03d0e9cdf83a93252a Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 00:45:41 +0200 Subject: [PATCH 13/35] fix for stackless --- main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.c b/main.c index 1a85c01199..74f61d846d 100644 --- a/main.c +++ b/main.c @@ -379,7 +379,9 @@ STATIC void cleanup_after_vm(stacks combo, mp_obj_t exception) { filesystem_flush(); stop_mp(); free_memory(combo.heap); + #if MICROPY_ENABLE_PYSTACK free_memory(combo.pystack); + #endif supervisor_move_memory(); // Let the workflows know we've reset in case they want to restart. From 8061e8e7c647b9a509bd4812f91e88de8ec6d9da Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 11:05:29 +0200 Subject: [PATCH 14/35] Names changed to better fit mp style --- main.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index 06ddc0aa6d..dc5e015da7 100644 --- a/main.c +++ b/main.c @@ -131,7 +131,7 @@ typedef struct { supervisor_allocation *pystack; #endif supervisor_allocation *heap; -} stacks; +} vm_memory_t; static void reset_devices(void) { #if CIRCUITPY_BLEIO_HCI @@ -139,9 +139,8 @@ static void reset_devices(void) { #endif } -#if MICROPY_ENABLE_PYSTACK -STATIC stacks __attribute__ ((noinline)) alloc_stacks(void) { - stacks res; +STATIC vm_memory_t allocate_vm_memory(void) { + vm_memory_t res; #if MICROPY_ENABLE_PYSTACK mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; #if CIRCUITPY_OS_GETENV @@ -164,9 +163,8 @@ STATIC stacks __attribute__ ((noinline)) alloc_stacks(void) { res.heap = allocate_remaining_memory(); return res; } -#endif -STATIC void start_mp(stacks combo) { +STATIC void start_mp(vm_memory_t vm_memory) { supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance @@ -194,11 +192,11 @@ STATIC void start_mp(stacks combo) { readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(combo.pystack->ptr, combo.pystack->ptr + get_allocation_length(combo.pystack) / sizeof(size_t)); + mp_pystack_init(vm_memory.pystack->ptr, vm_memory.pystack->ptr + get_allocation_length(vm_memory.pystack) / sizeof(size_t)); #endif #if MICROPY_ENABLE_GC - gc_init(combo.heap->ptr, combo.heap->ptr + get_allocation_length(combo.heap) / 4); + gc_init(vm_memory.heap->ptr, vm_memory.heap->ptr + get_allocation_length(vm_memory.heap) / 4); #endif mp_init(); mp_obj_list_init((mp_obj_list_t *)mp_sys_path, 0); @@ -298,7 +296,7 @@ STATIC void count_strn(void *data, const char *str, size_t len) { *(size_t *)data += len; } -STATIC void cleanup_after_vm(stacks combo, mp_obj_t exception) { +STATIC void cleanup_after_vm(vm_memory_t vm_memory, mp_obj_t exception) { // Get the traceback of any exception from this run off the heap. // MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it" // MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback" @@ -378,9 +376,9 @@ STATIC void cleanup_after_vm(stacks combo, mp_obj_t exception) { // Free the heap last because other modules may reference heap memory and need to shut down. filesystem_flush(); stop_mp(); - free_memory(combo.heap); + free_memory(vm_memory.heap); #if MICROPY_ENABLE_PYSTACK - free_memory(combo.pystack); + free_memory(vm_memory.pystack); #endif supervisor_move_memory(); @@ -436,8 +434,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { }; #endif - stacks combo = alloc_stacks(); - start_mp(combo); + vm_memory_t vm_memory = allocate_vm_memory(); + start_mp(vm_memory); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -485,7 +483,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { // Finished executing python code. Cleanup includes filesystem flush and a board reset. - cleanup_after_vm(combo, _exec_result.exception); + cleanup_after_vm(vm_memory, _exec_result.exception); _exec_result.exception = NULL; // If a new next code file was set, that is a reason to keep it (obviously). Stuff this into @@ -781,8 +779,8 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. - stacks combo = alloc_stacks(); - start_mp(combo); + vm_memory_t vm_memory = allocate_vm_memory(); + start_mp(vm_memory); #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -868,7 +866,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { port_post_boot_py(true); - cleanup_after_vm(combo, _exec_result.exception); + cleanup_after_vm(vm_memory, _exec_result.exception); _exec_result.exception = NULL; port_post_boot_py(false); @@ -883,8 +881,8 @@ STATIC int run_repl(void) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); - stacks combo = alloc_stacks(); - start_mp(combo); + vm_memory_t vm_memory = allocate_vm_memory(); + start_mp(vm_memory); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -927,7 +925,7 @@ STATIC int run_repl(void) { exit_code = PYEXEC_DEEP_SLEEP; } #endif - cleanup_after_vm(combo, MP_OBJ_SENTINEL); + cleanup_after_vm(vm_memory, MP_OBJ_SENTINEL); // Also reset bleio. The above call omits it in case workflows should continue. In this case, // we're switching straight to another VM so we want to reset. From c920dbb81c267f2f56b64a045f49cac3a3422796 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 11:50:35 +0200 Subject: [PATCH 15/35] Skip unecessary check for space --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index dc5e015da7..82b0a54fd6 100644 --- a/main.c +++ b/main.c @@ -149,7 +149,7 @@ STATIC vm_memory_t allocate_vm_memory(void) { (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); // Check if value is valid pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. - if ((CIRCUITPY_PYSTACK_SIZE != pystack_size) && (pystack_size < 384)) { + if (pystack_size < 384) { serial_write_compressed(translate("\nWARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n\n")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset } From f6e7edc9000acf6462c119a07c5ffffd274c0dee Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 12:34:48 +0200 Subject: [PATCH 16/35] Size reductions --- locale/circuitpython.pot | 24 +++++++++++++++--------- main.c | 8 ++++++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index f44f69dfde..8e9a929db9 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -38,15 +38,7 @@ msgstr "" #: main.c msgid "" "\n" -"WARNING: Allocating pystack failed, defaulting back to build value. \n" -"\n" -msgstr "" - -#: main.c -msgid "" -"\n" -"WARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n" -"\n" +"WARNING: " msgstr "" #: py/obj.c @@ -390,6 +382,12 @@ msgstr "" msgid "*x must be assignment target" msgstr "" +#: main.c +msgid "" +", defaulting back to build value.\n" +"\n" +msgstr "" + #: py/obj.c msgid ", in %q\n" msgstr "" @@ -496,6 +494,10 @@ msgstr "" msgid "All timers in use" msgstr "" +#: main.c +msgid "Allocating pystack failed" +msgstr "" + #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c msgid "Already advertising." @@ -1244,6 +1246,10 @@ msgstr "" msgid "Invalid BSSID" msgstr "" +#: main.c +msgid "Invalid CIRCUITPY_PYSTACK_SIZE" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Invalid MAC address" msgstr "" diff --git a/main.c b/main.c index 82b0a54fd6..ad91b50434 100644 --- a/main.c +++ b/main.c @@ -150,13 +150,17 @@ STATIC vm_memory_t allocate_vm_memory(void) { // Check if value is valid pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. if (pystack_size < 384) { - serial_write_compressed(translate("\nWARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n\n")); + serial_write_compressed(translate("\nWARNING: ")); + serial_write_compressed(translate("Invalid CIRCUITPY_PYSTACK_SIZE")); + serial_write_compressed(translate(", defaulting back to build value.\n\n")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset } #endif res.pystack = allocate_memory(pystack_size, false, false); if (res.pystack == NULL) { - serial_write_compressed(translate("\nWARNING: Allocating pystack failed, defaulting back to build value. \n\n")); + serial_write_compressed(translate("\nWARNING: ")); + serial_write_compressed(translate("Allocating pystack failed")); + serial_write_compressed(translate(", defaulting back to build value.\n\n")); res.pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); } #endif From a61a9f4bde75ad981aca73191837f5b476bab757 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 13:12:21 +0200 Subject: [PATCH 17/35] Size reductions (attempts, at the very least) --- locale/circuitpython.pot | 12 +++++------- main.c | 9 ++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 8e9a929db9..ab9df4aa37 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -35,12 +35,6 @@ msgid "" "https://github.com/adafruit/circuitpython/issues\n" msgstr "" -#: main.c -msgid "" -"\n" -"WARNING: " -msgstr "" - #: py/obj.c msgid " File \"%q\"" msgstr "" @@ -2369,7 +2363,7 @@ msgid "Voltage read timed out" msgstr "" #: main.c -msgid "WARNING: Your code filename has two extensions\n" +msgid "WARNING: " msgstr "" #: ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c @@ -2430,6 +2424,10 @@ msgid "" "You pressed the reset button during boot. Press again to exit safe mode." msgstr "" +#: main.c +msgid "Your code filename has two extensions\n" +msgstr "" + #: supervisor/shared/micropython.c msgid "[truncated due to length]" msgstr "" diff --git a/main.c b/main.c index ad91b50434..d94f1501e3 100644 --- a/main.c +++ b/main.c @@ -150,7 +150,8 @@ STATIC vm_memory_t allocate_vm_memory(void) { // Check if value is valid pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. if (pystack_size < 384) { - serial_write_compressed(translate("\nWARNING: ")); + serial_write("\n"); + serial_write_compressed(translate("WARNING: ")); serial_write_compressed(translate("Invalid CIRCUITPY_PYSTACK_SIZE")); serial_write_compressed(translate(", defaulting back to build value.\n\n")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset @@ -158,7 +159,8 @@ STATIC vm_memory_t allocate_vm_memory(void) { #endif res.pystack = allocate_memory(pystack_size, false, false); if (res.pystack == NULL) { - serial_write_compressed(translate("\nWARNING: ")); + serial_write("\n"); + serial_write_compressed(translate("WARNING: ")); serial_write_compressed(translate("Allocating pystack failed")); serial_write_compressed(translate(", defaulting back to build value.\n\n")); res.pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); @@ -469,7 +471,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { if (!found_main) { found_main = maybe_run_list(double_extension_filenames, MP_ARRAY_SIZE(double_extension_filenames)); if (found_main) { - serial_write_compressed(translate("WARNING: Your code filename has two extensions\n")); + serial_write_compressed(translate("WARNING: ")); + serial_write_compressed(translate("Your code filename has two extensions\n")); } } #else From 6dc179dc4a3ec54a26f0c50bca0af2ded9cfc640 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 13:33:37 +0200 Subject: [PATCH 18/35] Removed old supervisor stack setting code and revert some 'optimisations' --- locale/circuitpython.pot | 34 ++++++++++++---------------- main.c | 13 +++-------- shared-bindings/supervisor/Runtime.c | 21 ----------------- 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index ab9df4aa37..a5906ca6e7 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -35,6 +35,20 @@ msgid "" "https://github.com/adafruit/circuitpython/issues\n" msgstr "" +#: main.c +msgid "" +"\n" +"WARNING: Allocating pystack failed, defaulting back to build value.\n" +"\n" +msgstr "" + +#: main.c +msgid "" +"\n" +"WARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n" +"\n" +msgstr "" + #: py/obj.c msgid " File \"%q\"" msgstr "" @@ -376,12 +390,6 @@ msgstr "" msgid "*x must be assignment target" msgstr "" -#: main.c -msgid "" -", defaulting back to build value.\n" -"\n" -msgstr "" - #: py/obj.c msgid ", in %q\n" msgstr "" @@ -488,10 +496,6 @@ msgstr "" msgid "All timers in use" msgstr "" -#: main.c -msgid "Allocating pystack failed" -msgstr "" - #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c msgid "Already advertising." @@ -1240,10 +1244,6 @@ msgstr "" msgid "Invalid BSSID" msgstr "" -#: main.c -msgid "Invalid CIRCUITPY_PYSTACK_SIZE" -msgstr "" - #: shared-bindings/wifi/Radio.c msgid "Invalid MAC address" msgstr "" @@ -2363,7 +2363,7 @@ msgid "Voltage read timed out" msgstr "" #: main.c -msgid "WARNING: " +msgid "WARNING: Your code filename has two extensions\n" msgstr "" #: ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c @@ -2424,10 +2424,6 @@ msgid "" "You pressed the reset button during boot. Press again to exit safe mode." msgstr "" -#: main.c -msgid "Your code filename has two extensions\n" -msgstr "" - #: supervisor/shared/micropython.c msgid "[truncated due to length]" msgstr "" diff --git a/main.c b/main.c index d94f1501e3..09f507867f 100644 --- a/main.c +++ b/main.c @@ -150,19 +150,13 @@ STATIC vm_memory_t allocate_vm_memory(void) { // Check if value is valid pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. if (pystack_size < 384) { - serial_write("\n"); - serial_write_compressed(translate("WARNING: ")); - serial_write_compressed(translate("Invalid CIRCUITPY_PYSTACK_SIZE")); - serial_write_compressed(translate(", defaulting back to build value.\n\n")); + serial_write_compressed(translate("\nWARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n\n")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset } #endif res.pystack = allocate_memory(pystack_size, false, false); if (res.pystack == NULL) { - serial_write("\n"); - serial_write_compressed(translate("WARNING: ")); - serial_write_compressed(translate("Allocating pystack failed")); - serial_write_compressed(translate(", defaulting back to build value.\n\n")); + serial_write_compressed(translate("\nWARNING: Allocating pystack failed, defaulting back to build value.\n\n")); res.pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); } #endif @@ -471,8 +465,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { if (!found_main) { found_main = maybe_run_list(double_extension_filenames, MP_ARRAY_SIZE(double_extension_filenames)); if (found_main) { - serial_write_compressed(translate("WARNING: ")); - serial_write_compressed(translate("Your code filename has two extensions\n")); + serial_write_compressed(translate("WARNING: Your code filename has two extensions\n")); } } #else diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 4d8ddbacc7..d250ae89c0 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -168,26 +168,6 @@ MP_PROPERTY_GETSET(supervisor_runtime_ble_workflow_obj, (mp_obj_t)&supervisor_runtime_get_ble_workflow_obj, (mp_obj_t)&supervisor_runtime_set_ble_workflow_obj); -//| next_stack_limit: int -//| """The size of the stack for the next vm run. If its too large, the default will be used.""" -//| -STATIC mp_obj_t supervisor_runtime_get_next_stack_limit(mp_obj_t self) { - return mp_obj_new_int(get_next_stack_size()); -} -MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_next_stack_limit_obj, supervisor_runtime_get_next_stack_limit); - -STATIC mp_obj_t supervisor_runtime_set_next_stack_limit(mp_obj_t self, mp_obj_t size_obj) { - mp_int_t size = mp_obj_get_int(size_obj); - mp_arg_validate_int_min(size, 256, MP_QSTR_size); - set_next_stack_size(size); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_next_stack_limit_obj, supervisor_runtime_set_next_stack_limit); - -MP_PROPERTY_GETSET(supervisor_runtime_next_stack_limit_obj, - (mp_obj_t)&supervisor_runtime_get_next_stack_limit_obj, - (mp_obj_t)&supervisor_runtime_set_next_stack_limit_obj); - //| rgb_status_brightness: int //| """Set brightness of status RGB LED from 0-255. This will take effect //| after the current code finishes and the status LED is used to show @@ -220,7 +200,6 @@ STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_run_reason), MP_ROM_PTR(&supervisor_runtime_run_reason_obj) }, { MP_ROM_QSTR(MP_QSTR_autoreload), MP_ROM_PTR(&supervisor_runtime_autoreload_obj) }, { MP_ROM_QSTR(MP_QSTR_ble_workflow), MP_ROM_PTR(&supervisor_runtime_ble_workflow_obj) }, - { MP_ROM_QSTR(MP_QSTR_next_stack_limit), MP_ROM_PTR(&supervisor_runtime_next_stack_limit_obj) }, { MP_ROM_QSTR(MP_QSTR_rgb_status_brightness), MP_ROM_PTR(&supervisor_runtime_rgb_status_brightness_obj) }, }; From 54ae7ced827089694f1a94ac551daf425b39b77c Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 23:10:11 +0200 Subject: [PATCH 19/35] Updated to requested changes --- locale/circuitpython.pot | 22 +++++------- main.c | 77 ++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index a5906ca6e7..79899735de 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -28,6 +28,14 @@ msgid "" "Code stopped by auto-reload. Reloading soon.\n" msgstr "" +#: main.c +msgid "" +"\n" +"Invalid CIRCUITPY_PYSTACK_SIZE\n" +"\n" +"\r" +msgstr "" + #: supervisor/shared/safe_mode.c msgid "" "\n" @@ -35,20 +43,6 @@ msgid "" "https://github.com/adafruit/circuitpython/issues\n" msgstr "" -#: main.c -msgid "" -"\n" -"WARNING: Allocating pystack failed, defaulting back to build value.\n" -"\n" -msgstr "" - -#: main.c -msgid "" -"\n" -"WARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n" -"\n" -msgstr "" - #: py/obj.c msgid " File \"%q\"" msgstr "" diff --git a/main.c b/main.c index 09f507867f..1d67424e28 100644 --- a/main.c +++ b/main.c @@ -126,45 +126,36 @@ uint8_t value_out = 0; #include "shared-module/os/__init__.h" #endif -typedef struct { - #if MICROPY_ENABLE_PYSTACK - supervisor_allocation *pystack; - #endif - supervisor_allocation *heap; -} vm_memory_t; - static void reset_devices(void) { #if CIRCUITPY_BLEIO_HCI bleio_reset(); #endif } -STATIC vm_memory_t allocate_vm_memory(void) { - vm_memory_t res; - #if MICROPY_ENABLE_PYSTACK +#if MICROPY_ENABLE_PYSTACK +STATIC supervisor_allocation *allocate_pystack(void) { mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; - #if CIRCUITPY_OS_GETENV + #if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK // Fetch value if exists from settings.toml // Leaves size to build default on any failure (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); // Check if value is valid pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. if (pystack_size < 384) { - serial_write_compressed(translate("\nWARNING: Invalid CIRCUITPY_PYSTACK_SIZE, defaulting back to build value.\n\n")); + serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset } #endif - res.pystack = allocate_memory(pystack_size, false, false); - if (res.pystack == NULL) { - serial_write_compressed(translate("\nWARNING: Allocating pystack failed, defaulting back to build value.\n\n")); - res.pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); + supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); + if (pystack == NULL) { + serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r")); + pystack = allocate_memory(CIRCUITPY_PYSTACK_SIZE, false, false); } - #endif - res.heap = allocate_remaining_memory(); - return res; + return pystack; } +#endif -STATIC void start_mp(vm_memory_t vm_memory) { +STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack) { supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance @@ -192,11 +183,11 @@ STATIC void start_mp(vm_memory_t vm_memory) { readline_init0(); #if MICROPY_ENABLE_PYSTACK - mp_pystack_init(vm_memory.pystack->ptr, vm_memory.pystack->ptr + get_allocation_length(vm_memory.pystack) / sizeof(size_t)); + mp_pystack_init(pystack->ptr, pystack->ptr + get_allocation_length(pystack) / sizeof(size_t)); #endif #if MICROPY_ENABLE_GC - gc_init(vm_memory.heap->ptr, vm_memory.heap->ptr + get_allocation_length(vm_memory.heap) / 4); + gc_init(heap->ptr, heap->ptr + get_allocation_length(heap) / 4); #endif mp_init(); mp_obj_list_init((mp_obj_list_t *)mp_sys_path, 0); @@ -296,7 +287,7 @@ STATIC void count_strn(void *data, const char *str, size_t len) { *(size_t *)data += len; } -STATIC void cleanup_after_vm(vm_memory_t vm_memory, mp_obj_t exception) { +STATIC void cleanup_after_vm(supervisor_allocation *heap, supervisor_allocation *pystack, mp_obj_t exception) { // Get the traceback of any exception from this run off the heap. // MP_OBJ_SENTINEL means "this run does not contribute to traceback storage, don't touch it" // MP_OBJ_NULL (=0) means "this run completed successfully, clear any stored traceback" @@ -376,9 +367,9 @@ STATIC void cleanup_after_vm(vm_memory_t vm_memory, mp_obj_t exception) { // Free the heap last because other modules may reference heap memory and need to shut down. filesystem_flush(); stop_mp(); - free_memory(vm_memory.heap); + free_memory(heap); #if MICROPY_ENABLE_PYSTACK - free_memory(vm_memory.pystack); + free_memory(pystack); #endif supervisor_move_memory(); @@ -434,8 +425,14 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { }; #endif - vm_memory_t vm_memory = allocate_vm_memory(); - start_mp(vm_memory); + supervisor_allocation *pystack; + #if MICROPY_ENABLE_PYSTACK + pystack = allocate_pystack(); + #else + pystack = NULL; + #endif + supervisor_allocation *heap = allocate_remaining_memory(); + start_mp(heap, pystack); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -483,7 +480,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { // Finished executing python code. Cleanup includes filesystem flush and a board reset. - cleanup_after_vm(vm_memory, _exec_result.exception); + cleanup_after_vm(heap, pystack, _exec_result.exception); _exec_result.exception = NULL; // If a new next code file was set, that is a reason to keep it (obviously). Stuff this into @@ -779,8 +776,14 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. - vm_memory_t vm_memory = allocate_vm_memory(); - start_mp(vm_memory); + supervisor_allocation *pystack; + #if MICROPY_ENABLE_PYSTACK + pystack = allocate_pystack(); + #else + pystack = NULL; + #endif + supervisor_allocation *heap = allocate_remaining_memory(); + start_mp(heap, pystack); #if CIRCUITPY_USB // Set up default USB values after boot.py VM starts but before running boot.py. @@ -866,7 +869,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { port_post_boot_py(true); - cleanup_after_vm(vm_memory, _exec_result.exception); + cleanup_after_vm(heap, pystack, _exec_result.exception); _exec_result.exception = NULL; port_post_boot_py(false); @@ -881,8 +884,14 @@ STATIC int run_repl(void) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); - vm_memory_t vm_memory = allocate_vm_memory(); - start_mp(vm_memory); + supervisor_allocation *pystack; + #if MICROPY_ENABLE_PYSTACK + pystack = allocate_pystack(); + #else + pystack = NULL; + #endif + supervisor_allocation *heap = allocate_remaining_memory(); + start_mp(heap, pystack); #if CIRCUITPY_USB usb_setup_with_vm(); @@ -925,7 +934,7 @@ STATIC int run_repl(void) { exit_code = PYEXEC_DEEP_SLEEP; } #endif - cleanup_after_vm(vm_memory, MP_OBJ_SENTINEL); + cleanup_after_vm(heap, pystack, MP_OBJ_SENTINEL); // Also reset bleio. The above call omits it in case workflows should continue. In this case, // we're switching straight to another VM so we want to reset. From a37dad61fb3d72e5ab2ad993baac2494d4438c12 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 23:10:30 +0200 Subject: [PATCH 20/35] CIRCUITPY_SETTABLE_PYSTACK --- py/circuitpy_mpconfig.h | 1 + 1 file changed, 1 insertion(+) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 8bfb69297a..95a95fa12f 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -145,6 +145,7 @@ extern void common_hal_mcu_enable_interrupts(void); #define MICROPY_REPL_AUTO_INDENT (1) #define MICROPY_REPL_EVENT_DRIVEN (0) #define MICROPY_ENABLE_PYSTACK (1) +#define CIRCUITPY_SETTABLE_PYSTACK (1) #define MICROPY_STACK_CHECK (1) #define MICROPY_STREAMS_NON_BLOCK (1) #ifndef MICROPY_USE_INTERNAL_PRINTF From 4bb0b0acdfc7f2a67d8312c11fe19c253c6d9297 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 23:37:37 +0200 Subject: [PATCH 21/35] volatile to skip optimisation --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 1d67424e28..4a1201f56c 100644 --- a/main.c +++ b/main.c @@ -776,7 +776,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. - supervisor_allocation *pystack; + volatile supervisor_allocation *pystack; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); #else From c003b8817a8243968b166e8a6c7fca05fa8f81cb Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 23:40:49 +0200 Subject: [PATCH 22/35] Put on all and preinit with NULL --- main.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index 4a1201f56c..2f3f9bc969 100644 --- a/main.c +++ b/main.c @@ -425,11 +425,9 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { }; #endif - supervisor_allocation *pystack; + volatile supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); - #else - pystack = NULL; #endif supervisor_allocation *heap = allocate_remaining_memory(); start_mp(heap, pystack); @@ -776,11 +774,9 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. - volatile supervisor_allocation *pystack; + volatile supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); - #else - pystack = NULL; #endif supervisor_allocation *heap = allocate_remaining_memory(); start_mp(heap, pystack); @@ -884,11 +880,9 @@ STATIC int run_repl(void) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); - supervisor_allocation *pystack; + volatile supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); - #else - pystack = NULL; #endif supervisor_allocation *heap = allocate_remaining_memory(); start_mp(heap, pystack); From 66215f7983b05ebe7e9018495e02100af8908a55 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Thu, 16 Feb 2023 23:57:47 +0200 Subject: [PATCH 23/35] gcc is evil, I respond with fake pointer --- main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 2f3f9bc969..1a622a9858 100644 --- a/main.c +++ b/main.c @@ -425,7 +425,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { }; #endif - volatile supervisor_allocation *pystack = NULL; + supervisor_allocation *pystack = (supervisor_allocation *)1; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); #endif @@ -774,7 +774,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. - volatile supervisor_allocation *pystack = NULL; + supervisor_allocation *pystack = (supervisor_allocation *)1; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); #endif @@ -880,7 +880,7 @@ STATIC int run_repl(void) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); - volatile supervisor_allocation *pystack = NULL; + supervisor_allocation *pystack = (supervisor_allocation *)1; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); #endif From 8abce77971c47297526437bec5260ba7e005beb7 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 17 Feb 2023 00:52:13 +0200 Subject: [PATCH 24/35] fix safemode --- main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index aa58dcf45f..19ef60f2e1 100644 --- a/main.c +++ b/main.c @@ -425,7 +425,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { }; #endif - supervisor_allocation *pystack = (supervisor_allocation *)1; + supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); #endif @@ -767,8 +767,12 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) { return; } + supervisor_allocation *pystack = NULL; + #if MICROPY_ENABLE_PYSTACK + pystack = allocate_pystack(); + #endif supervisor_allocation *heap = allocate_remaining_memory(); - start_mp(heap); + start_mp(heap, pystack); static const char *const safemode_py_filenames[] = {"safemode.py", "safemode.txt"}; maybe_run_list(safemode_py_filenames, MP_ARRAY_SIZE(safemode_py_filenames)); @@ -779,7 +783,7 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) { set_safe_mode(SAFE_MODE_SAFEMODE_PY_ERROR); } - cleanup_after_vm(heap, _exec_result.exception); + cleanup_after_vm(heap, pystack, _exec_result.exception); _exec_result.exception = NULL; } #endif @@ -800,7 +804,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { // Do USB setup even if boot.py is not run. - supervisor_allocation *pystack = (supervisor_allocation *)1; + supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); #endif @@ -906,7 +910,7 @@ STATIC int run_repl(void) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); - supervisor_allocation *pystack = (supervisor_allocation *)1; + supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK pystack = allocate_pystack(); #endif From f05c730a01b55b779547e80bea79ac0d54a1cfec Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 17 Feb 2023 15:14:09 +0200 Subject: [PATCH 25/35] settable pystack = 0 for kicksat-sprite --- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h index eb7f1c62e3..7bcff4ad73 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h @@ -21,3 +21,8 @@ #define IGNORE_PIN_PA25 1 #define MICROPY_FATFS_EXFAT 0 + +#ifdef CIRCUITPY_SETTABLE_PYSTACK +#undef CIRCUITPY_SETTABLE_PYSTACK +#endif +#define CIRCUITPY_SETTABLE_PYSTACK (0) From 17e2598fa1b9f9bec2b1cd6df566f44e9e40145c Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 17 Feb 2023 15:23:01 +0200 Subject: [PATCH 26/35] Revert "settable pystack = 0 for kicksat-sprite" This reverts commit f05c730a01b55b779547e80bea79ac0d54a1cfec. --- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h index 7bcff4ad73..eb7f1c62e3 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h @@ -21,8 +21,3 @@ #define IGNORE_PIN_PA25 1 #define MICROPY_FATFS_EXFAT 0 - -#ifdef CIRCUITPY_SETTABLE_PYSTACK -#undef CIRCUITPY_SETTABLE_PYSTACK -#endif -#define CIRCUITPY_SETTABLE_PYSTACK (0) From 388279d9c15332f247ce92eeda0c303bb503f529 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 17 Feb 2023 15:24:27 +0200 Subject: [PATCH 27/35] Disable rainbowio instead. --- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk index 9bc50ab429..51b4371675 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk @@ -25,6 +25,7 @@ CIRCUITPY_KEYPAD = 0 CIRCUITPY_MSGPACK = 0 CIRCUITPY_PS2IO = 0 CIRCUITPY_RGBMATRIX = 0 +CIRCUITPY_RAINBOWIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_USB_HID = 0 From 8a4a408707256a563764afd050be992594178b99 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 17 Feb 2023 16:35:16 +0200 Subject: [PATCH 28/35] Disable settable-pystack too to make more space --- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h index eb7f1c62e3..bdc3fc5890 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h @@ -21,3 +21,8 @@ #define IGNORE_PIN_PA25 1 #define MICROPY_FATFS_EXFAT 0 + +#ifdef CIRCUITPY_SETTABLE_PYSTACK +#undef CIRCUITPY_SETTABLE_PYSTACK +#endif +#define CIRCUITPY_SETTABLE_PYSTACK 0 From d7e6a78ef447d592feb37486a644de8fce1089b2 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 17 Feb 2023 17:40:55 +0200 Subject: [PATCH 29/35] safemode prevent dynamic stack alloc --- main.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index 19ef60f2e1..5889ae5a67 100644 --- a/main.c +++ b/main.c @@ -133,17 +133,19 @@ static void reset_devices(void) { } #if MICROPY_ENABLE_PYSTACK -STATIC supervisor_allocation *allocate_pystack(void) { +STATIC supervisor_allocation *allocate_pystack(safe_mode_t safe_mode) { mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE; #if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK // Fetch value if exists from settings.toml // Leaves size to build default on any failure - (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); - // Check if value is valid - pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. - if (pystack_size < 384) { - serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r")); - pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset + if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER) { + (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); + // Check if value is valid + pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. + if (pystack_size < 384) { + serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r")); + pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset + } } #endif supervisor_allocation *pystack = allocate_memory(pystack_size, false, false); @@ -427,7 +429,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK - pystack = allocate_pystack(); + pystack = allocate_pystack(safe_mode); #endif supervisor_allocation *heap = allocate_remaining_memory(); start_mp(heap, pystack); @@ -769,7 +771,7 @@ STATIC void __attribute__ ((noinline)) run_safemode_py(safe_mode_t safe_mode) { supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK - pystack = allocate_pystack(); + pystack = allocate_pystack(safe_mode); #endif supervisor_allocation *heap = allocate_remaining_memory(); start_mp(heap, pystack); @@ -806,7 +808,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK - pystack = allocate_pystack(); + pystack = allocate_pystack(safe_mode); #endif supervisor_allocation *heap = allocate_remaining_memory(); start_mp(heap, pystack); @@ -906,13 +908,13 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { #endif } -STATIC int run_repl(void) { +STATIC int run_repl(safe_mode_t safe_mode) { int exit_code = PYEXEC_FORCED_EXIT; stack_resize(); filesystem_flush(); supervisor_allocation *pystack = NULL; #if MICROPY_ENABLE_PYSTACK - pystack = allocate_pystack(); + pystack = allocate_pystack(safe_mode); #endif supervisor_allocation *heap = allocate_remaining_memory(); start_mp(heap, pystack); @@ -1078,7 +1080,7 @@ int __attribute__((used)) main(void) { bool simulate_reset = true; for (;;) { if (!skip_repl) { - exit_code = run_repl(); + exit_code = run_repl(get_safe_mode()); supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); } if (exit_code == PYEXEC_FORCED_EXIT) { From b4ff08d185389e5b540a8e468c00895e1ae83927 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Sat, 18 Feb 2023 23:56:06 +0200 Subject: [PATCH 30/35] Prohibit too big a size --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 5889ae5a67..18f145c334 100644 --- a/main.c +++ b/main.c @@ -142,7 +142,7 @@ STATIC supervisor_allocation *allocate_pystack(safe_mode_t safe_mode) { (void)common_hal_os_getenv_int("CIRCUITPY_PYSTACK_SIZE", &pystack_size); // Check if value is valid pystack_size = pystack_size - pystack_size % sizeof(size_t); // Round down to multiple of 4. - if (pystack_size < 384) { + if ((pystack_size < 384) || (pystack_size > 900000)) { serial_write_compressed(translate("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r")); pystack_size = CIRCUITPY_PYSTACK_SIZE; // Reset } From 30a8e8bbcdba454b0af3c4acbe1cd6401fc92aa4 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Tue, 21 Feb 2023 13:26:57 +0200 Subject: [PATCH 31/35] Revert next_stack_size --- shared-bindings/supervisor/Runtime.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 4d94172205..c3418c6437 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -168,6 +168,26 @@ STATIC mp_obj_t supervisor_runtime_get_ble_workflow(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_ble_workflow_obj, supervisor_runtime_get_ble_workflow); +//| next_stack_limit: int +//| """The size of the stack for the next vm run. If its too large, the default will be used.""" +//| +STATIC mp_obj_t supervisor_runtime_get_next_stack_limit(mp_obj_t self) { + return mp_obj_new_int(get_next_stack_size()); +} +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_next_stack_limit_obj, supervisor_runtime_get_next_stack_limit); + +STATIC mp_obj_t supervisor_runtime_set_next_stack_limit(mp_obj_t self, mp_obj_t size_obj) { + mp_int_t size = mp_obj_get_int(size_obj); + mp_arg_validate_int_min(size, 256, MP_QSTR_size); + set_next_stack_size(size); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_next_stack_limit_obj, supervisor_runtime_set_next_stack_limit); + +MP_PROPERTY_GETSET(supervisor_runtime_next_stack_limit_obj, + (mp_obj_t)&supervisor_runtime_get_next_stack_limit_obj, + (mp_obj_t)&supervisor_runtime_set_next_stack_limit_obj); + STATIC mp_obj_t supervisor_runtime_set_ble_workflow(mp_obj_t self, mp_obj_t state_in) { #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE if (mp_obj_is_true(state_in)) { @@ -219,6 +239,7 @@ STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_safe_mode_reason), MP_ROM_PTR(&supervisor_runtime_safe_mode_reason_obj) }, { MP_ROM_QSTR(MP_QSTR_autoreload), MP_ROM_PTR(&supervisor_runtime_autoreload_obj) }, { MP_ROM_QSTR(MP_QSTR_ble_workflow), MP_ROM_PTR(&supervisor_runtime_ble_workflow_obj) }, + { MP_ROM_QSTR(MP_QSTR_next_stack_limit), MP_ROM_PTR(&supervisor_runtime_next_stack_limit_obj) }, { MP_ROM_QSTR(MP_QSTR_rgb_status_brightness), MP_ROM_PTR(&supervisor_runtime_rgb_status_brightness_obj) }, }; From d42aa41c70635c877c014fb6bfc2b654ede72bbd Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Tue, 21 Feb 2023 13:29:39 +0200 Subject: [PATCH 32/35] Revert it with more passion --- shared-bindings/supervisor/Runtime.c | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index c3418c6437..db3d8d1e4d 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -168,6 +168,24 @@ STATIC mp_obj_t supervisor_runtime_get_ble_workflow(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_ble_workflow_obj, supervisor_runtime_get_ble_workflow); +STATIC mp_obj_t supervisor_runtime_set_ble_workflow(mp_obj_t self, mp_obj_t state_in) { + #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE + if (mp_obj_is_true(state_in)) { + supervisor_bluetooth_enable_workflow(); + } else { + supervisor_bluetooth_disable_workflow(); + } + #else + mp_raise_NotImplementedError(NULL); + #endif + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_ble_workflow_obj, supervisor_runtime_set_ble_workflow); + +MP_PROPERTY_GETSET(supervisor_runtime_ble_workflow_obj, + (mp_obj_t)&supervisor_runtime_get_ble_workflow_obj, + (mp_obj_t)&supervisor_runtime_set_ble_workflow_obj); + //| next_stack_limit: int //| """The size of the stack for the next vm run. If its too large, the default will be used.""" //| @@ -188,24 +206,6 @@ MP_PROPERTY_GETSET(supervisor_runtime_next_stack_limit_obj, (mp_obj_t)&supervisor_runtime_get_next_stack_limit_obj, (mp_obj_t)&supervisor_runtime_set_next_stack_limit_obj); -STATIC mp_obj_t supervisor_runtime_set_ble_workflow(mp_obj_t self, mp_obj_t state_in) { - #if CIRCUITPY_BLE_FILE_SERVICE && CIRCUITPY_SERIAL_BLE - if (mp_obj_is_true(state_in)) { - supervisor_bluetooth_enable_workflow(); - } else { - supervisor_bluetooth_disable_workflow(); - } - #else - mp_raise_NotImplementedError(NULL); - #endif - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_2(supervisor_runtime_set_ble_workflow_obj, supervisor_runtime_set_ble_workflow); - -MP_PROPERTY_GETSET(supervisor_runtime_ble_workflow_obj, - (mp_obj_t)&supervisor_runtime_get_ble_workflow_obj, - (mp_obj_t)&supervisor_runtime_set_ble_workflow_obj); - //| rgb_status_brightness: int //| """Set brightness of status RGB LED from 0-255. This will take effect //| after the current code finishes and the status LED is used to show @@ -239,7 +239,7 @@ STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_safe_mode_reason), MP_ROM_PTR(&supervisor_runtime_safe_mode_reason_obj) }, { MP_ROM_QSTR(MP_QSTR_autoreload), MP_ROM_PTR(&supervisor_runtime_autoreload_obj) }, { MP_ROM_QSTR(MP_QSTR_ble_workflow), MP_ROM_PTR(&supervisor_runtime_ble_workflow_obj) }, - { MP_ROM_QSTR(MP_QSTR_next_stack_limit), MP_ROM_PTR(&supervisor_runtime_next_stack_limit_obj) }, + { MP_ROM_QSTR(MP_QSTR_next_stack_limit), MP_ROM_PTR(&supervisor_runtime_next_stack_limit_obj) }, { MP_ROM_QSTR(MP_QSTR_rgb_status_brightness), MP_ROM_PTR(&supervisor_runtime_rgb_status_brightness_obj) }, }; From 5dba32ed073f3cb00e961335ee7aaa1d74a9eaa8 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Tue, 21 Feb 2023 17:42:08 +0200 Subject: [PATCH 33/35] Try to pass ci with rainbowio --- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk index 51b4371675..9bc50ab429 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk @@ -25,7 +25,6 @@ CIRCUITPY_KEYPAD = 0 CIRCUITPY_MSGPACK = 0 CIRCUITPY_PS2IO = 0 CIRCUITPY_RGBMATRIX = 0 -CIRCUITPY_RAINBOWIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_USB_HID = 0 From 650c4c5d92f9f15ea1b29422caab323780b3a2a2 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Tue, 21 Feb 2023 20:50:07 +0200 Subject: [PATCH 34/35] pystack+ rainbow- --- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h | 5 ----- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h index bdc3fc5890..eb7f1c62e3 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.h @@ -21,8 +21,3 @@ #define IGNORE_PIN_PA25 1 #define MICROPY_FATFS_EXFAT 0 - -#ifdef CIRCUITPY_SETTABLE_PYSTACK -#undef CIRCUITPY_SETTABLE_PYSTACK -#endif -#define CIRCUITPY_SETTABLE_PYSTACK 0 diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk index 9bc50ab429..51b4371675 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk @@ -25,6 +25,7 @@ CIRCUITPY_KEYPAD = 0 CIRCUITPY_MSGPACK = 0 CIRCUITPY_PS2IO = 0 CIRCUITPY_RGBMATRIX = 0 +CIRCUITPY_RAINBOWIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_USB_HID = 0 From 1d12014ec76fda494b777aae29de0d1ee5762046 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Wed, 22 Feb 2023 13:31:15 +0200 Subject: [PATCH 35/35] disable pixelmap --- ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk index 51b4371675..9ca9259747 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk @@ -20,6 +20,7 @@ CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FLOPPYIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 +CIRCUITPY_PIXELMAP = 0 CIRCUITPY_GETPASS = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_MSGPACK = 0