This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Setting address of variable in flash

Hi,

Is it possible to set an address lets say for an array to be in Flash memory on compilation? So that way I dont need to reserve memory twice - once in my program memory area and once in flash.

Thanks!

Parents
  • You mean something like this?

    const uint8_t __attribute__((section (".my_array_in_flash_sect"))) my_array[my_array_size] __attribute__((used)) = {0};
    

    gcc_nrf51_s110_xxaa.ld

    /* Linker script to configure memory regions. */
    SEARCH_DIR(.)
    GROUP(-lgcc -lc -lnosys)
    
    MEMORY
    {
      FLASH (rx) : ORIGIN = 0x14000, LENGTH = 0x13C00 /* 80 kB is taken by S110, 16kB is taken by bootloader,  160 kB available for application in single bank mode or 80 kB in dual bank mode, 1kB for my array */
      my_array_in_flash (rwx) : ORIGIN = 0x27C00, LENGTH = 0x400 /* my array */
      RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */
    }
    INCLUDE "gcc_nrf51_common.ld"
    

    gcc_nrf51_common.ld

    SECTIONS
    {
        .my_array_in_flash_block 0x00027C00 :
        {
            KEEP(*(.my_array_in_flash_sect))
        } > my_array_in_flash
    ...
    

    UPD:

    For Keil it's like this:

    #define MY_ARRAY_ADDRESS     0x28C00
    const uint8_t  my_array[my_array_size] __attribute__((at(MY_ARRAY_ADDRESS))) __attribute__((used)) = {0};
    

    image description

  • Awesome! Thanks so much!

Reply Children
No Data
Related