From 5f7800cb063b25392bc011cf94ced3cb7a80a747 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Thu, 21 Aug 2025 13:29:25 -0500 Subject: [PATCH] feat: Allow customization of esp-now task --- src/espnow/include/espnow.h | 10 ++++++++++ src/espnow/src/espnow.c | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/espnow/include/espnow.h b/src/espnow/include/espnow.h index a4e0b13..f91a8f6 100644 --- a/src/espnow/include/espnow.h +++ b/src/espnow/include/espnow.h @@ -96,6 +96,11 @@ typedef struct { bool sec_data : 1; /**< Enable or disable security data */ uint32_t reserved2 : 18; /**< Reserved */ } receive_enable; /**< Set 1 to enable receiving the corresponding ESP-NOW data type */ + struct { + uint32_t stack_size_bytes; /**< Task stack size in bytes. Increase this if you perform more work in the callbacks. */ + int32_t core_id; /**< Task core ID, tskNO_AFFINITY means not pinned to a core. */ + uint8_t priority; /**< Task priority, tskIDLE_PRIORITY is the lowest priority */ + } task_config; /**< Task configuration for the espnow_main task. */ } espnow_config_t; #define ESPNOW_INIT_CONFIG_DEFAULT() { \ @@ -124,6 +129,11 @@ typedef struct { .sec_data = 0, \ .reserved2 = 0, \ }, \ + .task_config = { \ + .stack_size_bytes = 4096, \ + .priority = tskIDLE_PRIORITY + 1, \ + .core_id = tskNO_AFFINITY, \ + }, \ } /** diff --git a/src/espnow/src/espnow.c b/src/espnow/src/espnow.c index 42f3f37..e79e777 100644 --- a/src/espnow/src/espnow.c +++ b/src/espnow/src/espnow.c @@ -1105,7 +1105,12 @@ esp_err_t espnow_init(const espnow_config_t *config) ESP_LOGI(TAG, "mac: " MACSTR ", version: %d", MAC2STR(ESPNOW_ADDR_SELF), ESPNOW_VERSION); ESP_LOGI(TAG, "Enable main task"); - xTaskCreate(espnow_main_task, "espnow_main", 4096, NULL, tskIDLE_PRIORITY + 1, NULL); + xTaskCreatePinnedToCore(espnow_main_task, "espnow_main", + g_espnow_config->task_config.stack_size_bytes, + NULL, + g_espnow_config->task_config.priority, + NULL, + g_espnow_config->task_config.core_id); return ESP_OK; }