summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@noisybox.net>2021-05-12 21:10:06 -0700
committerDamien George <damien@micropython.org>2022-01-22 00:10:16 +1100
commit357078504d0d2c3a3f06ec4bd69e0ab3bcf9e016 (patch)
treec6a371256a58894c35c7dd5c3ec6a20845316894
parent63438a31bb6d0c8012e338433df95700f1cbca97 (diff)
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. NimBLE is also pinned to core 1 - the same core as MicroPython - when using IDF >=4.2.
-rw-r--r--ports/esp32/CMakeLists.txt13
-rw-r--r--ports/esp32/boards/sdkconfig.ble8
-rw-r--r--ports/esp32/boards/sdkconfig.nimble_core06
-rw-r--r--ports/esp32/boards/sdkconfig.nimble_core16
-rw-r--r--ports/esp32/mphalport.h11
5 files changed, 31 insertions, 13 deletions
diff --git a/ports/esp32/CMakeLists.txt b/ports/esp32/CMakeLists.txt
index 29409adc7..8b2f09a72 100644
--- a/ports/esp32/CMakeLists.txt
+++ b/ports/esp32/CMakeLists.txt
@@ -18,12 +18,22 @@ if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}")
endif()
+# Include main IDF cmake file.
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+
# Define the output sdkconfig so it goes in the build directory.
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
# Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options).
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
+# Add sdkconfig fragments that depend on the IDF version.
+if(IDF_VERSION_MAJOR EQUAL 4 AND IDF_VERSION_MINOR LESS 2)
+ set(SDKCONFIG_DEFAULTS ${SDKCONFIG_DEFAULTS} boards/sdkconfig.nimble_core0)
+else()
+ set(SDKCONFIG_DEFAULTS ${SDKCONFIG_DEFAULTS} boards/sdkconfig.nimble_core1)
+endif()
+
# Concatenate all sdkconfig files into a combined one for the IDF to use.
file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "")
foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})
@@ -33,6 +43,5 @@ endforeach()
configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY)
set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)
-# Include main IDF cmake file and define the project.
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+# Define the project.
project(micropython)
diff --git a/ports/esp32/boards/sdkconfig.ble b/ports/esp32/boards/sdkconfig.ble
index 5565fd81a..08d5e481f 100644
--- a/ports/esp32/boards/sdkconfig.ble
+++ b/ports/esp32/boards/sdkconfig.ble
@@ -7,11 +7,3 @@ CONFIG_BTDM_CTRL_MODE_BTDM=
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
-CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y
-CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n
-CONFIG_BT_NIMBLE_PINNED_TO_CORE=0
diff --git a/ports/esp32/boards/sdkconfig.nimble_core0 b/ports/esp32/boards/sdkconfig.nimble_core0
new file mode 100644
index 000000000..cacaff119
--- /dev/null
+++ b/ports/esp32/boards/sdkconfig.nimble_core0
@@ -0,0 +1,6 @@
+# For 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
diff --git a/ports/esp32/boards/sdkconfig.nimble_core1 b/ports/esp32/boards/sdkconfig.nimble_core1
new file mode 100644
index 000000000..33653cc4b
--- /dev/null
+++ b/ports/esp32/boards/sdkconfig.nimble_core1
@@ -0,0 +1,6 @@
+# For IDF >=4.2, we are able to put NimBLE on core 1, and for synchronisation
+# with the ringbuffer and scheduler MP needs to be on the same core.
+# MP on core 1 prevents interference with WiFi for time sensitive operations.
+CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=n
+CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y
+CONFIG_BT_NIMBLE_PINNED_TO_CORE=1
diff --git a/ports/esp32/mphalport.h b/ports/esp32/mphalport.h
index 01c14ad70..c838bd228 100644
--- a/ports/esp32/mphalport.h
+++ b/ports/esp32/mphalport.h
@@ -38,10 +38,15 @@
#define MICROPY_PLATFORM_VERSION "IDF" IDF_VER
// 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;