diff --git a/src/ESP_FlexyStepper.cpp b/src/ESP_FlexyStepper.cpp index f54592c..85e38d7 100644 --- a/src/ESP_FlexyStepper.cpp +++ b/src/ESP_FlexyStepper.cpp @@ -91,16 +91,23 @@ ESP_FlexyStepper::~ESP_FlexyStepper() } //TODO: use https://github.com/nrwiersma/ESP8266Scheduler/blob/master/examples/simple/simple.ino for ESP8266 -void ESP_FlexyStepper::startAsService(void) +void ESP_FlexyStepper::startAsService(int core) { - disableCore0WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper - xTaskCreate( + + if ( (!core_0_wdt_was_disabled_from_flexyStepper) && (core!=1) ) //If WDT has not been disabled previously and core 1 is not selected + { +disableCore0WDT(); // we have to disable the Watchdog timer to prevent it from rebooting the ESP all the time another option would be to add a vTaskDelay but it would slow down the stepper +core_0_wdt_was_disabled_from_flexyStepper=1; //Let's indicate that we have disabled WDT for kernel 0 + } + + xTaskCreateUniversal( //This type of task is specially adapted to work with single and dual core versions of ESP32 ESP_FlexyStepper::taskRunner, /* Task function. */ "FlexyStepper", /* String with name of task (by default max 16 characters long) */ 2000, /* Stack size in bytes. */ this, /* Parameter passed as input of the task */ 1, /* Priority of the task, 1 seems to work just fine for us */ - &this->xHandle); /* Task handle. */ + &this->xHandle, /* Task handle. */ + core); /* The core on which our task will be executed*/ } void ESP_FlexyStepper::taskRunner(void *parameter) diff --git a/src/ESP_FlexyStepper.h b/src/ESP_FlexyStepper.h index 149344b..9fa8929 100644 --- a/src/ESP_FlexyStepper.h +++ b/src/ESP_FlexyStepper.h @@ -51,13 +51,15 @@ typedef void (*callbackFunction)(void); typedef void (*positionCallbackFunction)(long); +static bool core_0_wdt_was_disabled_from_flexyStepper = 0; + class ESP_FlexyStepper { public: ESP_FlexyStepper(); ~ESP_FlexyStepper(); //service functions - void startAsService(void); + void startAsService(int core= (-1) ); //If the user does not specify the desired kernel as a parameter, then the free one will be selected void stopService(void); bool isStartedAsService(void);