Why is my task not found

For practice I use wokwiki to learn rtos on a ESP32.

This is my code :

#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0 ; 
#else 
static const BaseType_t app_cpu = 1; 
#endif 

// Pins 
static const int led_pin = 2; 

//Our task  blink a led 
void toggleLed(void * parameter) {
  while(1) {
    digitalWrite(led_pin, HIGH);
    vTaskDelay(500 / portTICK_PERIOD_MS ); 
    digitalWrite(led_pin, LOW); 
    vTaskDelay(500 / portTICK_PERIOD_MS);
  }
}



void setup() {
  pinMode(led_pin, OUTPUT); 

  // Task to run forever 
  xTaskCreate(
    toggleLed,    // Function to be called
    "ToggleLed",  // name of the function 
    1024,         // stack size
    NULL,         // parameter to pass to the function 
    1,            // priority
    NULL         // task handle
  );

  vTaskStartScheduler();
}

void loop() {

}

Shw
This is from a YT course of Shwan Hymel

But as soon as I compile it , I see this as output

E (1911) task_wdt: esp_task_wdt_reset(705): task not found

How to solve this ?

As documented here:

Unlike Vanilla FreeRTOS, users of FreeRTOS in ESP-IDF must never call vTaskStartScheduler() and vTaskEndScheduler() . Instead, ESP-IDF starts FreeRTOS automatically.

You are likely getting the watchdog timer expired because of the extra call to vTaskStartScheduler which prevents Arduino framework to manage it.

You can also refer to these examples.

oke

Changed the code to this :

#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0 ; 
#else 
static const BaseType_t app_cpu = 1; 
#endif 

// Pins 
static const int led_pin = 2; 

//Our task  blink a led 
void toggleLed(void * parameter) {
  while(1) {
    digitalWrite(led_pin, HIGH);
    vTaskDelay(500 / portTICK_PERIOD_MS ); 
    digitalWrite(led_pin, LOW); 
    vTaskDelay(500 / portTICK_PERIOD_MS);
  }
}



void setup() {
  pinMode(led_pin, OUTPUT); 

  // Task to run forever 
   xTaskCreatePinnedToCore(
    toggleLed,    // Function to be called
    "ToggleLed",  // name of the function 
    1024,         // stack size
    NULL,         // parameter to pass to the function 
    1,            // priority
    NULL ,        // task handle
    app_cpu
  );

  
}

void loop() {

}

But still no luck

ets Jul 29 2019 12:21:46



rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

configsip: 0, SPIWP:0xee

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00

mode:DIO, clock div:2

load:0x3fff0030,len:1156

load:0x40078000,len:11456

ho 0 tail 12 room 4

load:0x40080400,len:2972

entry 0x400805dc

The part you have used in your diagram.json: "type": "board-esp32-devkit-c-v4" doesn’t seem to have a user LED at GPIO 2.

Your code should be working with: "type": "wokwi-esp32-devkit-v1".
Example

Thanks

Now I can finally work on this : https://www.youtube.com/playlist?list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz

and the homework on lesson 2

is this a good way to make the led blink on different rates

#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0 ; 
#else 
static const BaseType_t app_cpu = 1; 
#endif 

// Pins 
static const int led_pin = 2; 

//Our task  blink a led 
void toggleLed1(void * parameter) {
  while(1) {
    digitalWrite(led_pin, HIGH);
    vTaskDelay(500 / portTICK_PERIOD_MS ); 
    digitalWrite(led_pin, LOW); 
    vTaskDelay(500 / portTICK_PERIOD_MS);
  }
}

// homework to change the delay to another time
void toggleLed2(void * parameter) {
  while(1) {
    digitalWrite(led_pin, HIGH);
    vTaskDelay(200 / portTICK_PERIOD_MS ); 
    digitalWrite(led_pin, LOW); 
    vTaskDelay(200 / portTICK_PERIOD_MS);
  }
}




void setup() {
  pinMode(led_pin, OUTPUT); 

  // Task to run forever 
   xTaskCreatePinnedToCore(
    toggleLed1,    // Function to be called
    "ToggleLed",  // name of the function 
    1024,         // stack size
    NULL,         // parameter to pass to the function 
    1,            // priority
    NULL ,        // task handle
    app_cpu
  );

   xTaskCreatePinnedToCore(
    toggleLed2,    // Function to be called
    "ToggleLed2",  // name of the function 
    1024,         // stack size
    NULL,         // parameter to pass to the function 
    1,            // priority
    NULL ,        // task handle
    app_cpu
  );

  
}

void loop() {

}

or can I improve the code ?

This isn’t the ideal way to make the LED blink at different rates. Issue is that you have two tasks trying to control a single shared resource, which is the LED; this can lead to a race condition.

Since the purpose of this Forum is to provide support related to FreeRTOS and its libraries, and the question seems like homework, I can’t comment further on this, but there are lots of resources online that can help you with this.

1 Like

pity.

it is not homework because im not at school or something but a self thaught developer who wants to learn more about rtos but wants to be sure he really understands things and do not learn bad things or ways

The challenge was to make a second task that blinks the same led.

And what are you expecting to happen if two different tasks are telling the LED to do differrent things?

No idea, that I did not learned so far what could happen.

Till now I only learned to write tasks.

Sometimes its interesting to try to think ahead about what you would expect to happen.

I would think that one of the two would win.
But who would be winning , I have no idea

Or that the led will go on and after a very very short time will go off or the other way around.

So I think it leads to undefined behaviour as you call it

Right. And as you likely have figured by now, if you want to blink one LED at a specific rate, it does not make sense to have 2 tasks do that.