2025-08-08 12:22 AM
Hi,Master:
MCU: stm32h743ii
IDE:keil
Question:
There is a 32M external SDRAM, and the scatter file is as follows:
LR_IROM1 0x08000000 0x00200000 { ; load region size_region
ER_IROM1 0x08000000 0x00200000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
*(_drv_set_)
.ANY (+RO)
.ANY (+XO)
}
...
EXT_SDRAM 0xC0000000 0x2000000 { ; RW data
*.o(ext_sdram)
}
}
Suppose there are some variables in the program that are specified to be located in 'ext_sdram' section.
static lv_color_t buff1[1024 * 600] __attribute__((used, section("ext_sdram")));
static lv_color_t buff2[1024 * 600] __attribute__((used, section("ext_sdram")));
...
During the scatter file loading, these variables will be initialized. Therefore, the external SDRAM needs to be initialized before the scatter file loading, as shown below:
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __low_level_init
IMPORT __main
LDR R0, =SystemInit
BLX R0
LDR R0, =__low_level_init
BLX R0
LDR R0, =__main
BX R0
ENDP
void __low_level_init(void)
{
DIS_INT();
sys_cache_enable();
HAL_Init();
sys_stm32_clock_init(192, 5, 2, 4); // init all clock
delay_init(480);
sdram_init();
}
Problems:
I think this approach does not elegantly solve the problem. Is there a more reasonable way to solve it? For example, prevent the scatter file from loading the ext_sdram section, thus eliminating the need to initialize the external SDRAM with __low_level_init before the scatter file loading.
Thank you very much!
Solved! Go to Solution.
2025-08-22 2:34 AM
This is not a question linked to STM32 MCU but to MDK-ARM toolchain (Keil). You need to contact them directly in their forum. But again you need to initialize the SDRAM before the scatter loading phase as I said before.
2025-08-21 1:24 AM
Hello,
You need to initialize the SDRAM in system_stm32h7xx.c / SystemInit().
Already implemented natively in the HAL: the SDRAM is initialized if DATA_IN_ExtSDRAM was defined by the user.
The initialization of the SDRAM is done with SystemInit_ExtMemCtl().
2025-08-21 6:27 PM
Hi, mƎALLEm
Currently, I haven't handled this by adding relevant initialization in the SystemInit() function. Instead, I've added the UNINIT modifier in the scatter file:
EXT_SDRAM 0xC0000000 UNINIT 0x2000000 { ; RW data
.ANY (ext_sdram)
}
And I've also added attribute modifiers to the variables:
__attribute__((zero_init, section("ext_sdram")))
I've found that after these operations, the EXT_SDRAM won't scatter-loading during the __main stage, thus eliminating the need for pre-initializing the external SDRAM in advance.
I discovered this approach through my own trials, but I'm not sure whether it's reasonable or not. I hope to get guidance from experts. Thank you very much.
2025-08-22 2:34 AM
This is not a question linked to STM32 MCU but to MDK-ARM toolchain (Keil). You need to contact them directly in their forum. But again you need to initialize the SDRAM before the scatter loading phase as I said before.
2025-08-22 6:27 PM
ok,Thank you for the good guidance