cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable compiler/linker to manage external memory?

Hansel
Senior

I've managed to get the SDRAM up and running on my STM32H745 Disco board. I've confirmed this by using

uint32_t* sdram = (uint32_t*) 0xD0000000;
sdram[0] = 0xDEADBEEF;

and checking the memory content. However, doing it this way, I have to control the address space myself.

Instead I want the linker to assign the address space automatically. I've made sure the linker script is set up properly as explained in the document linked here. The Build Analyzer confirms the correct assignment. However, As soon as I use code like this

// This part is declared globally
__attribute__((section(".sdram"))) uint32_t sdram[1000];
 
// This is in main()
sdram[0] = 0xDEADBEEF;

I get the dreaded

0693W00000BaAfeQAF.png 

Note that I've declared the variable as global because if I try to declare it locally inside main() just before the assignment of DEADBEEF to sdram[0], the compiler barfs.

How do I get the linker to recognize the definition of the variable sdram and have it memory managed?

1 ACCEPTED SOLUTION

Accepted Solutions
Hansel
Senior

@TDK​ , I should have said "the compiler barfs with that same message above".

@TDK​ , @Community member​ Your hint regarding NOINIT sent me in the right direction. All I had to do is adding a (NOLOAD) after the sdram section in my linker script:

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

Now it works as expected. Thanks for your help.

View solution in original post

4 REPLIES 4
TDK
Guru

> the compiler barfs

Please be more descriptive in the errors you encounter. You're the only one seeing the error messages. Copy/paste is very easy to do and helpful for those trying to assist.

You should mark the array as NOINIT, otherwise it'll try to load it from flash.

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

For the linker you'd need a suitable linker script

For the debugger you'd either need a script there to bring up the external memory like RAM, or an external loader.

A TDK points out making it NOINIT or NOLOAD stops the linker attempting to copy in initialized data.

To get initialized data you'd need to make sure code in SystemInit() brings up the external memory, and code in startup.s moves the data in there.

You should perhaps review other existing projects and linker scripts to get the feel of things.

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

@TDK​ , I should have said "the compiler barfs with that same message above".

@TDK​ , @Community member​ Your hint regarding NOINIT sent me in the right direction. All I had to do is adding a (NOLOAD) after the sdram section in my linker script:

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

Now it works as expected. Thanks for your help.

TDK
Guru

Glad you got it working. There may be a more descriptive error message in the Console tab, rather than the popup message which is sort of generic. Might help in the future.

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