FreeRTOS Task causes TWDT triggered

User avatar
SSSSSteven
Posts: 11
Joined: Tue Dec 05, 2023 1:53 pm
Location: Shanghai, China
Contact:

Re: FreeRTOS Task causes TWDT triggered

Postby SSSSSteven » Fri Apr 12, 2024 6:21 am

ESP_Sprite wrote:
Fri Apr 12, 2024 5:48 am
Hm, no clue. Any other tasks doing anything with lvgl? Wondering if you may have some sort of concurrency issue.
No, only oled_task operates with LVGL.

The only reason I can image is, while oled_task updating LVGL label, gpio_task become ready, and since gpio_task has a higher priority (10), FreeRTOS pauses oled_task and starts gpio_task. That's may causes two tasks accessing one variable at the same time, since they are pointed to the same memory. But in my understanding, as the task is running infinitely, the screen shouldn't be stuck, label showed on screen should become normal in the next task run, and shouldn't trigger TWDT.

User avatar
ok-home
Posts: 59
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: FreeRTOS Task causes TWDT triggered

Postby ok-home » Fri Apr 12, 2024 6:45 am

Hi
I would not do parameter passing via global variables not protected by mutex ( spinlock )
In ESP-IDF there are proper mechanisms to pass data between tasks ( queue .... ),
gpio_task received data, sent it to the queue, oled_task took it from the queue and sent it to the screen

boarchuz
Posts: 574
Joined: Tue Aug 21, 2018 5:28 am

Re: FreeRTOS Task causes TWDT triggered

Postby boarchuz » Fri Apr 12, 2024 7:25 am

Try increasing the stack size. 2048 is on the low side.

User avatar
SSSSSteven
Posts: 11
Joined: Tue Dec 05, 2023 1:53 pm
Location: Shanghai, China
Contact:

Re: FreeRTOS Task causes TWDT triggered

Postby SSSSSteven » Fri Apr 12, 2024 3:31 pm

ok-home wrote:
Fri Apr 12, 2024 6:45 am
Hi
I would not do parameter passing via global variables not protected by mutex ( spinlock )
In ESP-IDF there are proper mechanisms to pass data between tasks ( queue .... ),
gpio_task received data, sent it to the queue, oled_task took it from the queue and sent it to the screen
Yeah, I know passing data via global variables is not the best solution. I thought using queue to pass data, but the thing is, gpio_task is running at a high frequency, but other tasks are running at a much lower frequency, so the queue will be fully filled very soon.

oled_task is not the only task need data sampled by gpio_task. I want to make sure all tasks always get the real time data, and since every task has its own frequency, I need gpio_task runs at a very high frequency, much higher than other tasks, and the highest priority.

I'm not very familiar with ESP-IDF, FreeRTOS and embedded development, so I just used the dumbest solution - global variables. Could you please tell me any better solution?

I'm not sure whether I expressed what I want to express, feel free to ask me anything not clear anytime. Sorry for the poor English.

MicroController
Posts: 1383
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: FreeRTOS Task causes TWDT triggered

Postby MicroController » Fri Apr 12, 2024 7:06 pm

You can consider using a more 'event-driven' approach, i.e. only updating the display when a value actually changes instead of every 100ms.

Also, in

Code: Select all

void oled_task(void *pvParameter) {
    uint32_t *variable = (uint32_t*)pvParameter;
    for(;;) {
        lv_label_set_text_fmt(label, "%d", *variable);
        vTaskDelay(100 / portTICK_PERIOD_MS);
    }
}
you could/should (at least) make the variable you're reading volatile (and the pointer accordingly volatile uint32_t* const variable = ...). Otherwise the compiler can assume that the value of *variable never changes while oled_task is running and optimize away any re-reading of the value.

Who is online

Users browsing this forum: No registered users and 44 guests