ESP32 2Tasks on 2 Cores - Board reset
Posted: Wed Mar 27, 2019 8:21 am
/* Below is the code for the 2 tasks which will run on different core viz Core 1 and 2.
The Tasks would be triggered in the "Key press interrupt". I see that Tasks start but board
get reboot immediately.
Can anyone guide me here * /
#define DELAY1 delay(800)
#define DELAY2 delay(500)
TaskHandle_t Task1_Handler;
TaskHandle_t Task2_Handler;
// LED pins
const int led1 = 13;
const int led2 = 23;
struct Button
{
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button button1 = {2, 0, false};
/* Resume both task on Key press */
void IRAM_ATTR isr()
{
BaseType_t taskYieldRequired = 0;
button1.pressed = true;
taskYieldRequired = xTaskResumeFromISR(Task1_Handler);
taskYieldRequired = xTaskResumeFromISR(Task2_Handler);
}
void setup()
{
Serial.begin(115200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
/* intr init */
pinMode(button1.PIN, INPUT_PULLUP);
attachInterrupt(button1.PIN, isr, FALLING);
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(Task1code, "Task1", 8000, NULL, 1, &Task1_Handler, 0);
vTaskSuspend(Task1_Handler);
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(Task2code, "Task2", 8000, NULL, 1, &Task2_Handler, 1);
vTaskSuspend(Task2_Handler);
//esp_task_wdt_init(10,1);
}
//Task1code: blinks an LED every 800 ms
void Task1code( void * pvParameters )
{
uint8_t i;
Serial.print("********** Task1 core running ");
Serial.println(xPortGetCoreID());
for(i=0;i<2;i++)
{
digitalWrite(led1, HIGH);
DELAY1;
digitalWrite(led1, LOW);
DELAY1;
}
}
//Task2code: blinks an LED every 500 ms
void Task2code( void * pvParameters )
{
uint8_t i;
Serial.print("################ Task2 CORE ");
Serial.println(xPortGetCoreID());
for(i=0;i<2;i++)
{
digitalWrite(led2, HIGH);
DELAY2;
digitalWrite(led2, LOW);
DELAY2;
}
}
void loop()
{
if(button1.pressed)
{
Serial.print("in Intpt hit ");
button1.pressed = false;
}
}
The Tasks would be triggered in the "Key press interrupt". I see that Tasks start but board
get reboot immediately.
Can anyone guide me here * /
#define DELAY1 delay(800)
#define DELAY2 delay(500)
TaskHandle_t Task1_Handler;
TaskHandle_t Task2_Handler;
// LED pins
const int led1 = 13;
const int led2 = 23;
struct Button
{
const uint8_t PIN;
uint32_t numberKeyPresses;
bool pressed;
};
Button button1 = {2, 0, false};
/* Resume both task on Key press */
void IRAM_ATTR isr()
{
BaseType_t taskYieldRequired = 0;
button1.pressed = true;
taskYieldRequired = xTaskResumeFromISR(Task1_Handler);
taskYieldRequired = xTaskResumeFromISR(Task2_Handler);
}
void setup()
{
Serial.begin(115200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
/* intr init */
pinMode(button1.PIN, INPUT_PULLUP);
attachInterrupt(button1.PIN, isr, FALLING);
//create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
xTaskCreatePinnedToCore(Task1code, "Task1", 8000, NULL, 1, &Task1_Handler, 0);
vTaskSuspend(Task1_Handler);
//create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
xTaskCreatePinnedToCore(Task2code, "Task2", 8000, NULL, 1, &Task2_Handler, 1);
vTaskSuspend(Task2_Handler);
//esp_task_wdt_init(10,1);
}
//Task1code: blinks an LED every 800 ms
void Task1code( void * pvParameters )
{
uint8_t i;
Serial.print("********** Task1 core running ");
Serial.println(xPortGetCoreID());
for(i=0;i<2;i++)
{
digitalWrite(led1, HIGH);
DELAY1;
digitalWrite(led1, LOW);
DELAY1;
}
}
//Task2code: blinks an LED every 500 ms
void Task2code( void * pvParameters )
{
uint8_t i;
Serial.print("################ Task2 CORE ");
Serial.println(xPortGetCoreID());
for(i=0;i<2;i++)
{
digitalWrite(led2, HIGH);
DELAY2;
digitalWrite(led2, LOW);
DELAY2;
}
}
void loop()
{
if(button1.pressed)
{
Serial.print("in Intpt hit ");
button1.pressed = false;
}
}