2021-06-04 10:22 PM
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
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?
Solved! Go to Solution.
2021-06-05 11:58 AM
@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.
2021-06-05 06:39 AM
> 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.
2021-06-05 07:45 AM
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.
2021-06-05 11:58 AM
@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.
2021-06-05 01:17 PM
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.