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 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.
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.