Skip to content

Pin ESP32 tasks to core #4943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/esp32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void mp_task(void *pvParameter) {

void app_main(void) {
nvs_flash_init();
xTaskCreate(mp_task, "mp_task", MP_TASK_STACK_LEN, NULL, MP_TASK_PRIORITY, &mp_main_task_handle);
xTaskCreatePinnedToCore(mp_task, "mp_task", MP_TASK_STACK_LEN, NULL, MP_TASK_PRIORITY, &mp_main_task_handle, ESP32_TASK_COREID);
}

void nlr_jump_fail(void *val) {
Expand Down
2 changes: 2 additions & 0 deletions ports/esp32/modmachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "py/obj.h"

#define ESP32_TASK_COREID 1

typedef enum {
//MACHINE_WAKE_IDLE=0x01,
MACHINE_WAKE_SLEEP=0x02,
Expand Down
3 changes: 2 additions & 1 deletion ports/esp32/mpthreadport.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "py/gc.h"
#include "py/mpthread.h"
#include "mpthreadport.h"
#include "modmachine.h"

#include "esp_task.h"

Expand Down Expand Up @@ -130,7 +131,7 @@ void mp_thread_create_ex(void *(*entry)(void*), void *arg, size_t *stack_size, i
mp_thread_mutex_lock(&thread_mutex, 1);

// create thread
BaseType_t result = xTaskCreate(freertos_entry, name, *stack_size / sizeof(StackType_t), arg, priority, &th->id);
BaseType_t result = xTaskCreatePinnedToCore(freertos_entry, name, *stack_size / sizeof(StackType_t), arg, priority, &th->id, ESP32_TASK_COREID);
if (result != pdPASS) {
mp_thread_mutex_unlock(&thread_mutex);
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "can't create thread"));
Expand Down
2 changes: 1 addition & 1 deletion ports/esp32/network_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ STATIC mp_obj_t ppp_active(size_t n_args, const mp_obj_t *args) {
ppp_set_usepeerdns(self->pcb, 1);
pppapi_connect(self->pcb, 0);

xTaskCreate(pppos_client_task, "ppp", 2048, self, 1, (TaskHandle_t*)&self->client_task_handle);
xTaskCreatePinnedToCore(pppos_client_task, "ppp", 2048, self, 1, (TaskHandle_t*)&self->client_task_handle, ESP32_TASK_COREID);
self->active = true;
} else {
if (!self->active) {
Expand Down