Skip to main content
Explorer
October 7, 2024
Question

Mbed: compile a function to a different memory location

  • October 7, 2024
  • 1 reply
  • 560 views

Using an stm32f746 disco, I'm trying to get a function to compile to a different memory location using Mbed. 

so far, as a test, i have this mbed_app.json..

{
 "target_overrides": {
 "*": {
 "target.ld_script": "custom_stm32f746.ld"
 }
 }
}
 
then this custom_stm32f746.ld...
/* Linker script to configure memory regions. */

MEMORY
{
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
CUSTOM_SECTION (rx) : ORIGIN = 0x080C0000, LENGTH = 128K
}

/* Define entry point */
ENTRY(Reset_Handler)

/* Section Definitions */
SECTIONS
{
.text :
{
*(.text)
*(.text.*)
} > FLASH

.custom_section :
{
KEEP(*(.custom_section))
} > CUSTOM_SECTION

.data :
{
*(.data)
} > RAM AT > FLASH

.bss :
{
*(.bss)
} > RAM

/* Other sections */
}

and this in my main.c..

__attribute__((section(".custom_section"))) void myFunction(void);

__attribute__((section(".custom_section"), used)) void myFunction() {

 printf("This function is at %0xH\n", (int) myFunction);

}

but the output is.... 

This function is at 8000259H

and using the cube programmer the memory at 80c0000 is unchanged

    This topic has been closed for replies.

    1 reply

    Super User
    October 7, 2024

    @andy0105 wrote:

     using Mbed. 


    Probably best to ask mbed-specific questions on the mbed forum:

    https://forums.mbed.com/

     

    How to post "pre-formatted" text - like linker scripts:

    https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/725146/highlight/true#M54

     

    Are you aware that Mbed End Of Life has been announced:

    https://forums.mbed.com/t/important-update-on-mbed-end-of-life/23644