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

how to get memory slot not zeroed

I see options for target

default start      size   Noinit
        0x20000000 0x200
V       0x20000200 0xffff   v

and still a variable @ 0x20001348 zeroes out on reset/run

Erik

what then is the meaning of the noinit checkbox? the variable zeroes out on startup

Erik

Parents
  • I think you are much better off with elaborate scatter loading.

    #pragma arm section zidata = "non_init"
    
    __attribute__ ((zero_init)) data_interface_t    g_data_interface ;
    
    #pragma arm section zidata
    

    and in the scatter file:

    RW_DATA_INTERFACE   DATA_INTERFACE_ADDRESS   UNINIT
      {
        DATA_INTERFACE.o (data_interface_section)
      }
    

    A variable must be placed in a zero init section to prevent it from being set to 0.

Reply
  • I think you are much better off with elaborate scatter loading.

    #pragma arm section zidata = "non_init"
    
    __attribute__ ((zero_init)) data_interface_t    g_data_interface ;
    
    #pragma arm section zidata
    

    and in the scatter file:

    RW_DATA_INTERFACE   DATA_INTERFACE_ADDRESS   UNINIT
      {
        DATA_INTERFACE.o (data_interface_section)
      }
    

    A variable must be placed in a zero init section to prevent it from being set to 0.

Children
  • I posted a mistake - sorry:

    #pragma arm section zidata = "data_interface_section"
    
    __attribute__ ((zero_init)) data_interface_t    g_data_interface ;
    
    #pragma arm section zidata
    

  • what is a "scatter file"?

    Tamir, since you are in a place totally unknown to an IAR person, please be elaborate with the example.

    Erik

  • I did not know that you are working with IAR.
    However, for the RealView toolchain, a scatter file is the linker configuration file - the one that allows you to place just about any program element in a specified location. When you use the options for target dialog, you are basically manipulating the file that is provided by default. For IAR the syntax will be no doubt different. I am sorry I cannot provide an example - I never used IAR before.

  • I did not know that you are working with IAR.
    I am not, but I have till a short while ago been working with IAR and now working with Keil

  • The code above creates a section called "data_interface_section" and places the variables "g_data_interface" in it. Then, that section can be placed at will using the scatter file:

    RW_DATA_INTERFACE   DATA_INTERFACE_ADDRESS   UNINIT
    {
      DATA_INTERFACE.o (data_interface_section)
    }
    

    RW_DATA_INTERFACE is just a moniker for the execution region that can be found in the .map file.
    "DATA_INTERFACE_ADDRESS" can be replaced by a magic number and indicates that location of the object, but in the particular example I have taken advantage of the preprocessor capabilities of the toolchain that can be applied to non-source files as well (use something like

    #! armcc -E -I"..\firmware\src" -I"..\bootloader\src" -I"..\..\common\src" -I"..\common\src" -DSCATTER_FILE_PREPROCESSOR
    

    at the top of the scatter file. See linker user manual).
    UNINT is a descriptor of the execution region. It is compulsory here for this to work, as the location of the variable in a zero init type section (see definition in previous post).

  • at the top of the scatter file
    the noinit CLARLY should work, but does not.
    so how do you modify/generate a "scatter file"

    eRIK

  • Go to "options for target", linker tab, then select "Edit".

  • from the .scf file

     RW_IRAM2 0x20000200 UNINIT 0x0000FE00  {  ; RW data
        Pic_Etcs.o (+RW)
       .ANY (+RW +ZI)
      }
    

    the +ZI must be it
    thus something done elsewhere must be the cause of the zero init
    anyone any ideas?

    Erik

  • from various sources I have picked the below up

    scatter

    ; *************************************************************
    ; *** Scatter-Loading Description File generated by uVision ***
    ; *************************************************************
    
    LR_IROM1 0x08020000 0x00040000  {    ; load region size_region
      ER_IROM1 0x08020000 0x00040000  {  ; load address = execution address
       *.o (RESET, +First)
       *(InRoot$$Sections)
       .ANY (+RO)
      }
      RW_IRAM1 0x20000000 UNINIT 0x00000200  { ;no init section
            *(NoInit)
       }
      RW_IRAM2 0x20000200 UNINIT 0x0000FE00  {  ; RW data
        Pic_Etcs.o (+ZI +RW)
       .ANY (+RW)
      }
      RW_RAM1 0x68000000 UNINIT 0x00080000  {
        Dortmund_BIOS_ShadowRAM.o (+ZI +RW)
      }
    }
    
    LR_IROM2 0x08060000 0x00020000  {
      ER_IROM2 0x08060000 0x00020000  {  ; load address = execution address
        Dortmund_BIOS_LCD.o (+RO)
       .ANY (+RO)
      }
    }
    
    
    C
    DWORD dwPuppyMunch __attribute__( ( section( "NoInit"),zero_init) ) ;
    DWORD dwPuppyFood __attribute__( ( section( "NoInit")) ) ;
    
    #pragma arm section zidata = "NoInit"
    DWORD dwPuppyChow;                        //uninit (in non_init section)
    #pragma arm section zidata                //back to default (.bss section)
    

    this is as far as it seems I can get, but all 3 zeroes out :(

    Erik

  • It the varialble "dwPuppyChow" located in the right execution region? Is the execution region itself indeed of type UNINIT?

  • Try just the dwPuppyMunch, the same approach you have for the scatter file and the attribute for dwPuppyMunch worked for me. You need the zero_init in the attribute to force a small global into a specific segment but I think you might be assigning conflicting attributes by dropping the zero_init in the next line and then using the #pragma.

    The confusing part is that even though you tell the linker to UNINIT the segment, zero_init is needed to override the default placement algorithm. The default is to silently put small globals into the normal data segment.

    Andrew

  • DWORD dwPuppyMunch __attribute__( ( section( "NoInit"),zero_init) ) ;
    //DWORD dwPuppyFood __attribute__( ( section( "NoInit")) )  ;
    DWORD dwPuppyFood  ;
    
    //#pragma arm section zidata = "NoInit"
    DWORD dwPuppyChow;                        //uninit (in non_init section)
    //#pragma arm section zidata                //back to default (.bss section)
    

    andrew, please do me the favor of checking your reference, the above still initializes dwPuppyMunch

    thanx,

    Erik

  • Hi Erik,

    The program below, compiled with "use micro-lib", uVision 4.22.22:

    #include <stdio.h>
    #include <stdint.h>
    #include "stm32f10x.h"
    
    int32_t NoInit____zero_init __attribute__( ( section( "NoInit"),zero_init) ) ;
    int32_t NoInit __attribute__( ( section( "NoInit")) ) ;
    int32_t simpleGlobal;
    
    int main(void)
    {
            printf("NoInit-zero_init is %d at %x\n", NoInit____zero_init, (int)&NoInit____zero_init);
            printf("NoInit is %d at %x\n", NoInit, (int)&NoInit);
            printf("simpleGlobal is %d at %x\n", simpleGlobal, (int)&simpleGlobal);
    
            return 1;
    }
    

    prints out:

    NoInit-zero_init is 103643149 at 20000004
    NoInit is 0 at 20000000
    simpleGlobal is 0 at 20000200

    using this scatter-load:

    LR_IROM1 0x08000000 0x00100000  {    ; load region size_region
      ER_IROM1 0x08000000 0x00100000  {  ; load address = execution address
       *.o (RESET, +First)
       *(InRoot$$Sections)
       .ANY (+RO)
      }
      RW_IRAM1 0x20000000 UNINIT 0x00000200  { ;no init section
            *(NoInit)
       }
      RW_IRAM2 0x20000200 0x00018000  {  ; RW data
       .ANY (+RW +ZI)
      }
    }
    

    If you single step in the assembly view before you hit main you'll see that the scatterloader adds code to initialize the NoInit variable but not the NoInit____zero_init variable.

    Andrew

  • thanks a bunch, I'm stuck in meetings for the next 2 days, will report back

    Erik