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!