8000 esp32: Pin MicroPython to core 1 again. · leifbirger/micropython@3ab9039 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ab9039

Browse files
breedx2leifbirger
authored andcommitted
esp32: Pin MicroPython to core 1 again.
This follows up on micropython#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.
1 parent 022b4ee commit 3ab9039

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

ports/esp32/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ if(NOT EXISTS ${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
1818
message(FATAL_ERROR "Invalid MICROPY_BOARD specified: ${MICROPY_BOARD}")
1919
endif()
2020

21+
# Include main IDF cmake file.
22+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
23+
2124
# Define the output sdkconfig so it goes in the build directory.
2225
set(SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig)
2326

2427
# Include board config; this is expected to set SDKCONFIG_DEFAULTS (among other options).
2528
include(${MICROPY_BOARD_DIR}/mpconfigboard.cmake)
2629

30+
# Add sdkconfig fragments that depend on the IDF version.
31+
if(IDF_VERSION_MAJOR EQUAL 4 AND IDF_VERSION_MINOR LESS 2)
32+
set(SDKCONFIG_DEFAULTS ${SDKCONFIG_DEFAULTS} boards/sdkconfig.nimble_core0)
33+
else()
34+
set(SDKCONFIG_DEFAULTS ${SDKCONFIG_DEFAULTS} boards/sdkconfig.nimble_core1)
35+
endif()
36+
2737
# Concatenate all sdkconfig files into a combined one for the IDF to use.
2838
file(WRITE ${CMAKE_BINARY_DIR}/sdkconfig.combined.in "")
2939
foreach(SDKCONFIG_DEFAULT ${SDKCONFIG_DEFAULTS})
@@ -33,6 +43,5 @@ endforeach()
3343
configure_file(${CMAKE_BINARY_DIR}/sdkconfig.combined.in ${CMAKE_BINARY_DIR}/sdkconfig.combined COPYONLY)
3444
set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)
3545

36-
# Include main IDF cmake file and define the project.
37-
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
46+
# Define the project.
3847
project(micropython)

ports/esp32/boards/sdkconfig.ble

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ CONFIG_BTDM_CTRL_MODE_BTDM=
77
CONFIG_BT_NIMBLE_ENABLED=y
88

99
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=4
10-
11-
# Pin to the same core as MP.
12-
# Until we move to IDF 4.2+, we need NimBLE on core 0, and for synchronisation
13-
# with the ringbuffer and scheduler MP needs to be on the same core.
14-
# See https://github.com/micropython/micropython/issues/5489
15-
CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y
16-
CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n
17-
CONFIG_BT_NIMBLE_PINNED_TO_CORE=0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# For IDF <4.2, we need NimBLE on core 0, and for synchronisation
2+
# with the ringbuffer and scheduler MP needs to be on the same core.
3+
# See https://github.com/micropython/micropython/issues/5489
4+
CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=y
5+
CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=n
6+
CONFIG_BT_NIMBLE_PINNED_TO_CORE=0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# For IDF >=4.2, we are able to put NimBLE on core 1, and for synchronisation
2+
# with the ringbuffer and scheduler MP needs to be on the same core.
3+
# MP on core 1 prevents interference with WiFi for time sensitive operations.
4+
CONFIG_BT_NIMBLE_PINNED_TO_CORE_0=n
5+
CONFIG_BT_NIMBLE_PINNED_TO_CORE_1=y
6+
CONFIG_BT_NIMBLE_PINNED_TO_CORE=1

ports/esp32/mphalport.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@
3838
#define MICROPY_PLATFORM_VERSION "IDF" IDF_VER
3939

4040
// The core that the MicroPython task(s) are pinned to.
41-
// Until we move to IDF 4.2+, we need NimBLE on core 0, and for synchronisation
42-
// with the ringbuffer and scheduler MP needs to be on the same core.
43-
// See https://github.com/micropython/micropython/issues/5489
41+
// Now that we have IDF 4.2.0+, we are once again able to pin to core 1
42+
// and avoid the Wifi/BLE timing problems on the same core.
43+
// Best effort here to remain backwards compatible in rare version edge cases...
44+
// See https://github.com/micropython/micropython/issues/5489 for history
45+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0)
46+
#define MP_TASK_COREID (1)
47+
#else
4448
#define MP_TASK_COREID (0)
49+
#endif
4550

4651
extern TaskHandle_t mp_main_task_handle;
4752

0 commit comments

Comments
 (0)
0