How to change label value in ESP32-S3 without Guru Meditation Error panic

migmel
Posts: 22
Joined: Wed Oct 25, 2023 9:01 am

How to change label value in ESP32-S3 without Guru Meditation Error panic

Postby migmel » Wed Oct 25, 2023 9:26 am

Hello, I have created several simple GUI applications with Squareline. Since I've been struggling trying to modify the value of a label because no matter what i always get a Guru Meditation Error Panic.
Last app I created was a simple GUI with one screen, one panel and one label which text I pretend modify.
I have try to modify it from a FreeRTOS task <failed>, then I try to modify it using events <failed>.
The error I get is below. Here is the relevant part of the log:

I (851) MAIN: Event Posted
I (851) MAIN: Event Received
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.

Core 0 register dump:
PC : 0x42045ab3 PS : 0x00060e30 A0 : 0x8200d86c A1 : 0x3fcb1a00
0x42045ab3: _lv_obj_get_ext_draw_size at E:/WorkSpace/REBIT/SquareLine_Project/components/lvgl/src/core/lv_obj_draw.c:393

A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00060e20 A5 : 0x00060e23
A6 : 0xb33fffff A7 : 0xb33fffff A8 : 0x00000001 A9 : 0x00000000
A10 : 0x00060e23 A11 : 0x00000000 A12 : 0x00000000 A13 : 0x00000010
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000008 LBEG : 0x400556d5 LEND : 0x400556e5 LCOUNT : 0xfffffffe
0x400556d5: strlen in ROM

0x400556e5: strlen in ROM

Backtrace: 0x42045ab0:0x3fcb1a00 0x4200d869:0x3fcb1a20 0x4202534d:0x3fcb1a50 0x42008d3b:0x3fcb1a70 0x42047a89:0x3fcb1a90 0x42047b94:0x3fcb1af0
0x42045ab0: _lv_obj_get_ext_draw_size at E:/WorkSpace/REBIT/SquareLine_Project/components/lvgl/src/core/lv_obj_draw.c:392

0x4200d869: lv_obj_invalidate at E:/WorkSpace/REBIT/SquareLine_Project/components/lvgl/src/core/lv_obj_pos.c:857

0x4202534d: lv_label_set_text at E:/WorkSpace/REBIT/SquareLine_Project/components/lvgl/src/widgets/lv_label.c:90

0x42008d3b: i2cEventHandler at E:/WorkSpace/REBIT/SquareLine_Project/main/main.c:126
(inlined by) i2cEventHandler at E:/WorkSpace/REBIT/SquareLine_Project/main/main.c:121

0x42047a89: handler_execute at E:/Users/User/esp/components/esp_event/esp_event.c:137
(inlined by) esp_event_loop_run at E:/Users/User/esp/components/esp_event/esp_event.c:593

0x42047b94: esp_event_loop_run_task at E:/Users/User/esp/components/esp_event/esp_event.c:107 (discriminator 15)

ELF file SHA256: 5c2e407581eb43cb

Rebooting...


Here is the handler causing the error:
  1.  
  2. static void i2cEventHandler(void* event_handler_arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
  3.     switch (event_id) {
  4.         case DATA_READY:
  5.             ESP_LOGI(T2G, "Event Received");
  6.             if (xSemaphoreTake(labelMutex, portMAX_DELAY) == pdTRUE) {
  7.                 lv_label_set_text(ui_mainLabel, output);
  8.                 // Release the mutex
  9.                 xSemaphoreGive(labelMutex);
  10.             }    
  11.             break;
  12.         default:
  13.             ESP_LOGI(T2G, "Default Event Received");
  14.             break;
  15.     }
  16. }
If I comment this line: lv_label_set_text(ui_mainLabel, output);
The error does not happen and the application runs fine
I can share the whole code if needed
Please, can anybody help me to do it the right way?
Regards

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

Re: How to change label value in ESP32-S3 without Guru Meditation Error panic

Postby MicroController » Thu Oct 26, 2023 10:25 pm

Most likely, "output" does not point to a valid memory address. Make sure output is properly initialized.

migmel
Posts: 22
Joined: Wed Oct 25, 2023 9:01 am

Re: How to change label value in ESP32-S3 without Guru Meditation Error panic

Postby migmel » Thu Oct 26, 2023 11:09 pm

Thank you for your reply,
I will check that possibility. However, before trying to modify the label value I print "output" variable and it correctly shows the content I want to post to the label.
The label is declare as extern lv_obj_t *ui_mainLabel"; and I can access it from any file by just including the header containing this declaration.
This is driving me crazy as I don't understand why I can modify the label value from inside the lvgl_task, which is the task in charge of refreshing the LCD.

djixon
Posts: 113
Joined: Sun Oct 01, 2023 7:48 pm

Re: How to change label value in ESP32-S3 without Guru Meditation Error panic

Postby djixon » Sat Oct 28, 2023 10:40 am

If you expect someone to help you then it is not enough to show just a line caused an exception.

Show here place where ui_mainLabel is created (constructor called), Is it freed unintentionally? What does your LCD shows on turning ON? Is ui_mainLabel on screen? Does it contain any text at that moment? How the output is declared? Is it allocated and assigned at runtime? Is your output null terminated? ...

_lv_obj_get_ext_draw_size

could fail due to invalid pointer to lv_obj or lock on it too.

In general, that example shows, how you should never "interact" with graphical components especially not from an ISR. Think like this, an ISR can be triggered 1000, 10000, 1000000 ..... times per second (depending on interrupt which cause it). A LCD can be refreshed (usually) not more than 60 times per second. So trying to change some "visual" component with higher rate than that does not have any sense.
More over, it will produce very inefficient code in terms of stalls and unnecessary locks/waits among ISR responsible for display refresh and ISRs from where access to "visual" component is tried.
Much better approach is:
1. Have some reserved global variable (in your case string) which will be updated from your i2c ISR routine (writing access)
2. Override inherited paint method of your visual component (where reading of that string and drawing will be performed) because any display invalidate (refresh) will call paint methods of all of visual components which requires repainting. Which means, the paint method of your label will be called too. In a case that you do not need a custom painting, you can call SetText function but do not do that from ISR. That function is not just about copying string. Internally, it will call measuring routines (to determine size of rectangle required for new text), routines for realignment (if required), wrapping (if required) etc. So it is time costly (from the aspect of times you are dealing inside an ISR).

All that is just a proper approach, however you have other problems too. If you want someone to help you, please post all relevant parts of your code.

migmel
Posts: 22
Joined: Wed Oct 25, 2023 9:01 am

Re: How to change label value in ESP32-S3 without Guru Meditation Error panic

Postby migmel » Sun Oct 29, 2023 9:35 am

Thank you for your reply and the explanation. I have solved it.
The event handler is not triggered by any I2C interrupt, but events are posted from within a task every 5 seconds.
I think the problem was that the functions I were trying to access were private to the lvgl_task in charge of initializing the screen, the UI and refreshing the LCD.
To solve it, I just made these functions accessible to the label_task in charge of making label modifications. In the solution I also got rid of the i2c_event_handler which was just an intermediary and I make the modifications directly from within the label_task.
In the solution I create a task that initializes the timer, screen and UI and after creating a label_task and a lvgl_task delete itself. In this way, the label task has the right access to the needed variables and functions to make the label modifications and the lvgl_task is only tasked with the refreshing LCD part
I will post here the solution, to help others with the same problem:
  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stddef.h>
  5. #include "freertos/FreeRTOS.h"
  6. #include "freertos/task.h"
  7. #include "freertos/queue.h"
  8. #include "freertos/semphr.h"
  9. #include "rom/gpio.h"
  10. #include "driver/gpio.h"
  11. #include "esp_log.h"
  12. #include "lvgl.h"
  13. #include "board.h"
  14. #include "nvs_flash.h"
  15. #include "esp_spiffs.h"
  16. #include "esp_timer.h"
  17. #include "aw9523.h"
  18. #include "ui/ui.h"
  19. #include "lvgl_esp32_drivers/lvgl_tft/esp_lcd_backlight.h" // Include the backlight header
  20. #include "hal/ledc_types.h"
  21.  
  22. #define TAG "MAIN"
  23.  
  24. extern void screen_init(void);
  25. extern void ui_init(void);
  26.  
  27. static void increase_lvgl_tick(void* arg) {
  28.     lv_tick_inc(portTICK_PERIOD_MS);
  29. }
  30.  
  31. void label_task(void* arg) {
  32.     uint8_t cnt=0;
  33.     char output[18];
  34.     for (;;) {
  35.         snprintf(output, sizeof(output), "New Text: %03d", cnt++);
  36.         if(cnt>255){cnt=0;}
  37.         lv_label_set_text(ui_Label1, output);
  38.         vTaskDelay(pdMS_TO_TICKS(5000));
  39.     }
  40. }
  41.  
  42. void lvgl_task(void* arg) {
  43.     for (;;) {
  44.         lv_task_handler();
  45.         vTaskDelay(pdMS_TO_TICKS(10));
  46.     }
  47. }
  48.  
  49.  
  50. void init_task(void* arg) {
  51.     for (;;) {
  52.         screen_init();
  53.         // Tick interface for LVGL
  54.         const esp_timer_create_args_t periodic_timer_args = {
  55.             .callback = increase_lvgl_tick,
  56.             .name = "periodic_gui"
  57.         };
  58.         esp_timer_handle_t periodic_timer;
  59.         esp_timer_create(&periodic_timer_args, &periodic_timer);
  60.         esp_timer_start_periodic(periodic_timer, portTICK_PERIOD_MS * 1000);
  61.         ui_init();
  62.         xTaskCreatePinnedToCore(lvgl_task, NULL, 4 * 1024, NULL, 5, NULL, 1);
  63.         xTaskCreate(label_task, NULL, 4 * 1024, NULL, 4, NULL);
  64.         vTaskDelete(NULL);
  65.     }
  66. }
  67.  
  68.  
  69. void app_main(void) {
  70.     /* init aw9523 */
  71.     aw9523_softreset();
  72.     aw9523_init(TOUCH_IIC_SDA, TOUCH_IIC_SDA);
  73.     ESP_LOGI(TAG, "Initialization done.");
  74.     xTaskCreatePinnedToCore(init_task, NULL, 8 * 1024, NULL, 5, NULL, 1);    
  75. }

Who is online

Users browsing this forum: Baidu [Spider], rsimpsonbusa and 83 guests