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

Declaring a constant structure in flash memory without initialization

Hello everyone!

I am using Keil uVision 5.28 with Compiler V6.12.

How to declare a constant structure in flash memory so that it is not initialized by programmer / debugger and functions from scatterloader?

I'm looking at document https://static.docs.arm.com/100748/0609/compiler_user_guide_100748_0609_00_en.pdf.

There is an example on page 120 for peripheral registers, but it does not quite suit me, since there can be many such structures, and I do not want to make many files for each structure.

Now I have limited the size of the flash memory in the scatter file and refer to the structure at an absolute address.
Maybe there is some other, more correct solution?

Parents
  • Thanks for the answer.

    My scatter file:

    LR1 0x08000000 0x0007C800
    {
      USRROM 0x08000000 0x0007C800
      {
        *.o (RESET, +First)
        *(InRoot$$Sections)
        .ANY (+RO)
        .ANY (+XO)
      }
      
      NVRAM 0x20000000 UNINIT 0x00000008
      {
        *.o (.bss.dfuflg)
      }
      
      USRRAM 0x20000008 0x0000FFF8
      {
        .ANY (+RW +ZI)
      }
    }
    
    LR2 0x0807E800 0x00001000
    {
      NVROM1 0x0807E800 UNINIT 0x00001000
      {
        *.o (.bss.wtime)
      }
    }
    
    LR3 0x0807F800 0x00000800
    {
      NVROM2 0x0807F800 UNINIT 0x00000800
      {
        *.o (.bss.nvm)
      }
    }

    In my source code:

    static const u32 Var[10] __attribute__((section(".bss.nvm")));

    Moreover, in the message "Program size: code = 16176 RO-data = 1732 RW-data = 16 ZI-data = 7904" I notice that my array (for example, or structure) is placed in ZI-data.
    Does this violate linker logic?

Reply
  • Thanks for the answer.

    My scatter file:

    LR1 0x08000000 0x0007C800
    {
      USRROM 0x08000000 0x0007C800
      {
        *.o (RESET, +First)
        *(InRoot$$Sections)
        .ANY (+RO)
        .ANY (+XO)
      }
      
      NVRAM 0x20000000 UNINIT 0x00000008
      {
        *.o (.bss.dfuflg)
      }
      
      USRRAM 0x20000008 0x0000FFF8
      {
        .ANY (+RW +ZI)
      }
    }
    
    LR2 0x0807E800 0x00001000
    {
      NVROM1 0x0807E800 UNINIT 0x00001000
      {
        *.o (.bss.wtime)
      }
    }
    
    LR3 0x0807F800 0x00000800
    {
      NVROM2 0x0807F800 UNINIT 0x00000800
      {
        *.o (.bss.nvm)
      }
    }

    In my source code:

    static const u32 Var[10] __attribute__((section(".bss.nvm")));

    Moreover, in the message "Program size: code = 16176 RO-data = 1732 RW-data = 16 ZI-data = 7904" I notice that my array (for example, or structure) is placed in ZI-data.
    Does this violate linker logic?

Children