Hardfault error


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

STM32F103RCT6 (RAM 48 KB, custom board)
display: 128*160, RGB565(16 bit), ST7735/ST7789 lcd driver


What LVGL version are you using?

the latest one (v8.0)

What do you want to achieve?

To solve the hard fault error.
It occurs when lv_task_handler() is called or lv_scr_act() is called (I guess)
I think it is not caused by memory size, I’ve changed several times.

What have you tried so far?

check the flush function, test if the lv_task_handler() is called.

The display is connected with SPI (8 bit) comm to mcu.
I’m not sure where the hard fault occurs, I stepped in the function (from lv_scr_act()) deeper, I cannot find the cause.
When I deleted the creating label part, the error occurred as calling the lv_task_handler().
On the other hands, the error occurred as calling the lv_obj_create() when I deleted lv_task_handler().
It was fallen in hardfault error when calling the event function, but I can’t be sure.

Code to reproduce


/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX 128
#define LV_VER_RES_MAX 160

/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH     16

/*Swap the 2 bytes of RGB565 color. Useful if the display has a 8 bit interface (e.g. SPI)*/
#define LV_COLOR_16_SWAP   1

/*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
#define LV_MEM_CUSTOM      0
#if LV_MEM_CUSTOM == 0
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
#  define LV_MEM_SIZE    (16U * 1024U)          /*[bytes]*/

/*Use a custom tick source that tells the elapsed time in milliseconds.
 *It removes the need to manually update the tick with `lv_tick_inc()`)*/
#define LV_TICK_CUSTOM     0

Heap, Stack size in STM32F103RCTX_FLASH.ld

/* Highest address of the user mode stack */
_estack = ORIGIN(RAM) + LENGTH(RAM);	/* end of "RAM" Ram type memory */

_Min_Heap_Size = 0x2800 ;	/* required amount of heap  */
_Min_Stack_Size = 0x2800 ;	/* required amount of stack */

/* Memories definition */
  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 48K
  FLASH    (rx)    : ORIGIN = 0x8000000,   LENGTH = 256K


int main(void)
  /* Initialize all configured peripherals */ (I deleted)

  App_Start();            // App_Start(): contains all other process


App_Start() // it is declared other source code file, not main.c.

void App_Start(void)
        // uart set
		HAL_UART_Receive_IT(&huart1, _rxBuffer1, RX_BUF_SIZE);

       // lvgl and lcd driver configuation 
		LCD_Init(); // lcd driver initialization function 
		LCD_Clear(0xffff); // lcd driver function - clear the lcd with white
		lv_config_main(); // lvgl configuration function

       // create label
	    lv_obj_t * label1 =  lv_label_create(lv_scr_act(), NULL);
	    lv_label_set_text(label1, "Hello world!");



void LCD_flush(lv_disp_drv_t * drv, const lv_area_t * area,  lv_color_t * color_map)
	lv_color_t color = *color_map;
	    for(y = area->y1; y <= area->y2; y++) {
	        for(x = area->x1; x <= area->x2; x++) {
	        	LCD_DrawPaint(x, y, (uint16_t)color.full);    // set the color pixel by pixel
	DEV_Digital_Write(DEV_CS_PIN, 1);    // set the cs pin set/reset function

SPI comm setting


Had the same issue one week ago:
Please check if your driver is static:

Thanks a lot!
I declared the disp_drv as static, I could watch the code was running.
In the log, the time was counting and initialization of screen was done, the screen was colored with white.

However, I was failed to create an object and the hard fault error showed up again(when I added the example, lv_example_get_started_1())
Hard fault doesn’t show up when I just added the label creation lines, the label wasn’t created, though.
(the code is below)

		 lv_obj_t * label1 =  lv_label_create(lv_scr_act(), NULL);
		 lv_label_set_text(label1, "Hello world!");
		 lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 20, 40);

Although I haven’t solved the problem yet, your comment is quite useful :kissing_heart:
v8 is hard to import because there is no documentation update for the latest version.
Please let me know if you know other references to learn lvgl v8 :grinning: