8000 esp32: Fix Python cstack size for bluetooth irq callbacks. · mzdaniel/micropython@6565b3c · GitHub
[go: up one dir, main page]

Skip to content

Commit 6565b3c

Browse files
projectgusdpgeorge
authored andcommitted
esp32: Fix Python cstack size for bluetooth irq callbacks.
This value should have been adjusted when the new cstack API was adopted in e3955f4, as otherwise the stack limit is too small especially on ESP32-C3 where the stack limit was 6144 - 2048 - 2048. Some extra margin is needed for bluetooth irq because invoke_irq_handler() isn't a top-level task function, NimBLE calls through multiple layers first. Measuring this overhead on IDF V5.2.2 (by putting an abort() in invoke_irq_handler() and then measuring the stack size) yielded 672 bytes on ESP32-S3 and 612 bytes on ESP32-C3, similar to the size reported in cd66aa0. Sticking with 1024 bytes for added safety margin. This means on Xtensa the total margin for the BLE task stays the same (2048 bytes) as before switching to cstack. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent 0b75e18 commit 6565b3c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

ports/esp32/mpconfigport.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@
101101
#define MICROPY_PY_BLUETOOTH (1)
102102
#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS (1)
103103
#define MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS_WITH_INTERLOCK (1)
104-
#define MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE (CONFIG_BT_NIMBLE_TASK_STACK_SIZE - 2048)
104+
// Event stack size is the RTOS stack size minus an allowance for the stack used
105+
// by the NimBLE functions that call into invoke_irq_handler().
106+
// MICROPY_STACK_CHECK_MARGIN is further subtracted from this value to set the stack limit.
107+
#define MICROPY_PY_BLUETOOTH_SYNC_EVENT_STACK_SIZE (CONFIG_BT_NIMBLE_TASK_STACK_SIZE - 1024)
105108
#define MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE (1)
106109
#define MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING (1)
107110
#define MICROPY_BLUETOOTH_NIMBLE (1)

0 commit comments

Comments
 (0)
0