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

define variable in the designated address space

I want to define the variable in the designated address space.I used another compiler,before the variable define,I can use the #pragma to distribute the address space.
What can I do with Keil?Such as the #pragma!
Thank you very much!

  • There are probably numerous ways, but this is one that I have used:

    uint32_t __attribute__((section("MySection"),zero_init)) MyInt;
    

  • Thank you for your reply!but I also have some question:
    1ã€I want to define the whole data in the designated address space one by one,such as
    #pragma section
    int data1;
    int data2;
    . .
    . the variable distribute the address automatic
    so,how can I do?
    2ã€if use your way,where define "MySection",what is mean about the "zero_init"?
    Thank you very much again!

  • You can put the whole collection of items you want placed in a section within a structure. That also groups all the information into a logical unit.

    The zero_init is used to force the linker to put the data into a section that is not initialized at startup, which is very useful for non volatile data. You might not need or want it.

  • Thank you very much!
    I define the section in the sct like this:
    RAM 0x20000000 0x7FFF
    { ADDER 0x7FFF { data_common.o(+RW) (foo) ; select section foo from data_common.o }
    }

    define the variable in the data_common.c like this:
    #pragma arm section rwdata="foo"
    int data=0;
    #pragma arm section rwdata

    but the variable address in the .map file not assigned to the correct address after compile:
    Base Addr Size Type Attr Idx E Section Name Object

    0x1fff8000 0x0000000c Data RW 605 .data main.o 0x1fff800c 0x00000004 Data RW 647 foo data_common.o

    can you help me?Thank you!

  • I can see no reason for me to continue to give advice when you have chosen to do something other than what I have suggested.

    It's over to you now.

  • I have tested the way you told me like this,but it not effective:
    int__attribute__((section("foo"))) data;

    define the section in the .sct like this :

    RAM 0x20000000 0x7FFF
    { RAM_Data 0x20000000 0x7FFF { data_common.o(+RW) (foo) ; select section foo from data_common.o }
    }

    but the address in the .map didn't in the expect address:
    data 0x1fff800c Data 4 data_common.o(foo)

    so,if I define variable by this method,what can I do?
    Thank you very much!