Hi,
This is caused by the fact your custom section (placed into RAM) is actually included in your project binary image.
The original linker script below needs to be modified.
MEMORY
{
...
/* SRAM_U */
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00007000
}
...
/* Custom Section Block that can be used to place data at absolute address. */
/* Use __attribute__((section (".customSection"))) to place data here. */
.customSectionBlock ORIGIN(m_data_2) :
{
KEEP(*(.customSection)) /* Keep section even if not referenced. */
} > m_data_2
The original linker script tells the linker to place the data section directly at 0x2000_0000 so it makes a huge gap in binary image of your app. Basically the gap begins at the code end address (e.g. 0x0000_91e8) in flash and ends at the beginning of RAM (0x2000_0000)
S-record allows gaps so the size is relatively small but the binary raw image is a continuous memory block without any gaps - this causes it is so huge.
I assume this is not intended in your case since the project should run from Flash.
Therefore you should create a ROM image of your RAM section and let startup routine to perform ROM-to-RAM copy-down.
I'd suggest you to adjust the linker script file in order to create the ROM images for your custom RAM sections + avoid loading of uninitialized sections such as BSS, STACK, HEAP (see below the snippet of updated script file)
.
__DATA_END = __DATA_ROM + (__data_end__ - __data_start__);
__CODE_ROM = __DATA_END; /* Symbol is used by code initialization. */
.code : AT(__CODE_ROM) /* Load the section image at ROM address __CODE_ROM*/
{
. = ALIGN(4);
__CODE_RAM = .;
__code_start__ = .; /* Create a global symbol at code start. */
*(.code_ram) /* Custom section for storing code in RAM */
. = ALIGN(4);
__code_end__ = .; /* Define a global symbol at code end. */
} > m_data
__CODE_END = __CODE_ROM + (__code_end__ - __code_start__);
__CUSTOM_ROM = __CODE_END;
/* Custom Section Block that can be used to place data at absolute address. */
/* Use __attribute__((section (".customSection"))) to place data here. */
.customSectionBlock : AT(__CUSTOM_ROM) /* Load the section image at __CUSTOM_ROM*/
{
__CUSTOM_RAM = .; /* Create Symbol used by startup to copydown*/
__custom_start__ = .; /* Define a global symbol at start. */
KEEP(*(.customSection)) /* Keep section even if not referenced. */
__custom_end__ = .; /* Define a global symbol at end. */
} > m_data_2
/* Create Symbol used by startup to copydown*/
__CUSTOM_END = __CUSTOM_ROM + (__custom_end__ -__custom_start__);
/* Uninitialized data section. */
.bss (NOLOAD) : /* Do not init this section */
{
/* This is used by the startup in order to initialize the .bss section. */
. = ALIGN(4);
__BSS_START = .;
__bss_start__ = .;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(4); __bss_end__ = .;
__BSS_END = .;
} > m_data_2
.heap (NOLOAD): /* Do not init this section */
{
. = ALIGN(8);
__end__ = .;
PROVIDE(end = .);
PROVIDE(_end = .);
PROVIDE(__end = .);
__HeapBase = .;
. += HEAP_SIZE;
__HeapLimit = .;
__heap_limit = .;
} > m_data_2
.stack (NOLOAD): /* Do not init this section */
{
. = ALIGN(8);
. += STACK_SIZE;
} > m_data_2
The final step is to adjust the startup routine to initialize the custom RAM section.
Go to file "startup.c" located "/App_demo/SDK/platform/devices/startup.c"
You should add the custom section symbols + custom initialization sequence:
void init_data_bss(void)
{
...
uint8_t * custom_ram;
...
const uint8_t * custom_rom, * custom_rom_end;
...
extern uint32_t __CUSTOM_RAM[];
extern uint32_t __CUSTOM_ROM[];
extern uint32_t __CUSTOM_END[];
...
custom_ram = (uint8_t *)__CUSTOM_RAM;
custom_rom = (uint8_t *)__CUSTOM_ROM;
custom_rom_end = (uint8_t *)__CUSTOM_END;
....
while (custom_rom_end != custom_rom)
{
*custom_ram = *custom_rom;
custom_ram++;
custom_rom++;
}
Attached is the modified project for you reference.
Hope it helps.
Stan