How to put work_mem in SDRM?

Description

I want work_mem in function _lv_mem_init to be stored in SDRM.
I tried several methods but none of them worked. Either HardFault or memory allocation error

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

STM32F429

What LVGL version are you using?

V7.7.0

What do you want to achieve?

I want work_mem in function _lv_mem_init to be stored in SDRM.

Can you give a successful example?

What have you tried so far?

1、I put COLOR_BUF in SDRM and it works normally

uint16_t g_colorBuf[COLOR_BUF_SIZE] attribute((at(0XC0040000 )));
lv_disp_buf_init(&disp_buf, g_colorBuf, NULL, COLOR_BUF_SIZE);

2、I use the same method to put mem in SDRM but it doesn’t work。
uint32_t g_membase_SDRAM[MEM_SDRAM_MAX_SIZE] attribute((at(0XC0100000)));
work_mem = (uint8_t *)g_membase_SDRAM;

3、I try to define MEM_ADR 0XC0100000 or define MEM_ADR attribute((at(0XC0100000))) but it doesn’t work

Screenshot and/or video

First of all, you don’t need to modify lv_mem.c. There is a flag in lv_conf.h made for just this purpose.

Second of all, please test that the RAM at that address works normally first before trying to put LVGL things there. Perhaps this RAM is already being used by C library.

Hi, it doesn’t work.

Have you tested that the RAM works independently of LVGL? I would try a 200KB memset on the area.

As far as I know this setting works fine so I think this might be a problem with your platform.

I’m here again. Can you give me an email? I send you my code。

When I # define LV_MEM_ADR 0xC0080000, various errors are reported。Restore it back(I # define LV_MEM_ADR 0), everything is OK .
image

It sounds like the memory is being overwritten. Did you try the memset?

I tried it, but I still get errors.
image

@embeddedt

Sorry, but I don’t have the bandwidth at the moment to review individual projects.

I will ping @kisvegabor on this to see if he has any ideas, but this should be working without problems. The only logical explanation I see is that something else is using the memory or the memory is initialized improperly.

@kisvegabor I want to send my code to your mailbox. Can you help me see what is wrong?

My SDRAM is

I agree with @embeddedt regarding the possible causes.
I suggest trying this:

  1. Use the internal memory for LV_MEM
  2. memset(sram_addr, 0xaa, FULL_SIZE);
  3. Let the UI run
  4. See if 0xaa is preserved on the target address

1、everthing is OK.

2、This will cause an error, no matter if you use _lv_memset_00 or _lv_memset_ff or not use.

3、I have sent the demo to your Gmail mailbox @kisvegabor
image

Best excercise is not to use absolute address, instead use linker script to automatically locate your mem address to avoid memory colliding.

Hi @kisvegabor ,
Have you tried my code?
If this solution is feasible, I want to use lvgl to manage SDRAM .

I meant to set LV_MEM_ADR 0 to make LVGL run and use memset to see if that area is overwritten.

Do you want to test whether SDRAM can be memset? I tested this is ok.

No, I meant memset an LV_MEM_SIZE block from0xC0080000 to 0xaa, run LVGL with LV_MEM_ADR 0 and see if the 0xaa is retained in the SRAM.

You will see that if the frame buffer or something else overwrites SRAM from 0xC0080000.

This is no problem.

Please modify the code like this:

int i;
uint8_t * mem = (uint8_t *) t_mySDRAMbuf;
memset(mem, 0xaa LV_MEM_SIZE);
lv_demo_widgets();

for(i = 0; i < LV_MEM_SIZE; i++) {
  if(mem[i] != 0xaa) {
    while(1);  
  }
} 

while(1) {
  lv_task_handler();
  for(i = 0; i < LV_MEM_SIZE; i++) {
    if(mem[i] != 0xaa) {
      while(1);  
    }
  } 

 ...
}

And let the program run for a while, change tabs, etc.

The first check will not pass.
If a delay is added before and after memset, it is OK.