This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to store constant variables at specific address during compile time

Hi,

I would like to store firmware version number at a particular offset from the application start address so that it can be retrieved by boot loader as explained here.

Could you give an example on how to do this? The version number will be generated at compile time.

Thanks in advance Arjun

Parents
  • Here is a template you could use for GCC (similar to what is done in the bootloader project, adapted from this post).

    First you need to add a new section in your linker script:

    MEMORY
    {
      FLASH (rx) : ...
      RAM (rwx) : ...
    
      bootloader_settings (rwx) : ORIGIN = 0x3FC00, LENGTH = 0x400
    }
    
    SECTIONS
    {
        .bootloader_settings_block 0x0003FC00 :
        {
            KEEP(*(.bootloader_settings_sect))
        } > bootloader_settings
    }
    

    The you can read/write bytes from this sections using a normal array, like this:

    uint8_t __attribute__((section (".bootloader_settings_sect"))) m_boot_settings[0x400] __attribute__((used));
    
Reply
  • Here is a template you could use for GCC (similar to what is done in the bootloader project, adapted from this post).

    First you need to add a new section in your linker script:

    MEMORY
    {
      FLASH (rx) : ...
      RAM (rwx) : ...
    
      bootloader_settings (rwx) : ORIGIN = 0x3FC00, LENGTH = 0x400
    }
    
    SECTIONS
    {
        .bootloader_settings_block 0x0003FC00 :
        {
            KEEP(*(.bootloader_settings_sect))
        } > bootloader_settings
    }
    

    The you can read/write bytes from this sections using a normal array, like this:

    uint8_t __attribute__((section (".bootloader_settings_sect"))) m_boot_settings[0x400] __attribute__((used));
    
Children
Related