0

I develop for the STM32 environment (same IDE), and I have to change the original Linker Script. I would like to store a struct in the exact memory address. If I create a new memory item (in the MEMORY body), it could be a solution but I have to specify the length. ( but I dont want to) Can I do it without knowing the length / struct size?

This is my current solution:

.isr_vector:
...

  .text:
  {
    . = ALIGN(0x8000300);
    KEEP(*(.SWHEADER_SECTION))
    
  }>FLASH
.text:
...

So it will store SWHEADER_SECTION into 0x8000300, and the FLASH will continue on the next section. I can't add a variable to ALIGN instead of setting a constans. I have tried lots of other solutions, but they were not effecive or the linker dropped an error (ex: OVERLAPPED, etc.) Is there any other solution?

Another question: If the SWHEADER_SECTION is written like this, then between these two sections, there will be a section that will not be used. Is it possible that .isr_vector can be followed by the common .text, and the linker can skip space by the SWHEADER_SECTION section?

Thanks!

2
  • align is not position in the address space. Commented Feb 15, 2024 at 21:44
  • What is the exact task you are trying to solve? I see no reason to fix a struct in the middle of a section. Usually you want to fix a struct int the memory to be able to reflash it and, e.g. change settings. But in this case it must be located on a separate flash page. Commented Feb 16, 2024 at 7:53

1 Answer 1

1

ALIGN tells the linker that the address must be a multiple of this, not exactly this. The argument must be a power of two.

You don't have to know the exact size of something to fix its address though. Just put the .isr_vector in a fixed size memory region and then put your headers at the start of the text section, followed by the rest of your program.

Something like:

    MEMORY
    {
        VECTORS (r)   : ORIGIN = 0x08000000, LENGTH = 768
        ROM     (rx)  : ORIGIN = 0x08000300, LENGTH = (16K - 768)
        RAM     (rwx) : ORIGIN = 0x20000000, LENGTH = 4K
    }

    SECTIONS
    {
        .vectors :
        {

            KEEP(*(.isr_vector))
        }
        >VECTORS

        .text :
        {
            KEEP(*(.SWHEADER_SECTION))
            *(.text .text.* .stub .gnu.linkonce.t.*)
        }
        >ROM
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! But I have to keep the "SWHEADER_SECTION" in a exact position! (The "updater" device will be read the FLASH section from the exact memory address) This code are put the "SWHEADER_SECTION" after "isr_vector", and it is not always fix.
No, this puts the header first in the ROM memory, which is always at the fixed address. The vector is in a separate memory region. It does exactly what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.