cancel
Showing results for 
Search instead for 
Did you mean: 

How Can I define a SDRAM usage in the Script Linker.

BTang
Associate II

Hello, everyone:

I just migrate my development job from MDK to STM32CubeIDE. But I've got a little problem, details as follows:

1.environment

STM32H750 + SDRAM(FMC), with bootloader in the AXI flash,but app was copied from spiFlash to AXI SRAM by the bootloader when system starts.

2.problem

when I DO my job on the MDK, i can define an huge array in the SDRAM using the statement like this:

unsigned char MemoryEx_Pool[MEMORY_EX_MAX_SIZE] __attribute__((at(SDRAM_BANK_1_ADDR)));

where SDRAM_BANK_1_ADDR is defined as the start address of FMC 0xC0000000. Then nothing left to do, the compiler tools can deal with this automatically well. But on STM32CubeIde, it seems not that easy to get this work, I made some changes while migrating from MDK Project:

1). I changed my statement in the source code to define this array in the sdramas follows:

__attribute__((section(".sdram"))) unsigned char MemoryEx_Pool[MEMORY_EX_MAX_SIZE];

here i intend to put this huge uninitialized array into section 'sdram' defined in the linker script later.

2). i chaged Memory definition a little bit in the linker script:

/* Memories definition */
MEMORY
{
    FLASH	(rx)	: ORIGIN = 0x8000000,	LENGTH = 128K
    DTCMRAM	(rwxa)	: ORIGIN = 0x20000000,	LENGTH = 128K
    IMAGE   (rwx)   : ORIGIN = 0x24000000,  LENGTH = 350K
    RAM_D1	(rwx)	: ORIGIN = 0x24057800,	LENGTH = 162K
    ITCMRAM	(rwx)	: ORIGIN = 0x00000000,	LENGTH = 64K
    RAM_D3	(rwx)	: ORIGIN = 0x38000000,	LENGTH = 64K
    RAM_D2	(rwx)	: ORIGIN = 0x30000000,	LENGTH = 288K
    SDRAM 	(rwxa)  : ORIGIN = 0xC0000000,  LENGTH = 16384K
}

here I split AXI SRAM into 2 parts, IMAGE(350k) for the app program image and RAM_D1(162K) for data use. And I add SDRAM definition here for use.

3).in the SECTION area of linker script , I put sdram input section to the SDRAM as follows:

  .sdram_section :
  {
    . = ALIGN(4);
    __SDARAM_START__ = .;
    *(.sdram)
    *(.sdram*)
    . = ALIGN(4);
    __SDRAM_END__ = .;
  } >SDRAM

here I intend to put this huge uninitialized array (MemoryEx_Pool) defined in the soucre file to SDRAM.

THE PROBLEM IS : I got a huge .bin (about 2.2G ) after i comile and link the project while the .elf is about 13M. I inspect the build information as follows:

10:57:39 **** Incremental Build of configuration Debug for project CP300_BiSun_New ****
make -j6 all 
arm-none-eabi-size   CP300_BiSun_New.elf 
   text	   data	    bss	    dec	    hex	filename
 260020	13617084	 126936	14004040	 d5af48	CP300_BiSun_New.elf
Finished building: default.size.stdout

the most huge part is data. it seems that the huge uninitialized array was taken into the data area and copied into the program image, but from what i understand ,it should be put into the bss.

so i want to ask:

1.where linker put my self-defined section to? for example i defined a sdram_section output section in the linker script,but i didn't see it in the build output information.

2.why my uninitialized huge array was put to the data section, from what i understand ,this data section is for the initialized data use.

3.why my .bin is so huge, how can i avoid this? how should i modify linker script if i want to use this sdram , for example, define an variable or array in it?

i really have no idea , i hope someone can help me out,relly appreciate!😀

1 ACCEPTED SOLUTION

Accepted Solutions
Ethan HUANG
ST Employee

Hi Candy,

I read this interesting questions days ago but found myself not able to completely answer them. So, I spent some time to figure it out (mostly for how arm-none-eabi-size deals with the size of text/data/bss). Even there are to me still lots of mysterious parts inside ELF handling, I share what I did by attaching the PDF and hope to answer your questions #1 and #2 clearly enough while #3 is perfectly answered by Clive.

For your question regarding missing functions, I am curious if you put those functions in .sdram_section?

Regards,

Ethan

View solution in original post

4 REPLIES 4

It is huge because binaries can't be sparse like .HEX files.

If you want it packed into FLASH, you'll need to use >SDRAM AT> FLASH

Code and symbols will be needed to be created so you can unpack it in your new startup.c code, after you bring up the SDRAM

If you want it not to create binary data you should perhaps define the segment as .sdram_section (NOLOAD) :

Review the .MAP file to review/confirm placement

Keil does this better, GNU/GCC require a lot more manual labour to get it to work the way you want it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

YES, I made it by taking your advice : to mark the sdram_section  as NOLOAD type and i get a 300k .bin. I find that the bss now become very huge but it's ok because bss won't be packed into image. I still don't understand why uninitialized array was put into data section instead of bss when there is no NOLOAD type for sdram_section.

and one more question: after i load this 300k image into the AXI SRAM, the system brings up as what i expect, that's good. but I found some functions in the program was missing(or maybe just cannnot work as what I expected), for example ,system cannot detect usb-disk. and if i adjust the compile optimization to O1 or higher , the emwin display would go wrong with some icons wigets or even no touch reaction on the screen. I found this probelm on MDK too....there would be some disorders in the system function if i change the compile optimization level, what might be the reason of this, do I have to optimize my code ?

Ethan HUANG
ST Employee

Hi Candy,

I read this interesting questions days ago but found myself not able to completely answer them. So, I spent some time to figure it out (mostly for how arm-none-eabi-size deals with the size of text/data/bss). Even there are to me still lots of mysterious parts inside ELF handling, I share what I did by attaching the PDF and hope to answer your questions #1 and #2 clearly enough while #3 is perfectly answered by Clive.

For your question regarding missing functions, I am curious if you put those functions in .sdram_section?

Regards,

Ethan

Dear Ethan,

thanks for your reply and all of your impressive works on this.Maybe this question is too much more about build tools...I learned a lot from what you've down.I'll use the tools you mentioned in this demonstration to analyze and verify some of the arm-none-eabi utilities. As for the function disorder I mentioned before ,what refused me a lot is that sometimes, the system would behave totally diffrent if I change the compile optimization level.(for example, if I use -O0, everything behaves as what i expected.But if I adjust optimization level to -O1, the heater of the system will be out of control). I believe i have to work more on the code debugging...HAHA.

Best Regards,

candylife91