From 697fd0d4b5aea4c24e3a8f81693bdc97a174bc61 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Wed, 10 Jul 2024 10:16:12 +0300 Subject: [PATCH 1/2] feat(eth): Allow setting the RX task stack size Default stack size of 2K might not be enough in some cases. Increase the default to safer 4K and allow setting it to custom value. --- libraries/Ethernet/src/ETH.cpp | 10 ++++++++++ libraries/Ethernet/src/ETH.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index 2480dd982ec..f7a14435572 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -130,6 +130,8 @@ ETHClass::ETHClass(uint8_t eth_index) , _pin_mcd(-1), _pin_mdio(-1), _pin_power(-1), _pin_rmii_clock(-1) #endif /* CONFIG_ETH_USE_ESP32_EMAC */ + , + _task_stack_size(4096) { } @@ -141,6 +143,10 @@ bool ETHClass::ethDetachBus(void *bus_pointer) { return true; } +void ETHClass::setTaskStackSize(size_t size) { + _task_stack_size = size; +} + #if CONFIG_ETH_USE_ESP32_EMAC bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, int power, eth_clock_mode_t clock_mode) { esp_err_t ret = ESP_OK; @@ -214,6 +220,7 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG(); eth_mac_config.sw_reset_timeout_ms = 1000; + eth_mac_config.rx_task_stack_size = _task_stack_size; esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config, ð_mac_config); if (mac == NULL) { @@ -578,6 +585,9 @@ bool ETHClass::beginSPI( __unused eth_mac_config_t eth_mac_config = ETH_MAC_DEFAULT_CONFIG(); __unused eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); + // Set RX Task Stack Size + eth_mac_config.rx_task_stack_size = _task_stack_size; + // Update PHY config based on board specific configuration phy_config.phy_addr = phy_addr; phy_config.reset_gpio_num = _pin_rst; diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index b481b9e36c3..14d2d042614 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -153,6 +153,9 @@ class ETHClass : public NetworkInterface { void end(); + // This function must be called before `begin()` + void setTaskStackSize(size_t size); + // ETH Handle APIs bool fullDuplex() const; uint8_t linkSpeed() const; @@ -203,6 +206,7 @@ class ETHClass : public NetworkInterface { int8_t _pin_power; int8_t _pin_rmii_clock; #endif /* CONFIG_ETH_USE_ESP32_EMAC */ + size_t _task_stack_size; static bool ethDetachBus(void *bus_pointer); bool beginSPI( From cd49756725901354edab2e113dd98b14dff3a57c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 10 Jul 2024 10:04:35 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- libraries/Ethernet/src/ETH.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index f7a14435572..4d215d80034 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -131,8 +131,7 @@ ETHClass::ETHClass(uint8_t eth_index) _pin_mcd(-1), _pin_mdio(-1), _pin_power(-1), _pin_rmii_clock(-1) #endif /* CONFIG_ETH_USE_ESP32_EMAC */ , - _task_stack_size(4096) -{ + _task_stack_size(4096) { } ETHClass::~ETHClass() {}