Skip to main content
greg_t
Associate III
October 26, 2010
Question

Struct in Flash

  • October 26, 2010
  • 11 replies
  • 2664 views
Posted on October 26, 2010 at 19:42

Struct in Flash

    This topic has been closed for replies.

    11 replies

    greg_t
    greg_tAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    I found a way to do it :

    __no_init struct   {

      uint32_t x;

      uint32_t y;

    } tempor @ 0x0801FFFC;

    Is there a way to place data in Flash without giving the address and let the compiler to decide ?

    Andrew Neil
    Super User
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    ''Warning[Pe609]: this kind of pragma may not be used here''

     

    So you need to consult your IAR manuals to see what other kinds of pragmas exist that can be used there...

    Have you asked IAR about this?

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    dthedens2
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    use the ''const'' key word.

    usualy all members of the structure must be const

    struct {

    const int x;

    const int y;

    } const A;

    should place A into flash

    xacc
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    He wants it at a specific location.

    silvia
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    Hello,

    I used (const and __at), need the library (absacc.h)

    example:

    const unsigned long CodeChecksum __at (0x8000640)

    epassoni950
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    Hello,

    You can use first syntax with #pragma if you declare first the struct and after you reserve it.

    struct s_tempor

    {

       int x ;

       int y ;

    } ;

    #pragma location=0x0801FFFE

    __no_init struct s_tempor tempor ;

    Be carrefull in your example, the size of struct is 8 bytes. With a 128 k device, I think the correct address is 0x801FFF8 for the end of Flash.

    If you don't want to have address in source, you can declare a new section and edit your ICF file to place this section at the correct address in Flash.

    #pragma location=''.param''

    __no_init struct s_tempor tempor ;

    With this method, you can have several parameters in your project even in different files, and the linker group together all parameters in the same sector of the Flash.

    Best regards

    Eric
    smart2
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    Absoulte placement is possible for variable but not for structure.

    CONSTSEG should be defined in linker files based on the size of your structure.

     

    Try this one:

    #pragma location=CONSTSEG

    const struct 

    {

         int x;

         int y;

    tempor;

    #pragma location=default

    Hello, I am trying to write some parameters to the Flash memory

    I am using IAR ...

    This code works fine : 

    #pragma location=0x0801FFFE

    __no_init char tempor;

    but when I try to do something like that : 

    #pragma location=0x0801FFFE

    __no_init struct 

    {

         int x;

         int y;

    tempor;

    I get : 

    '' Warning[Pe609]: this kind of pragma may not be used here  ..\main.c 35 ''

    and the data is placed in RAM

    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    Or heaven forbid, something crude and relatively portable like

    unsigned long *CodeChecksum = (unsigned long *)0x08000640;

    printf(''%08lX\n'',*CodeChecksum);

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    Whats wrong with IAR specific pragma commands?

    Like any language extensions they aren't very portable, casts work practically everywhere. The IAR extensions aren't going to work on RealView, Keil, GHS, Rowley, Atollic, GCC, etc.

    The same reason I'd avoid nameless unions/structures, and incrementing void * pointers. The code will be difficult to work with, and maintain, 5,10,15 or 20 years from now.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    smart2
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 14:12

    Hello damh

    Just to extend my knowledge..can you give some more explanation ..

    Whats wrong with IAR specific pragma commands?