text updata abnormal

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.


I use lv_label_create create two Label widgets to display times and number;
the object hander is global variable,and i only create them one time,and set their style,
then,i try to updata the text of the labels,lilke this
lv_label_set_text_fmt(guider_ui.CanDataPlayLabel6,“%lld Times”,PlayCounter);
lv_label_set_text_fmt(guider_ui.CanDataPlayLabel6,“%lld Times”,PlayCounter);

printf(PlayCounter= %lld\r\n,PlayCounter);

the nmber can updata when the Circulation running;
when the Circulation have finished execution,
i see the printf contents is correct,but some times the lab shows the smaller data;
for example printf shows 12345,but i see 12341 on the screnn
what is more important,when the number not equal to the fact,
the code "lv_img_set_src(guider_ui.CanDataPlayImg,&Compelet);"did not work,it can not change the image;
when the printf number equals to label show,the lv_img_set_src work,and change the image.

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


What LVGL version are you using?


What do you want to achieve?

i want the Label show the data that needs to change

What have you tried so far?

i guess,the Circulation function run too fast,the LVGL memory manage can not creat and free memory
in time,(infact,i allocate a huge memry to LVGL 40KB,it is enough ,wen the code runs,it have 20KB left)
i change the Label up data like lv_label_set_text_static,but it can not show the last data probability
the code like this(PlayCounterStr is globle)
sprintf(PlayCounterStr,“%lld Times”,PlayCounter);
sprintf(PlayCounterStr,“%lld Times”,PlayCounter);

printf(PlayCounter= %lld\r\n,PlayCounter);
When the value of the label is not equal to the actual value, the image does not change;just
have less probability compared with lv_label_set_text_fmt;
i can affirm lv_task_handler();run correctly all the time.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:
/You code here/
the code is
typedef struct
lv_obj_t *ScrCanDataPlay;
bool ScrCanDataPlay_Del;
lv_obj_t *CanDataPlayLabel6;

lv_ui guider_ui;
//Write codes ScrCanDataPlay
guider_ui.ScrCanDataPlay = lv_obj_create(NULL);
lv_obj_set_scrollbar_mode(guider_ui.ScrCanDataPlay, LV_SCROLLBAR_MODE_OFF);

//Write style state: LV_STATE_DEFAULT for style_screen_main_main_default
static lv_style_t style_screen_main_main_default;
if (style_screen_main_main_default.prop_cnt > 1)
lv_style_set_bg_color(&style_screen_main_main_default, lv_color_make(0xff, 0xff, 0xff));
lv_style_set_bg_opa(&style_screen_main_main_default, 0);
lv_obj_add_style(guider_ui.ScrCanDataPlay, &style_screen_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

//Write style state: LV_STATE_DEFAULT for style_screen_label_all_main_main_default
static lv_style_t style_screen_label_all_main_main_default;
if (style_screen_label_all_main_main_default.prop_cnt > 1)
lv_style_set_radius(&style_screen_label_all_main_main_default, 0);
lv_style_set_bg_color(&style_screen_label_all_main_main_default, lv_color_make(0xff, 0xff, 0xff));
lv_style_set_bg_grad_color(&style_screen_label_all_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_bg_grad_dir(&style_screen_label_all_main_main_default, LV_GRAD_DIR_NONE);
lv_style_set_bg_opa(&style_screen_label_all_main_main_default, 255);
lv_style_set_shadow_width(&style_screen_label_all_main_main_default, 0);
lv_style_set_shadow_color(&style_screen_label_all_main_main_default, lv_color_make(0x21, 0x95, 0xf6));
lv_style_set_shadow_opa(&style_screen_label_all_main_main_default, 255);
lv_style_set_shadow_spread(&style_screen_label_all_main_main_default, 0);
lv_style_set_shadow_ofs_x(&style_screen_label_all_main_main_default, 0);
lv_style_set_shadow_ofs_y(&style_screen_label_all_main_main_default, 0);
lv_style_set_text_color(&style_screen_label_all_main_main_default, lv_color_make(0x00, 0x00, 0x00));
lv_style_set_text_font(&style_screen_label_all_main_main_default, &HeiTi16);
lv_style_set_text_letter_space(&style_screen_label_all_main_main_default, 0);
lv_style_set_text_line_space(&style_screen_label_all_main_main_default, 0);
lv_style_set_text_align(&style_screen_label_all_main_main_default, LV_TEXT_ALIGN_CENTER);
lv_style_set_pad_left(&style_screen_label_all_main_main_default, 0);
lv_style_set_pad_right(&style_screen_label_all_main_main_default, 0);
lv_style_set_pad_top(&style_screen_label_all_main_main_default, 5);
lv_style_set_pad_bottom(&style_screen_label_all_main_main_default, 0);

guider_ui.CanDataPlayLabel6 = lv_label_create(guider_ui.ScrCanDataPlay);
lv_obj_set_pos(guider_ui.CanDataPlayLabel6, CHINESELABWIDTH, 25);
lv_obj_set_size(guider_ui.CanDataPlayLabel6, INFORMATIONLABWIDTH, INFORMATIONLABHIGH);
lv_obj_set_scrollbar_mode(guider_ui.CanDataPlayLabel6, LV_SCROLLBAR_MODE_OFF);
lv_label_set_text(guider_ui.CanDataPlayLabel6, "");
lv_label_set_long_mode(guider_ui.CanDataPlayLabel6, LV_LABEL_LONG_SCROLL);
lv_obj_add_style(guider_ui.CanDataPlayLabel6, &style_screen_label_all_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);


uint64_t PlayCounter;
uint64_t CanDataPlayTotalCount = 12345;
char PlayCounterStr[50];

		lv_label_set_text_fmt(guider_ui.CanDataPlayLabel6,"%lld Times",PlayCounter);
		DelayMs(1);//1 ms delay

lv_label_set_text_fmt(guider_ui.CanDataPlayLabel6,“%lld Times”,PlayCounter); //updata the last time

printf("CanDataPlayTotalCount =%lld\r\n",CanDataPlayTotalCount);

sprintf(PlayCounterStr,“%lld Times”,PlayCounter);
DelayMs(1);//1 ms delay
sprintf(PlayCounterStr,“%lld Times”,PlayCounter);//updata the last time

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Sorry, your post is a bit incomprehensible.
It is not clear to what function your code snippets belong to.
What do you mean with circulation function?

Please next time post your code properly quoted so it is more readable.

I think there is a misconception about LVGL’s drawing and update mechanism. From the code you provided, you think the screen should update immediately after calling “lv_label_set_text”, but it doesn’t. The FPS of LVGL is related to the timer handle and the clock of the screen hardware interface. My recommendation is for delay to be greater than the minimum FPS, but that’s still not the best solution, it’s better to decouple the data from the display.

Thank you for your reply. I have one thread that is always refreshing the display at 20fps and another thread that is doing interface changes etc. Changing text is one of them. When I change the text content, the screen refresh thread is executing and the text has not been updated until the last assignment. In addition, when using FATFS, EMWIN and other libraries, these libraries provide a mutex interface. When using RTOS, users can write the mutex corresponding to RTOS into the mutex interface of the library. lvgl document mentioned that lvgl is not thread-safe, but I did not find the mutex interface. As a result, I need to manually add mutex in many places, which is easy to leak and cause deadlock. Does lvgl provide a mutex interface for users to fill in the corresponding function? If so, can you specify the location for me

Sorry I have no experience with LVGL in RTOS environment, but you can try lv_timer instead of RTOS thread to update the screen content, so there is no mutex problem