I have no text on the button label

Description

I use STM32F411RET6 and TFT LCD 320x240 based on ILI9341. I use the latest version of CubeMX and Keil uVision.

I want to run LVGL library on my microcontroller.

I have imported this library and even start it. Unfortunatly I have no text on the button label in lv_ex_get_started_1();. I have no touchpad I don’t use the button’s callback. I can add a text to the slider in lv_ex_get_started_3();

Code to reproduce

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "lvgl.h"
#include "ILI9341_GFX.h"
/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi1;

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * LV_VER_RES_MAX / 2]; 

void lv_ex_get_started_1(void)
{
    lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);     /*Add a button the current screen*/
    lv_obj_set_pos(btn, 10, 10);                            /*Set its position*/
    lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
    //lv_obj_set_event_cb(btn, btn_event_cb);                 /*Assign a callback to the button*/

    lv_obj_t * label = lv_label_create(btn, NULL);          /*Add a label to the button*/
    lv_label_set_text(label, "Button");                     /*Set the labels text*/
}

void lv_ex_get_started_3(void)
{
    /* Create a slider in the center of the display */
    lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL);
    lv_obj_set_width(slider, 200);                        /*Set the width*/
    lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0);    /*Align to the center of the parent (screen)*/
    //lv_obj_set_event_cb(slider, slider_event_cb);         /*Assign an event function*/

    /* Create a label below the slider */
    lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text_fmt(label, "%d", 74);
    lv_obj_set_auto_realign(slider, true);                          /*To keep center alignment when the width of the text changes*/
    lv_obj_align(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);    /*Align below the slider*/
}
void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p)
{
    int32_t x, y;	

    for(y = area->y1; y <= area->y2; y++) {
        for(x = area->x1; x <= area->x2; x++) {
            ILI9341_Draw_Pixel(x, y, color_p->full);  // Put a pixel to the display
            color_p++;
        }
    }
    lv_disp_flush_ready(disp);         /* Indicate you are ready with the flushing*/
}

void lv_user_init(void) {
	lv_init();
		
	 
	lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * LV_VER_RES_MAX / 2);
	lv_disp_drv_t disp_drv;
	lv_disp_drv_init(&disp_drv);
	disp_drv.flush_cb = my_disp_flush;
	disp_drv.buffer = &disp_buf;
	lv_disp_drv_register(&disp_drv);

	lv_ex_get_started_1();

}
/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();
  /* USER CODE BEGIN 2 */
  __HAL_SPI_ENABLE(DISP_SPI_PTR); 
  ILI9341_Init(); 
  ILI9341_Set_Rotation(SCREEN_HORIZONTAL_2);

  lv_user_init();

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		lv_task_handler();
		HAL_Delay(5);		
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Screenshot and/or video

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

From your code, it looks like there is no clock beat for LVGL, so you need to periodically call lv_tick_inc(1);
you can try add lv_tick_inc(5);to the while loop in main function.

I added lv_tick_inc(5); to the while loop and a have got nothing.

  while (1)
  {
		lv_task_handler();
		lv_tick_inc(5);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

Otherwice I can add the label with text in the lv_ex_get_started_3();

I don’t know what it can be because I have no extra errors or warnings while compilling the code.

Rebuild started: Project: lvgl_test
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Rebuild target 'lvgl_test'
assembling startup_stm32f411xe.s...
compiling lv_disp.c...
compiling lv_group.c...
compiling lv_indev.c...
compiling lv_refr.c...
compiling lv_draw_arc.c...
compiling lv_style.c...
compiling stm32f4xx_hal_msp.c...
compiling system_stm32f4xx.c...
compiling stm32f4xx_it.c...
compiling lv_draw_img.c...
compiling lv_obj.c...
lib\lvgl\src\lv_core\lv_obj.c(4599): warning:  #111-D: statement is unreachable
              break;
lib\lvgl\src\lv_core\lv_obj.c: 1 warning, 0 errors
compiling lv_draw_blend.c...
compiling lv_draw_line.c...
compiling lv_draw_triangle.c...
compiling main.c...
compiling lv_draw_label.c...
compiling lv_draw_mask.c...
lib\lvgl\src\lv_draw\lv_draw_mask.c(339): warning:  #111-D: statement is unreachable
          return;
lib\lvgl\src\lv_draw\lv_draw_mask.c(350): warning:  #111-D: statement is unreachable
          return;
lib\lvgl\src\lv_draw\lv_draw_mask.c: 2 warnings, 0 errors
compiling lv_img_cache.c...
compiling lv_font.c...
compiling lv_img_buf.c...
compiling lv_img_decoder.c...
compiling lv_font_dejavu_16_persian_hebrew.c...
compiling lv_font_fmt_txt.c...
lib\lvgl\src\lv_font\lv_font_fmt_txt.c(132): warning:  #111-D: statement is unreachable
      return NULL;
lib\lvgl\src\lv_font\lv_font_fmt_txt.c: 1 warning, 0 errors
compiling lv_font_montserrat_8.c...
compiling lv_draw_rect.c...
compiling lv_font_montserrat_10.c...
compiling lv_font_montserrat_12.c...
compiling lv_font_loader.c...
compiling lv_font_montserrat_12_subpx.c...
compiling lv_font_montserrat_14.c...
compiling lv_font_montserrat_16.c...
compiling lv_font_montserrat_18.c...
compiling lv_font_montserrat_20.c...
compiling lv_font_montserrat_24.c...
compiling lv_font_montserrat_22.c...
compiling lv_font_montserrat_26.c...
compiling lv_font_montserrat_30.c...
compiling lv_font_montserrat_28_compressed.c...
compiling lv_font_montserrat_28.c...
compiling lv_font_montserrat_32.c...
compiling lv_font_montserrat_34.c...
compiling lv_font_montserrat_38.c...
compiling lv_font_montserrat_36.c...
compiling lv_font_montserrat_42.c...
compiling lv_font_montserrat_44.c...
compiling lv_font_montserrat_40.c...
compiling lv_gpu_nxp_pxp.c...
compiling lv_gpu_nxp_pxp_osa.c...
compiling lv_font_montserrat_46.c...
compiling lv_font_unscii_8.c...
compiling lv_font_montserrat_48.c...
compiling lv_font_simsun_16_cjk.c...
compiling lv_font_unscii_16.c...
compiling lv_gpu_nxp_vglite.c...
compiling lv_gpu_stm32_dma2d.c...
compiling lv_hal_tick.c...
compiling lv_async.c...
compiling lv_hal_disp.c...
compiling lv_hal_indev.c...
compiling lv_anim.c...
compiling lv_area.c...
compiling lv_bidi.c...
compiling lv_color.c...
compiling lv_debug.c...
compiling lv_gc.c...
compiling lv_log.c...
compiling lv_ll.c...
compiling lv_fs.c...
compiling lv_math.c...
compiling lv_templ.c...
compiling lv_mem.c...
lib\lvgl\src\lv_misc\lv_mem.c(511): warning:  #111-D: statement is unreachable
                  return NULL;
lib\lvgl\src\lv_misc\lv_mem.c(521): warning:  #111-D: statement is unreachable
      return NULL;
lib\lvgl\src\lv_misc\lv_mem.c: 2 warnings, 0 errors
compiling lv_printf.c...
compiling lv_task.c...
compiling lv_utils.c...
compiling lv_txt_ap.c...
compiling lv_txt.c...
compiling lv_theme_empty.c...
compiling lv_theme.c...
compiling lv_theme_template.c...
compiling lv_bar.c...
compiling lv_arc.c...
compiling lv_btn.c...
compiling lv_theme_mono.c...
compiling lv_checkbox.c...
compiling lv_btnmatrix.c...
compiling lv_calendar.c...
lib\lvgl\src\lv_widgets\lv_calendar.c(447): warning:  #111-D: statement is unreachable
          return LV_RES_OK;
lib\lvgl\src\lv_widgets\lv_calendar.c: 1 warning, 0 errors
compiling lv_theme_material.c...
compiling lv_cont.c...
compiling lv_canvas.c...
compiling lv_chart.c...
compiling lv_cpicker.c...
compiling lv_gauge.c...
compiling lv_imgbtn.c...
compiling lv_dropdown.c...
compiling lv_keyboard.c...
compiling lv_img.c...
compiling lv_led.c...
compiling lv_line.c...
compiling lv_objx_templ.c...
compiling lv_linemeter.c...
compiling lv_msgbox.c...
compiling lv_objmask.c...
compiling lv_label.c...
compiling lv_list.c...
compiling lv_spinner.c...
compiling lv_switch.c...
compiling lv_spinbox.c...
compiling lv_slider.c...
compiling lv_roller.c...
compiling lv_page.c...
compiling lv_table.c...
compiling lv_tileview.c...
compiling lv_win.c...
compiling lv_tabview.c...
compiling lv_textarea.c...
compiling stm32f4xx_hal_rcc_ex.c...
compiling stm32f4xx_hal_flash.c...
compiling stm32f4xx_hal_flash_ex.c...
compiling fonts.c...
compiling ILI9341_GFX.c...
compiling stm32f4xx_hal_rcc.c...
compiling stm32f4xx_hal_spi.c...
compiling stm32f4xx_hal_pwr_ex.c...
compiling stm32f4xx_hal_flash_ramfunc.c...
compiling stm32f4xx_hal_gpio.c...
compiling stm32f4xx_hal_cortex.c...
compiling stm32f4xx_hal_pwr.c...
compiling stm32f4xx_hal_dma.c...
compiling stm32f4xx_hal_dma_ex.c...
compiling stm32f4xx_hal_tim.c...
compiling stm32f4xx_hal_exti.c...
compiling stm32f4xx_hal_tim_ex.c...
compiling stm32f4xx_hal.c...
linking...
Program Size: Code=88752 RO-data=14488 RW-data=300 ZI-data=112052  
FromELF: creating hex file...
"lvgl_test\lvgl_test.axf" - 0 Error(s), 7 Warning(s).
Build Time Elapsed:  00:00:17

What it can be else ?)

keep your delay function call

Like this?

  while (1)
  {
		lv_task_handler();
		HAL_Delay(5);
		lv_tick_inc(5);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

There are no changes

Привет Глеб. У меня так…
while(1) {
lv_task_handler();
delay_ms(5);
}
вызывается каждые 5 мс.
void TIM4_IRQHandler(void)
{
if (RESET != TIM_GetITStatus(TIM4, TIM_IT_Update))
{
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
lv_tick_inc(5);
}
}

Привет! Пожалуй, я буду писать на английском для более широкой публики :slight_smile:
I created a timer interrupt for every 5ms but the problem not in lv_tick_inc();.


void TIM1_UP_TIM10_IRQHandler(void)
{
  /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 */

  /* USER CODE END TIM1_UP_TIM10_IRQn 0 */
  HAL_TIM_IRQHandler(&htim1);
  /* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */
	lv_tick_inc(5);
	HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
  /* USER CODE END TIM1_UP_TIM10_IRQn 1 */
}

I have debug my code and fond out some interesting.
My program crushes when entering to the lv_task_handler(); on the line 133 in lv_task.c :

else {
                if(lv_task_exec(LV_GC_ROOT(_lv_task_act))) {
                    if(!task_created && !task_deleted) {
                        task_interrupter = LV_GC_ROOT(_lv_task_act); /*Check all tasks again from the highest priority */
                        end_flag         = false;
                        break;
                    }
                }
            }

It is printig the button without text in if(lv_task_exec(LV_GC_ROOT(_lv_task_act))) and stops everything. Even interrupt not working.
I started to read all information about lv_task_handler(); and not found a solution yet.

void TIM1_UP_TIM10_IRQHandler(void)
{
if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM1, TIM_IT_Update); // Очистить флаг прерывания
lv_tick_inc(5);
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
}
}

In the interrupt handler, add the following line of code TIM_ClearITPendingBit (TIM1, TIM_IT_Update); (reset the interrupt flag) otherwise, once the program gets there, it will not exit.

What is your stack size?

O my god!!
It works!!!))))
I am so happy!))

My stack size was 0x400 -> 1 kB
I changed it to 0x2000 -> 8 kB

And I not added the reset interrupt flag in my timer interrupt. I don`t know is it nessesary but it works good )


It works!
Thank you all guys !!!))))
Тебе тоже спасибо Дима!

I need to read the documentation more carefully.
https://docs.lvgl.io/latest/en/html/intro/index.html

Глеб очень рад, что у темя все получилось, удачи…