summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-11-10 10:56:12 -0800
committerGitHub <noreply@github.com>2020-11-10 10:56:12 -0800
commit75a977febd27fc69f2c2dc3c017e765d215be633 (patch)
treee7468a60a474d7e899f58be9e80a068b87d35d03
parentfd43c0a9fe87aac543d196e48c8d9e7446868652 (diff)
parent2d8ebfcf633a0e744e49fe14cc0025d8d7d348fc (diff)
Merge pull request #3668 from jepler/esp32s2-stack-size
esp32s2: Correct port_stack_get_top()
-rw-r--r--ports/esp32s2/supervisor/port.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c
index 0b9c03f74..a25bcce00 100644
--- a/ports/esp32s2/supervisor/port.c
+++ b/ports/esp32s2/supervisor/port.c
@@ -148,7 +148,18 @@ uint32_t *port_stack_get_limit(void) {
}
uint32_t *port_stack_get_top(void) {
- return port_stack_get_limit() + CONFIG_ESP_MAIN_TASK_STACK_SIZE / (sizeof(uint32_t) / sizeof(StackType_t));
+ // The sizeof-arithmetic is so that the pointer arithmetic is done on units
+ // of uint32_t instead of units of StackType_t. StackType_t is an alias
+ // for a byte sized type.
+ //
+ // The main stack is bigger than CONFIG_ESP_MAIN_TASK_STACK_SIZE -- an
+ // "extra" size is added to it (TASK_EXTRA_STACK_SIZE). This total size is
+ // available as ESP_TASK_MAIN_STACK. Presumably TASK_EXTRA_STACK_SIZE is
+ // additional stack that can be used by the esp-idf runtime. But what's
+ // important for us is that some very outermost stack frames, such as
+ // pyexec_friendly_repl, could lie inside the "extra" area and be invisible
+ // to the garbage collector.
+ return port_stack_get_limit() + ESP_TASK_MAIN_STACK / (sizeof(uint32_t) / sizeof(StackType_t));
}
supervisor_allocation _fixed_stack;