cancel
Showing results for 
Search instead for 
Did you mean: 

Moving code to a different memory sector

ALane.1
Associate

I am currently saving user data to sector 7 on a STM32F446 board. I need to move that into one of the 16k sectors to keep the erase times small (would prefer to use sector 0, but any 16k sector will work). I am using a linker script to set up memory sections, and when I try to run my program it doesn't start.

The vector table and code are also saved to flash sectors, so what I need help with is moving the code to a different sector such that when I start the program it will load from whatever sector I have moved the code to.

Here is a snippet of my linker script BEFORE I started making changes to move sectors around:

MEMORY

{

RAM (xrw)     : ORIGIN = 0x20000000, LENGTH = 128K

FLASH (rx)     : ORIGIN = 0x8000000, LENGTH = 512K - 128k

DATA (rwx)     : ORIGIN = 0x08060000, LENGTH = 5120

}

/* Define output sections */

SECTIONS

{

 .user_data :

 {

   . = ALIGN(4);

   KEEP(*(.user_data))

   . = ALIGN(4);

 } >DATA

 /* The startup code goes first into FLASH */

 .isr_vector :

 {

   . = ALIGN(4);

   KEEP(*(.isr_vector)) /* Startup code */

   . = ALIGN(4);

 } >FLASH

 /* The program code and other data goes into FLASH */

 .text :

 {

   . = ALIGN(4);

   *(.text)          /* .text sections (code) */

   *(.text*)         /* .text* sections (code) */

   *(.glue_7)        /* glue arm to thumb code */

   *(.glue_7t)       /* glue thumb to arm code */

   *(.eh_frame)

   KEEP (*(.init))

   KEEP (*(.fini))

   . = ALIGN(4);

   _etext = .;       /* define a global symbols at end of code */

 } >FLASH

1 ACCEPTED SOLUTION

Accepted Solutions

>>..when I try to run my program it doesn't start.

The rules here are pretty basic and fixed. It is going to load from the memory mapped/shadowed at ZERO, This will be the data at 0x08000000 if FLASH is selected via BOOTx pins.

>>The vector table and code are also saved to flash sectors, so what I need help with is moving the code to a different sector such that when I start the program it will load from whatever sector I have moved the code to.

Ok, but you don't show how you do it currently, so hard to modify/suggest, change the addresses?

MEMORY
{
RAM (xrw)     : ORIGIN = 0x20000000, LENGTH = 128K
VECTORS (rx)   : ORIGIN = 0x08000000, LENGTH = 16K
DATA (rwx)     : ORIGIN = 0x08004000, LENGTH = 16K
FLASH (rx)     : ORIGIN = 0x08008000, LENGTH = 512K - 32k
}
 
/* Define output sections */
 
SECTIONS
{
 /* The startup code goes first into FLASH */
 
 .isr_vector :
 {
   . = ALIGN(4);
   KEEP(*(.isr_vector)) /* Startup code */
   . = ALIGN(4);
 } >VECTORS
 
 
 .user_data :
 {
   . = ALIGN(4);
   KEEP(*(.user_data))
   KEEP(*(.user_data*))
   . = ALIGN(4);
 } >DATA
 
 
 /* The program code and other data goes into FLASH */
 
 .text :
 {
   . = ALIGN(4);
   *(.text)          /* .text sections (code) */
   *(.text*)         /* .text* sections (code) */
   *(.glue_7)        /* glue arm to thumb code */
   *(.glue_7t)       /* glue thumb to arm code */
   *(.eh_frame)
 
   KEEP (*(.init))
   KEEP (*(.fini))
 
   . = ALIGN(4);
   _etext = .;       /* define a global symbols at end of code */
 } >FLASH
...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

1 REPLY 1

>>..when I try to run my program it doesn't start.

The rules here are pretty basic and fixed. It is going to load from the memory mapped/shadowed at ZERO, This will be the data at 0x08000000 if FLASH is selected via BOOTx pins.

>>The vector table and code are also saved to flash sectors, so what I need help with is moving the code to a different sector such that when I start the program it will load from whatever sector I have moved the code to.

Ok, but you don't show how you do it currently, so hard to modify/suggest, change the addresses?

MEMORY
{
RAM (xrw)     : ORIGIN = 0x20000000, LENGTH = 128K
VECTORS (rx)   : ORIGIN = 0x08000000, LENGTH = 16K
DATA (rwx)     : ORIGIN = 0x08004000, LENGTH = 16K
FLASH (rx)     : ORIGIN = 0x08008000, LENGTH = 512K - 32k
}
 
/* Define output sections */
 
SECTIONS
{
 /* The startup code goes first into FLASH */
 
 .isr_vector :
 {
   . = ALIGN(4);
   KEEP(*(.isr_vector)) /* Startup code */
   . = ALIGN(4);
 } >VECTORS
 
 
 .user_data :
 {
   . = ALIGN(4);
   KEEP(*(.user_data))
   KEEP(*(.user_data*))
   . = ALIGN(4);
 } >DATA
 
 
 /* The program code and other data goes into FLASH */
 
 .text :
 {
   . = ALIGN(4);
   *(.text)          /* .text sections (code) */
   *(.text*)         /* .text* sections (code) */
   *(.glue_7)        /* glue arm to thumb code */
   *(.glue_7t)       /* glue thumb to arm code */
   *(.eh_frame)
 
   KEEP (*(.init))
   KEEP (*(.fini))
 
   . = ALIGN(4);
   _etext = .;       /* define a global symbols at end of code */
 } >FLASH
...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..