How to put buffer into external SDRAM

Description

MCU goes to HardFault_Handler if I put buffer to external SDRAM and press any key on on screen keyboard. Other examples in lv_tutorials folder seem to work flawless.

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

STM32F746G-DISCO board

What do you want to achieve?

Put buffer into external SDRAM and use a full display sized buffer. May be double buffering

What have you tried so far?

I made some modification on linker script.
I also tried to create large memory objects and read/write them in order to check the functionality of the FSMC module. FSMC initialized with supplied BSP package and it seems to be working without any problems.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/* In linker script */
/* Specify the memory areas */
MEMORY
{
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 320K
FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 1024K
SDRAM (xrw)      : ORIGIN = 0xC0000000, LENGTH = 8192K // I added this line
}
(...)

.HeapMemSection : {*(.HeapMemSection)} >SDRAM // heap memory section for ext. SDRAM


/*In tft.c file*/
#define EXT_BUFFER 1
#if EXT_BUFFER
#define _buf_size (TFT_HOR_RES * TFT_VER_RES) 
static lv_color_t bufext_1[_buf_size] __attribute__((section(".HeapMemSection")));
#else
// this option works without any problems whatsoever
#define _buf_size (TFT_HOR_RES * 10) 
static lv_color_t bufext_1[_buf_size]; // variable in internal RAM
#endif
static uintpixel_t my_fb[TFT_HOR_RES * TFT_VER_RES] __attribute__((section(".HeapMemSection")));
static lv_disp_buf_t disp_buf_1;
(...)

lv_disp_buf_init(&disp_buf_1, bufext_1, NULL, _buf_size);   /*Initialize the display buffer*/


I see that you’ve put it in .HeapMemSection. Make sure the heap isn’t still using that space. :slightly_smiling_face:

Is the CPU cache enabled?

Yes CPU cache is enabled. LTDC is using SDRAM as framebuffer. I have double checked the addresses and sizes of the variables. They do not overlap.