Загрузка данных


/* Include the base linker file */
#include <linker.ld>

/* Define the SDRAM data section with load address */
SECTIONS {
    .sdram_data : {
        __sdram_data_load_start = LOADADDR(.sdram_data);  /* Load address in FLASH */
        __sdram_data_start = .;  /* Start of section in SDRAM */

        /* Include all data in the sdram_data section */
        *(.sdram_data)
        *(.sdram_data.*)
        /* 
         * Align the section end to _region_min_align to ensure proper alignment.
         * The _region_min_align value is defined in the base linker file.
         */
        . = ALIGN(_region_min_align);
        __sdram_data_end = .;  /* End of the section */
    } > SDRAM AT > FLASH /* Place .sdram_data in SDRAM for execution, but load its initial content from FLASH. */
}

I also created an initialization function that relocates data from FLASH to SDRAM utilizing CONFIG_SOC_PREP_HOOK:
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>

#ifdef CONFIG_SOC_PREP_HOOK

extern char __sdram_data_load_start[];
extern char __sdram_data_start[];
extern char __sdram_data_end[];
void z_early_memset(void *dst, int c, size_t n);
void z_early_memcpy(void *dst, const void *src, size_t n);

/*  
 * This function is expected to be called from the `z_prep_c()` function in  
 * `zephyr/arch/arm/core/cortex_m/prep_c.c` when `CONFIG_SOC_PREP_HOOK` is  
 * enabled. The SoC hook is executed after the reset vector.  
 */
void soc_prep_hook(void)
{
    /* Clear and copy sdram_data from the load address to its destination in SDRAM */
    z_early_memset(&__sdram_data_start, 0,
                   (uintptr_t)&__sdram_data_end - (uintptr_t)&__sdram_data_start);

    z_early_memcpy((void *)&__sdram_data_start,
                   &__sdram_data_load_start,
                   __sdram_data_end - __sdram_data_start);
}
#endif