RAM overflowed when using rotating feature of canvas

Hi everyone,

Description

Currently, I am designing basic a watch face on STM32L4R9I Discovery. When I test the rotate feature on canvas (I used the example code from this site: https://docs.littlevgl.com/en/html/object-types/canvas.html#). I tested the rotating canvas using C and MicroPython.

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

STM32L4R9I Discovery

What do you experience?

Give a detailed description. “It doesn’t work” is not enough information for us to diagnose the issue.
On both platform, I experienced the same thing: ‘RAM’ overflowed by a certain number of bytes.

What do you expect?

I expect the canvas should be like the one in thelink above.

Code to reproduce

this is the code of my driver. the code of recreating rotating canvas, I took from the link above.

Use the ```c and ``` tags to format your code:

#include "lv_conf.h"
#include "display.h"
#include "lvgl/src/lv_hal/lv_hal.h"
#include "lvgl/lvgl.h"
#include "stm32l4xx_hal.h"
#include "stm32l4xx_hal_ltdc.h"
#include "stm32l4xx_hal_dma2d.h"
#include "stm32l4xx_hal_dsi.h"
#include "stm32l4xx_hal_rcc.h"
#include "stm32l4xx_hal_gfxmmu.h"

#include "stm32l4r9i_discovery.h"
#include "stm32l4r9i_discovery_lcd.h"
#include "stm32l4r9i_discovery_psram.h"

#include "log.h"

#define LAYER0_ADDRESS               GFXMMU_VIRTUAL_BUFFER0_BASE
#define ActiveLayer 				 LTDC_ACTIVE_LAYER_BACKGROUND
//**************STATIC PROTOTYPES**************

/* For LittlevGL */
static void my_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area,
		lv_color_t *color_p);
/* LCD */
/* RAM */
static void CopyBuffer(uint32_t *pSrc, uint32_t *pDst, uint16_t x, uint16_t y, uint16_t xsize, uint16_t ysize);
// ************STATIC VARIABLES***************

extern LTDC_HandleTypeDef hltdc_discovery;

extern DSI_HandleTypeDef hdsi_discovery;
DSI_VidCfgTypeDef hdsivideo_handle;
DSI_PLLInitTypeDef dsiPllInit;


static uint32_t *my_fb = (uint32_t*)LAYER0_ADDRESS;
static DMA2D_HandleTypeDef   hdma2d_discovery;
// ************ GLOBAL FUNCTION *************

// ********* initialize the display ***********

void tft_init(void) {
	log_debug("enter tft\r\n");
	/* Deactivate speculative/cache access to first FMC Bank to save FMC bandwidth */
	FMC_Bank1_R->BTCR[0] = 0x000030D2;
	BSP_PSRAM_Init();
	BSP_LCD_Init();
	BSP_LCD_SelectLayer(0);
	BSP_LCD_Refresh();

	static lv_disp_buf_t disp_buf;
	static lv_color_t buf1[390 * 10];
//	static lv_color_t buf2[390 * 10];
	lv_disp_buf_init(&disp_buf, buf1, NULL, 390 * 10);

	lv_disp_drv_t disp_drv;                 /*A variable to hold the drivers. Can be local variable*/
	lv_disp_drv_init(&disp_drv);            /*Basic initialization*/
	disp_drv.buffer = &disp_buf;            /*Set an initialized buffer*/
	log_debug("enter flush \r\n");
	disp_drv.flush_cb = my_flush_cb;
	log_debug("finish flush \r\n");
	//lv_disp_t * disp;/*Set a flush callback to draw to the display*/
	lv_disp_drv_register(&disp_drv); /*Regis ter the driver and save the created display objects*/
	log_debug("exit\r\n");
}

static void my_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_p) {
	log_debug("in my_flush,enter CopyBuffer\r\n");
	CopyBuffer((uint32_t*)color_p, my_fb, area->x1, area->y1, lv_area_get_width(area), lv_area_get_height(area));
	log_debug("in my_flush,exit CopyBuffer\r\n");
	BSP_LCD_Refresh();
	log_debug("in my_flush,enter FlushReady\r\n");
	lv_disp_flush_ready(drv);
	log_debug("in my_flush,exit FlushReady\r\n");
}

/**
  * @brief  Copy an input RGB888 buffer to output RGB888 with output offset
  * @param  pSrc: Pointer to source buffer
  * @param  pDst: Output color
  * @param  x: Start x position
  * @param  y: Start y position
  * @param  xsize: width
  * @param  ysize: height
  * @param  ColorMode: Input color mode
  * @retval None
  */

static void CopyBuffer(uint32_t *pSrc, uint32_t *pDst, uint16_t x, uint16_t y, uint16_t xsize, uint16_t ysize)
{
  uint32_t destination = (uint32_t)pDst + (y * 768 + x) * 4;
  uint32_t source      = (uint32_t)pSrc;

  hdma2d_discovery.Instance = DMA2D;

  /*##-1- Configure the DMA2D Mode, Color Mode and output offset #############*/
  hdma2d_discovery.Init.Mode           = DMA2D_M2M;
  hdma2d_discovery.Init.ColorMode      = DMA2D_OUTPUT_ARGB8888;
  hdma2d_discovery.Init.OutputOffset   = 768 - xsize; //// CHANGE FROM 1024 TO 768 TO FIX THE HORIZONTAL STRIBE
  hdma2d_discovery.Init.AlphaInverted  = DMA2D_REGULAR_ALPHA;  /* No Output Alpha Inversion */
  hdma2d_discovery.Init.RedBlueSwap    = DMA2D_RB_REGULAR;     /* No Output Red & Blue swap */
  hdma2d_discovery.Init.BytesSwap      = DMA2D_BYTES_REGULAR;  /* Regular output byte order */
  hdma2d_discovery.Init.LineOffsetMode = DMA2D_LOM_PIXELS;     /* Pixel mode                */

  /*##-2- Foreground Configuration ###########################################*/
  hdma2d_discovery.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888;
  hdma2d_discovery.LayerCfg[1].InputOffset    = 0;
  hdma2d_discovery.LayerCfg[1].AlphaMode      = DMA2D_NO_MODIF_ALPHA;
  hdma2d_discovery.LayerCfg[1].InputAlpha     = 0xFF;                /* Not used */
  hdma2d_discovery.LayerCfg[1].RedBlueSwap    = DMA2D_RB_SWAP; //DMA2D_RB_REGULAR;    /* No ForeGround Red/Blue swap */
  hdma2d_discovery.LayerCfg[1].AlphaInverted  = DMA2D_REGULAR_ALPHA; /* No ForeGround Alpha inversion */

  /* DMA2D Initialization */
  if(HAL_DMA2D_Init(&hdma2d_discovery) == HAL_OK)
  {
    if(HAL_DMA2D_ConfigLayer(&hdma2d_discovery, 1) == HAL_OK)
    {
      if (HAL_DMA2D_Start(&hdma2d_discovery, source, destination, xsize, ysize) == HAL_OK)
      {
        /* Polling For DMA transfer */
        HAL_DMA2D_PollForTransfer(&hdma2d_discovery, 10);
      }
    }
  }
}

I tried to increase the buffer size [390 * 20] but it did not work.

How can I fix this issue?

Thank you.

did you invalidate canvas?
void lv_obj_invalidate ( const lv_obj_t obj)

example;

void tos_analogClock_animation(lv_obj_t * analogsaat)
{
lv_mem_assert(analogsaat);

ext = lv_obj_get_ext_attr(analogsaat);
lv_obj_invalidate(analogsaat);
}

i got the error before. canvas sram is also kept as a bitmap, therefore swell in a big business and it can be overflow. if your sram overflow, you can try create one or more custom objects.
you can look at how I got the result;


Hi @nesetaydinn,

Thank you for your reply. I will give it a try and response to your later.

Huy

1 Like