Core 1 panic'ed (LoadProhibited) error after executing lv_btnmatrix_get_btn_text()

What MCU/Processor/Board and compiler are you using?

esp32, esp-wrover-kit
freeRTOS, arduino framework

What LVGL version are you using?

8.3.4

What have you tried so far?

I created a calendar using Squareline Studio and displayed it on an LCD screen by copying and pasting the code. When I touch a date on the calendar, a panic occurs in the event handler, and it seems that an error occurs when trying to retrieve the value of txt[0] after executing the code inside the lv_calendar_get_pressed_date(obj, id) function:

const char* txt = lv_btnmatrix_get_btn_text(calendar->btnm, lv_btnmatrix_get_selected_btn(calendar->btnm));

Where could the problem be?

lv_res_t lv_calendar_get_pressed_date(const lv_obj_t * obj, lv_calendar_date_t * date)
{
    LV_ASSERT_OBJ(obj, MY_CLASS);
    lv_calendar_t * calendar = (lv_calendar_t *)obj;
    uint16_t d = lv_btnmatrix_get_selected_btn(calendar->btnm);
    if(d == LV_BTNMATRIX_BTN_NONE) {
        date->year = 0;
        date->month = 0;
        date->day = 0;
        return LV_RES_INV;
    }
    const char * txt = lv_btnmatrix_get_btn_text(calendar->btnm, lv_btnmatrix_get_selected_btn(calendar->btnm));
    my_printf("txt: %s, %d\n", txt);
    my_printf("txt[0]: %c\n", txt[0]);
    my_printf("txt[0]: %c\n", txt[1]);
    if(txt[1] == 0) date->day = txt[0] - '0';
    else date->day = (txt[0] - '0') * 10 + (txt[1] - '0');

    date->year = calendar->showed_date.year;
    date->month = calendar->showed_date.month;
    
    return LV_RES_OK;
}
  • the result of “my_printf(“txt: %s, %d\n”, txt);” is “|�␐@�e�?␄”
  • the result of “my_printf(“txt[0]: %c\n”, txt[0]);” is Core 1 panic’ed (LoadProhibited)
    Refer to the below.
txt: |�␐@�e�?␄, 1073571344
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400ebb37  PS      : 0x00060830  A0      : 0x800d27ca  A1      : 0x3ffd6660
A2      : 0x3ffc69ac  A3      : 0x3ffd668c  A4      : 0x00000000  A5      : 0x3f404dd0  
A6      : 0x00000000  A7      : 0x00000001  A8      : 0x800ebb34  A9      : 0x3ffd6610
A10     : 0x3f404dc0  A11     : 0x3ffd6610  A12     : 0x0000ffff  A13     : 0x3ffd65cc  
A14     : 0x00000004  A15     : 0x000068fc  SAR     : 0x00000004  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000  LBEG    : 0x4008b76d  LEND    : 0x4008b77d  LCOUNT  : 0xfffffffd 

the lv_calendar_get_pressed_date() is called in the ui_event_Calendar.

// ui.c
void ui_event_Calendar(lv_event_t *e) // Calendar event
{
    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t *target = lv_event_get_target(e);

    if (event_code == LV_EVENT_VALUE_CHANGED)
    {
        // Calendar_Event_Handler(e);
        lv_calendar_date_t date;
        my_printf("Calendar event: %d\n", target);
        if (target != NULL)
        {
            if (lv_calendar_get_pressed_date(target, &date))
            {
                my_printf("Clicked date: %02d.%02d.%d\n", date.day, date.month, date.year);
            }
        }
    }
}

I think you are running into an issue because of using FreeRTOS. LVGL is not thread safe nor is it safe to be accessed from 2 different cores.

Have you tried removing your use of FreeRTOS and seeing if the issue goes away?

I believe this is the issue.

my_printf("txt: %s, %d\n", txt);

You are not even getting to the second my_printf

txt: |�␐@�e�?␄, 1073571344

1073571344 is a memory address

maybe the txt is not terminated with a \0 like it should be. have you tried removing the first my_printf and see if it’s actually the second one that causes the core panic??

I don’t think there is a \0 on the end. the reason why I say this is because you are dealing with something that should have at most 2 characters in it yet the printed value is |�␐@�e�?␄ which is more than 2 characters. The core panic would occur because printf is not able to locate the end.

If you remove the first my_printf it will probably work correctly.

How is my_printf implemented?

A panic error occurred, so I inserted my_printf() to find the cause. It is not because of my_printf(). The panic error still occurs even after removing my_printf(). The error happens when accessing txt[0].

ui_event_Calendar() -> lv_calendar_get_pressed_date() ->
...
const char * txt = lv_btnmatrix_get_btn_text(calendar->btnm, lv_btnmatrix_get_selected_btn(calendar->btnm));
if(txt[1] == 0) date->day = txt[0] - '0';  // <- here
// my_print.h
#ifndef MY_PRINT_H
#define MY_PRINT_H

void my_print(const char *msg);
void my_println(const char *msg);
void my_printf(const char *format, ...);
#endif
//my_print.cpp
#include <Arduino.h>
#include <stdarg.h>
extern "C" {
#include "my_print.h"
}

void my_print (const char *msg) {
  Serial.print (msg);
}

void my_println (const char *msg) {
  Serial.println (msg);
}

void my_printf(const char *format, ...) {
    va_list args;
    va_start(args, format);
    Serial.printf(format, args);
    va_end(args);
}

There was one strange thing.
I created a calendar in squareline studio and pasted the code (ui.c) as it is, but lv_calendar_set_shown_date() did not build because an undefined reference error occurred. It was not implemented in lv_calendar.c, so I just commented it out and executed it.
could this be a problem?

    ui_Calendar = lv_calendar_create(ui_ScreenSetDate);
    lv_calendar_set_today_date(ui_Calendar, 2023, 1, 1);
    lv_calendar_set_shown_date(ui_Calendar, 2023, 1);
    lv_obj_t *ui_Calendar_header = lv_calendar_header_arrow_create(ui_Calendar);
    lv_obj_set_width(ui_Calendar, 248);
    lv_obj_set_height(ui_Calendar, 193);
    lv_obj_set_x(ui_Calendar, 6);
    lv_obj_set_y(ui_Calendar, 11);
    lv_obj_set_align(ui_Calendar, LV_ALIGN_CENTER);
c:/users/jjs/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp-wrover-kit\src\ui.c.o:(.literal.ui_ScreenSetDate_screen_init+0x18): undefined reference to `lv_calendar_set_shown_date'
c:/users/jjs/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp-wrover-kit\src\ui.c.o: in function `ui_ScreenSetDate_screen_init':
D:\Project\HVP\FreeRTOS_test_230116/src/ui.c:619: undefined reference to `lv_calendar_set_shown_date'

I didn’t use the calendar functions, so I have no experiece.
I would carefully say yes, could be a problem when you outcommet something.
Although there is missing the second parameter, it shouldn’t result in an exception.
There is something wrong before.

yeah that would cause a problem not having the date set. That is why you having an issue with the txt

change lv_calendar_set_shown_date to lv_calendar_set_showed_date and I believe that will sort out your issue.

I am in agreement with @robekras as far as the core panic. I will have to look at the current version of LVGL and see if there are any checks in place to see if the date has been set before trying to collect it from the widget. If there isn’t there should be so this doesn’t happen.