STM32F769 Customboard bring up: Active/Focused elements are getting visually doubled

Description

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

STM32F769NI, Custom Board with 64Mb SDRAM
Compiler: GNU Arm Embedded Toolchain
Display: 800x480 RGB Controller ST762

What do you want to achieve?

Running LVGL without strange visual errors. When I switch through the GUI objects with an encoder the focused elements are getting visually doubled right next to themselves. Tried the same GUI logic in a simulator and everything works fine.

What have you tried so far?

Using the keypad & encoder example from lv_examples as test UI.
LVGL is setup to use DMA2D as GPU. The display flush function uses DMA. Also implemented VSYNC via LTDC line event but disabled it to exclude it as possible source of errors.
Tried RGB and DSI interface (board supports both). Issue exists on both interfaces and 2 different displays.

Code to reproduce

/**
 * @file tft.c
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include "lv_conf.h"
#include "lvgl/lvgl.h"
#include <string.h>

#include "bsp/tft.h"
#include "bsp/ili9806e.h"
#include "stm32f7xx_hal.h"
#include "main.h"

/*********************
 *      DEFINES
 *********************/

/* DMA Stream parameters definitions. You can modify these parameters to select
   a different DMA Stream and/or channel.
   But note that only DMA2 Streams are capable of Memory to Memory transfers. */
#define DMA_STREAM               DMA2_Stream0
#define DMA_CHANNEL              DMA_CHANNEL_0
#define DMA_STREAM_IRQ           DMA2_Stream0_IRQn
#define DMA_STREAM_IRQHANDLER    DMA2_Stream0_IRQHandler

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/*For LittlevGL*/
static void tft_flush_cb(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p);

/*LCD*/
static void LCD_Config(void);
void BSP_LCD_Reset(void);
void BSP_LCD_MspInit(void);

/*DMA to flush to frame buffer*/
static void DMA_Config(void);
static void DMA_TransferComplete(DMA_HandleTypeDef *han);
static void DMA_TransferError(DMA_HandleTypeDef *han);

/**********************
 *  STATIC VARIABLES
 **********************/

extern LTDC_HandleTypeDef hltdc;
extern DSI_HandleTypeDef hdsi;

__IO uint16_t *FrontBuffer = (__IO uint16_t*)(LCD_FB_START_ADDRESS);
__IO uint16_t *BackBuffer = (__IO uint16_t*) (LCD_FB_START_ADDRESS + 1024 * 1024 * 16);             // Only used when VSYNC active

//__IO uint16_t __attribute__((section(".extbss"))) ltdc_fb[TFT_HOR_RES * TFT_VER_RES];
__IO uint16_t *ltdc_fb;
//static lv_color_t __attribute__((section(".extbss"))) lvgl_buffer1[TFT_HOR_RES * TFT_VER_RES];
//static lv_color_t __attribute__((section(".extbss"))) lvgl_buffer2[TFT_HOR_RES * TFT_VER_RES];
static lv_disp_t *tft_disp = NULL;

DMA_HandleTypeDef     DmaHandle;
static lv_disp_drv_t disp_drv;
static int32_t x1_flush;
static int32_t y1_flush;
static int32_t x2_flush;
static int32_t y2_fill;
static int32_t y_fill_act;
static const lv_color_t * buf_to_flush;
static volatile uint32_t t_saved = 0;
static volatile bool refr_qry = false;
/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/

/**
 * Monitor refresh time
 * */
void monitor_cb(lv_disp_drv_t * d, uint32_t t, uint32_t p)
{
    t_saved = t;
}

/**
 * Initialize your display here
 */
void tft_init(void)
{
	LCD_Config();
	DMA_Config();
	static lv_color_t lvgl_buffer1[LV_HOR_RES_MAX  * 48];
	static lv_color_t lvgl_buffer2[LV_HOR_RES_MAX  * 48];
	static lv_disp_buf_t disp_buf;

	lv_disp_buf_init(&disp_buf, lvgl_buffer1, lvgl_buffer2,LV_HOR_RES_MAX  * 48);
	ltdc_fb = FrontBuffer;
	lv_disp_drv_init(&disp_drv);
	disp_drv.hor_res = 800;
    disp_drv.ver_res = 480;
    disp_drv.flush_cb = tft_flush_cb;
	disp_drv.monitor_cb = monitor_cb;
	disp_drv.buffer = &disp_buf;

	tft_disp = lv_disp_drv_register(&disp_drv);
}

/**********************
 *   STATIC FUNCTIONS
 **********************/
static void tft_flush_cb(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p)
{
    int32_t x1 = area->x1;
    int32_t x2 = area->x2;
    int32_t y1 = area->y1;
    int32_t y2 = area->y2;
    /*Return if the area is out the screen*/

    if(x2 < 0) return;
    if(y2 < 0) return;
    if(x1 > TFT_HOR_RES - 1) return;
    if(y1 > TFT_VER_RES - 1) return;

    /*Truncate the area to the screen*/
    int32_t act_x1 = x1 < 0 ? 0 : x1;
    int32_t act_y1 = y1 < 0 ? 0 : y1;
    int32_t act_x2 = x2 > TFT_HOR_RES - 1 ? TFT_HOR_RES - 1 : x2;
    int32_t act_y2 = y2 > TFT_VER_RES - 1 ? TFT_VER_RES - 1 : y2;

    x1_flush = act_x1;
    y1_flush = act_y1;
    x2_flush = act_x2;
    y2_fill = act_y2;
    y_fill_act = act_y1;
    buf_to_flush = color_p;

    SCB_CleanInvalidateDCache();
    SCB_InvalidateICache();
    /*##-7- Start the DMA transfer using the interrupt mode #*/
    /* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */
    /* Enable All the DMA interrupts */
    HAL_StatusTypeDef err;
    uint32_t length = (x2_flush - x1_flush + 1);

    err = HAL_DMA_Start_IT(&DmaHandle,(uint32_t)buf_to_flush, (uint32_t)&ltdc_fb[y_fill_act * TFT_HOR_RES + x1_flush],
                           length);
    if(err != HAL_OK)
    {
        while(1);	/*Halt on error*/
    }
}

static void LCD_Config(void)
{
	/* Toggle Hardware Reset of the DSI LCD using
	 * its XRES signal (active low) */

	/* Call first MSP Initialize only in case of first initialization
	 * This will set IP blocks LTDC, DSI and DMA2D
	 * - out of reset
	 * - clocked
	 * - NVIC IRQ related to IP blocks enabled
	 */
  BSP_LCD_MspInit();
  BSP_LCD_Reset();
    for(uint32_t i = 0; i < (TFT_HOR_RES * TFT_VER_RES) ; i++)
    {
        FrontBuffer[i] = 0;
//        BackBuffer[i] = 0;
    }

    /* Start DSI */
	HAL_Delay(10);
}

/**
  * @brief  Configure the DMA controller according to the Stream parameters
  *         defined in main.h file
  * @note  This function is used to :
  *        -1- Enable DMA2 clock
  *        -2- Select the DMA functional Parameters
  *        -3- Select the DMA instance to be used for the transfer
  *        -4- Select Callbacks functions called after Transfer complete and
               Transfer error interrupt detection
  *        -5- Initialize the DMA stream
  *        -6- Configure NVIC for DMA transfer complete/error interrupts
  * @param  None
  * @retval None
  */
static void DMA_Config(void)
{
  /*## -1- Enable DMA2 clock #################################################*/
  __HAL_RCC_DMA2_CLK_ENABLE();

  /*##-2- Select the DMA functional Parameters ###############################*/
  DmaHandle.Init.Channel = DMA_CHANNEL;                     /* DMA_CHANNEL_0                    */
  DmaHandle.Init.Direction = DMA_MEMORY_TO_MEMORY;          /* M2M transfer mode                */
  DmaHandle.Init.PeriphInc = DMA_PINC_ENABLE;               /* Peripheral increment mode Enable */
  DmaHandle.Init.MemInc = DMA_MINC_ENABLE;                  /* Memory increment mode Enable     */
  DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; /* Peripheral data alignment : 16bit */
  DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;    /* memory data alignment : 16bit     */
  DmaHandle.Init.Mode = DMA_NORMAL;                         /* Normal DMA mode                  */
  DmaHandle.Init.Priority = DMA_PRIORITY_HIGH;              /* priority level : high            */
  DmaHandle.Init.FIFOMode = DMA_FIFOMODE_ENABLE;            /* FIFO mode enabled                */
  DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL; /* FIFO threshold: 1/4 full   */
  DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE;              /* Memory burst                     */
  DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE;           /* Peripheral burst                 */

  /*##-3- Select the DMA instance to be used for the transfer : DMA2_Stream0 #*/
  DmaHandle.Instance = DMA_STREAM;

  /*##-4- Initialize the DMA stream ##########################################*/
  if(HAL_DMA_Init(&DmaHandle) != HAL_OK)
  {
    while(1);
  }

  /*##-5- Select Callbacks functions called after Transfer complete and Transfer error */
  HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_CPLT_CB_ID, DMA_TransferComplete);
  HAL_DMA_RegisterCallback(&DmaHandle, HAL_DMA_XFER_ERROR_CB_ID, DMA_TransferError);

  /*##-6- Configure NVIC for DMA transfer complete/error interrupts ##########*/
  HAL_NVIC_SetPriority(DMA_STREAM_IRQ, 5, 0);
  HAL_NVIC_EnableIRQ(DMA_STREAM_IRQ);
}

/**
  * @brief  DMA conversion complete callback
  * @note   This function is executed when the transfer complete interrupt
  *         is generated
  * @retval None
  */
static void DMA_TransferComplete(DMA_HandleTypeDef *han)
{
    y_fill_act ++;

    if(y_fill_act > y2_fill) {
        SCB_CleanInvalidateDCache();
        SCB_InvalidateICache();
        //if(lv_disp_flush_is_last(&disp_drv)) refr_qry = true;              // For VSYNC,turned off for testing
        // else lv_disp_flush_ready(&tft_disp->driver);
        lv_disp_flush_ready(&tft_disp->driver);
    } else {
        uint32_t length = (x2_flush - x1_flush + 1);
        buf_to_flush += x2_flush - x1_flush + 1;
        /*##-7- Start the DMA transfer using the interrupt mode ####################*/
        /* Configure the source, destination and buffer size DMA fields and Start DMA Stream transfer */
        /* Enable All the DMA interrupts */

        if(HAL_DMA_Start_IT(han,(uint32_t)buf_to_flush, (uint32_t)&ltdc_fb[y_fill_act * TFT_HOR_RES + x1_flush],
                            length) != HAL_OK)
        {
            while(1);	/*Halt on error*/
        }
    }
}

/**
  * @brief  DMA conversion error callback
  * @note   This function is executed when the transfer error interrupt
  *         is generated during DMA transfer
  * @retval None
  */
static void DMA_TransferError(DMA_HandleTypeDef *han)
{
    while(1);
}


/**
  * @brief  This function handles DMA Stream interrupt request.
  * @param  None
  * @retval None
  */
void DMA_STREAM_IRQHANDLER(void)
{
    /* Check the interrupt and clear flag */
    HAL_DMA_IRQHandler(&DmaHandle);
}

/**
  * @brief  Initialize the BSP LCD Msp.
  * Do not DMA2D is initialized by LVGL
  */
void BSP_LCD_MspInit(void)
{
//  HAL_LTDC_ProgramLineEvent(&hltdc, 480);                                 // For VSYNC,turned off for testing
}

void BSP_LCD_Reset(void)
{
	HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_RESET);
	HAL_Delay(100);
	HAL_GPIO_WritePin(LCD_RESET_GPIO_Port, LCD_RESET_Pin, GPIO_PIN_SET);
}

void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc) {                // For VSYNC,turned off for testing
  if(refr_qry) {
   refr_qry = 0;
   if(ltdc_fb == FrontBuffer) {
     ltdc_fb = BackBuffer;
     LTDC_LAYER(hltdc, 0)->CFBAR = ((uint32_t)FrontBuffer);
     __HAL_LTDC_RELOAD_CONFIG(hltdc);
     lv_disp_flush_ready (&disp_drv);
   } else {
     ltdc_fb = FrontBuffer;
     LTDC_LAYER(hltdc, 0)->CFBAR = ((uint32_t)BackBuffer);
     __HAL_LTDC_RELOAD_CONFIG(hltdc);
     lv_disp_flush_ready (&disp_drv);
   }
  }
   HAL_LTDC_ProgramLineEvent(hltdc, 480);
}


Screenshot and/or video

GIF Animation of the strange behaviour is on giphy because the file exceeds 4Mb see link below:


Shorter example:

	disp_drv.hor_res = 800;
    disp_drv.ver_res = 480;

ILI9806E has 480 x 864 resolution

The include of the ILI9806E header is a leftover from a test with an DSI-Display. The example uses a 800x480 RGB-interface Display with ST762 controller.