cancel
Showing results for 
Search instead for 
Did you mean: 

Struct in Flash

greg_t
Associate II
Posted on October 26, 2010 at 19:42

Struct in Flash

11 REPLIES 11
Andrew Neil
Evangelist III
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?

greg_t
Associate II
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 ?

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

He wants it at a specific location.

dthedens2
Associate II
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

epassoni950
Associate II
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
silvia
Associate II
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)

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
Up vote any posts that you find helpful, it shows what's working..
smart2
Associate II
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

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

A similar way like clive:

typedef struct {

    uint32_t a;

    uint32_t b;

    uint32_t c;

} tFlashParams;

#define flashParams    ((volatile tFlashParams *) 0x0801F000)

Be sure, that only 16 bit wide AND 16 bit aligned writes should be used!

I would NOT use any way of IAR specific pragma commands!