cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE placing variable on specific addres in external SDRAM

Petr3
Associate III

Hello,

i need help how to edit linker file for placing array on specific address in external SDRAM connected via FMC.

I'm working with 7" TFT 800x480 @ 24bpp via LTDC controller and i have configuration 2 layers and both double buffered. So in HW is connected external SDRAM 8MB four banks (2MBx4). I would like to use each bank for one buffer as recommended in AN4861 https://www.st.com/resource/en/application_note/an4861-lcdtft-display-controller-ltdc-on-stm32-mcus-stmicroelectronics.pdf.

I added SDRAM and SDRAM section into linker script as follows:

SDRAM (rwx) : ORIGIN = 0xC0000000, LENGTH = 8192K

...

...

.sdram (NOLOAD) :
{
. = ALIGN(4);
*(.sdram .sdram.*)
} > SDRAM

 

But i don't know how to place four buffers into start address of each SDRAM bank.

I tried to create 4 SDRAM sections instead of one:

SDRAM0 (rwx) : ORIGIN = 0xC0000000, LENGTH = 2048K
SDRAM1 (rwx) : ORIGIN = 0xC0200000, LENGTH = 2048K
SDRAM2 (rwx) : ORIGIN = 0xC0400000, LENGTH = 2048K
SDRAM3 (rwx) : ORIGIN = 0xC0600000, LENGTH = 2048K

...

...

/* external SDRAM0 */
.sdram0 (NOLOAD) :
{
. = ALIGN(4);
*(.sdram0 .sdram0.*)
} > SDRAM0

/* external SDRAM1 */
.sdram1 (NOLOAD) :
{
. = ALIGN(4);
*(.sdram1 .sdram1.*)
} > SDRAM1

/* external SDRAM2 */
.sdram2 (NOLOAD) :
{
. = ALIGN(4);
*(.sdram2 .sdram2.*)
} > SDRAM2

/* external SDRAM3 */
.sdram3 (NOLOAD) :
{
. = ALIGN(4);
*(.sdram3 .sdram3.*)
} > SDRAM3

 

and declare variables as:

uint32_t lcd_buffer0[288000] __attribute__((section(".sdram0")));
uint32_t lcd_buffer1[288000] __attribute__((section(".sdram1")));
uint32_t lcd_buffer2[288000] __attribute__((section(".sdram2")));
uint32_t lcd_buffer3[288000] __attribute__((section(".sdram3")));

 

But i don't know if it's correct approach.

 

Can you help me how to do it?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

That is the correct approach. Does it compile and work? Might be missing some subtle syntax but the idea is correct.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

That is the correct approach. Does it compile and work? Might be missing some subtle syntax but the idea is correct.

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

@Petr3 You don't even need to touch the link script. Just define the addresses as standard C pointers with absolute values. For example 

#define lcd_buffer0 ((uint8_t*)0xC0000000)
....
#define lcd_buffer3 ((uint8_t*)0xC0600000)

 

Petr3
Associate III

Yes, it seems to work fine. List file shows, that buffers are placed on correct adddres in external SDRAM.