From c20cfb10e0a898b9e411d7cd67a64460e4558446 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 12 May 2021 21:10:06 -0700 Subject: [PATCH 1/4] esp32: Pin MicroPython to core 1 again. This follows up on #5489, where we changed the esp32 core pinning to core 0 in order to work around an issue with IDF < 4.2.0. Now that IDF > 4.2.0 is available, we allow pinning back to core 1, which eliminates some problematic callback latency with wifi enabled. --- ports/esp32/mphalport.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ports/esp32/mphalport.h b/ports/esp32/mphalport.h index 60cc308d68275..6df39f4da0c2c 100644 --- a/ports/esp32/mphalport.h +++ b/ports/esp32/mphalport.h @@ -36,10 +36,15 @@ #include "freertos/task.h" // The core that the MicroPython task(s) are pinned to. -// Until we move to IDF 4.2+, we need NimBLE on core 0, and for synchronisation -// with the ringbuffer and scheduler MP needs to be on the same core. -// See https://github.com/micropython/micropython/issues/5489 +// Now that we have IDF 4.2.0+, we are once again able to pin to core 1 +// and avoid the Wifi/BLE timing problems on the same core. +// Best effort here to remain backwards compatible in rare version edge cases... +// See https://github.com/micropython/micropython/issues/5489 for history +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) +#define MP_TASK_COREID (1) +#else #define MP_TASK_COREID (0) +#endif extern TaskHandle_t mp_main_task_handle; From 4d7921db0c63ddfc5a548011b5d0f842c06afa8f Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 13 May 2021 20:57:56 -0700 Subject: [PATCH 2/4] esp32/boards: Pin NimBLE to core 1 if IDF > 4.2. This ensures that NimBLE is on the same core as Micropython, even in IDF versions above 4.2. --- ports/esp32/boards/sdkconfig.ble | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ports/esp32/boards/sdkconfig.ble b/ports/esp32/boards/sdkconfig.ble index 5565fd81a8432..c24428941c2c2 100644 --- a/ports/esp32/boards/sdkconfig.ble +++ b/ports/esp32/boards/sdkconfig.ble @@ -9,9 +9,15 @@ CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4 # Pin to the same core as MP. -# Until we move to IDF 4.2+, we need NimBLE on core 0, and for synchronisation -# with the ringbuffer and scheduler MP needs to be on the same core. -# See https://github.com/micropython/micropython/issues/5489 +# Prior to IDF 4.2+, we needed to pin NimBLE to core 0 for +# synchronization with the ringbuffer. This +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) +CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=n +CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y +CONFIG_BT_NIMBLE_PINNED_TO_CORE=1 +#else CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n CONFIG_BT_NIMBLE_PINNED_TO_CORE=0 +#endif + From 9fd0b177d9af8780487c985f5790bcfe66f22a74 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 13 May 2021 22:20:57 -0700 Subject: [PATCH 3/4] esp32/boards: Fix/undo misunderstood macros Whoops, probably should not have expected c macros to work in kconfig files. This undoes that and just plain pins to core 1. --- ports/esp32/boards/sdkconfig.ble | 8 -------- 1 file changed, 8 deletions(-) diff --git a/ports/esp32/boards/sdkconfig.ble b/ports/esp32/boards/sdkconfig.ble index c24428941c2c2..535cc68db55a8 100644 --- a/ports/esp32/boards/sdkconfig.ble +++ b/ports/esp32/boards/sdkconfig.ble @@ -9,15 +9,7 @@ CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4 # Pin to the same core as MP. -# Prior to IDF 4.2+, we needed to pin NimBLE to core 0 for -# synchronization with the ringbuffer. This -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=n CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y CONFIG_BT_NIMBLE_PINNED_TO_CORE=1 -#else -CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y -CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n -CONFIG_BT_NIMBLE_PINNED_TO_CORE=0 -#endif From bbee9c420f4b053f7cff92be0b3c17c168d2d1a2 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 14 May 2021 20:16:08 -0700 Subject: [PATCH 4/4] revert to leave BLE on core 0 (and wait for #7046) --- ports/esp32/boards/sdkconfig.ble | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ports/esp32/boards/sdkconfig.ble b/ports/esp32/boards/sdkconfig.ble index 535cc68db55a8..6369f5ebf147b 100644 --- a/ports/esp32/boards/sdkconfig.ble +++ b/ports/esp32/boards/sdkconfig.ble @@ -8,8 +8,9 @@ CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4 -# Pin to the same core as MP. -CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=n -CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y -CONFIG_BT_NIMBLE_PINNED_TO_CORE=1 - +# Until we move to IDF 4.2+, we need NimBLE on core 0, and for synchronisation +# with the ringbuffer and scheduler MP needs to be on the same core. +# See https://github.com/micropython/micropython/issues/5489 +CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y +CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n +CONFIG_BT_NIMBLE_PINNED_TO_CORE=0