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));
    
  • Hi Christopher,

    Thanks for the quick response. Yes I am aware of this method. But I would actually like to place the field at an offset from Application start address. And Application start address is not always fixed and depends on softdevice size. Also I would like to know if we can store firmware id(4 bytes) without having to allocate 1K of flash just for that.

    Thanks Arjun

Reply
  • Hi Christopher,

    Thanks for the quick response. Yes I am aware of this method. But I would actually like to place the field at an offset from Application start address. And Application start address is not always fixed and depends on softdevice size. Also I would like to know if we can store firmware id(4 bytes) without having to allocate 1K of flash just for that.

    Thanks Arjun

Children
No Data
Related