EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Assigning variables in Flash

Started by Pratik Shah March 15, 2007
Can any one tell me How to assign any particular vairable & function in Flash ?
Also if anyone can provide me small assembly function so that i can go through the method of writing assembly language in Keil Compiler.

---------------------------------
Sucker-punch spam with award-winning protection.
Try the free Yahoo! Mail Beta.

An Engineer's Guide to the LPC2100 Series

--- In l..., Pratik Shah wrote:
>
> Can any one tell me How to assign any particular vairable & function
in Flash ?
> Also if anyone can provide me small assembly function so that i
can go through the method of writing assembly language in Keil Compiler.
>
>
>
> ---------------------------------
> Sucker-punch spam with award-winning protection.
> Try the free Yahoo! Mail Beta.
>
>
>

That's a tough one, a variable in flash. You really want to put
variables in RAM!.
And having such basic questions, "C" might be a better choice too!
Please, no offense

Bob
Pratik Shah wrote:
>
> Can any one tell me How to assign any particular vairable & function
> in Flash ?
> Also if anyone can provide me small assembly function so that i can go
> through the method of writing assembly language in Keil Compiler.
>
In the GNU gcc compiler / bintools, it is very easy to do:

1. edit the loader script and put a reference in to the Flash block,
then a label to the struct.

=============== LOADER.LD =============MEMORY
{
CODE (rx) : ORIGIN = 0x00010000, LENGTH = 0x0001FFFF
SRAM(rw) : ORIGIN = 0x81008000, LENGTH = 0xEFFF
HEAPTOP(rw) : ORIGIN = 0x8100F000, LENGTH = 0x4
STACK(rw) : ORIGIN = 0x8100FFF0, LENGTH = 0x4
CONFIG(rw) : ORIGIN = 0x3a000, LENGTH = 0x1FFF
}

...
...
.configuration :
{
PROVIDE (sysConfig = .);
} > CONFIG

=============== snip ==================2. add your extern reference in your code:

================ loader.c ===============...
...
extern setup_config_t sysConfig; // this is in Flash @ 0x3a000.
...
...
================= snip ================Since you have such an odd compiler, you will probably have to do this
much differently.

Regards,

TomW

--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."
----------------
--- In l..., Tom Walsh wrote:
>
> Pratik Shah wrote:
> >
> > Can any one tell me How to assign any particular vairable &
function
> > in Flash ?
> > Also if anyone can provide me small assembly function so that i
can go
> > through the method of writing assembly language in Keil Compiler.
> >
> In the GNU gcc compiler / bintools, it is very easy to do:
>
> 1. edit the loader script and put a reference in to the Flash
block,
> then a label to the struct.
>
> =============== LOADER.LD =============> MEMORY
> {
> CODE (rx) : ORIGIN = 0x00010000, LENGTH = 0x0001FFFF
> SRAM(rw) : ORIGIN = 0x81008000, LENGTH = 0xEFFF
> HEAPTOP(rw) : ORIGIN = 0x8100F000, LENGTH = 0x4
> STACK(rw) : ORIGIN = 0x8100FFF0, LENGTH = 0x4
> CONFIG(rw) : ORIGIN = 0x3a000, LENGTH = 0x1FFF
> }
>
> ...
> ...
> .configuration :
> {
> PROVIDE (sysConfig = .);
> } > CONFIG
>
> =============== snip ==================> 2. add your extern reference in your code:
>
> ================ loader.c ===============> ...
> ...
> extern setup_config_t sysConfig; // this is in Flash @ 0x3a000.
> ...
> ...
> ================= snip ================> Since you have such an odd compiler, you will probably have to do
this
> much differently.
>
> Regards,
>
> TomW
>
> --
> Tom Walsh - WN3L - Embedded Systems Consultant
> http://openhardware.net http://cyberiansoftware.com
http://openzipit.org
> "Windows? No thanks, I have work to do..."
> ----------------
>

Can't see the point of holding true variables in Flash myself.

If you do something like:

const int foo = 23;

isn't it placed in flash by default on most systems?

Or am I missing something?
Brendan Murphy wrote:
>
> --- In lpc2000@yahoogroups .com ,
> Tom Walsh wrote:
> >
> > Pratik Shah wrote:
> > >
> > > Can any one tell me How to assign any particular vairable &
> function
> > > in Flash ?
> > > Also if anyone can provide me small assembly function so that i
> can go
> > > through the method of writing assembly language in Keil Compiler.
> > >
> > In the GNU gcc compiler / bintools, it is very easy to do:
> >
> > 1. edit the loader script and put a reference in to the Flash
> block,
> > then a label to the struct.
> >
> > ============ === LOADER.LD ============ => > MEMORY
> > {
> > CODE (rx) : ORIGIN = 0x00010000, LENGTH = 0x0001FFFF
> > SRAM(rw) : ORIGIN = 0x81008000, LENGTH = 0xEFFF
> > HEAPTOP(rw) : ORIGIN = 0x8100F000, LENGTH = 0x4
> > STACK(rw) : ORIGIN = 0x8100FFF0, LENGTH = 0x4
> > CONFIG(rw) : ORIGIN = 0x3a000, LENGTH = 0x1FFF
> > }
> >
> > ...
> > ...
> > .configuration :
> > {
> > PROVIDE (sysConfig = .);
> > } > CONFIG
> >
> > ============ === snip ============ ======> >
> >
> > 2. add your extern reference in your code:
> >
> > ============ ==== loader.c ============ ===> > ...
> > ...
> > extern setup_config_ t sysConfig; // this is in Flash @ 0x3a000.
> > ...
> > ...
> > ============ ===== snip ============ ====> >
> >
> > Since you have such an odd compiler, you will probably have to do
> this
> > much differently.
> >
> > Regards,
> >
> > TomW
> >
> >
> >
> > --
> > Tom Walsh - WN3L - Embedded Systems Consultant
> > http://openhardware .net
> http://cyberiansoft ware.com
> http://openzipit. org
> > "Windows? No thanks, I have work to do..."
> > ------------ --------- --------- --------- --------- ----
> > Can't see the point of holding true variables in Flash myself.
>
> If you do something like:
>
> const int foo = 23;
>
> isn't it placed in flash by default on most systems?
>
> Or am I missing something?
>
Yes, the use of Flash as a config block that is factory written with
unique data.

TomW

--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."
----------------
--- In l..., Tom Walsh wrote:
> > Can't see the point of holding true variables in Flash myself.
> >
> > If you do something like:
> >
> > const int foo = 23;
> >
> > isn't it placed in flash by default on most systems?
> >
> > Or am I missing something?
> >
> Yes, the use of Flash as a config block that is factory written
with
> unique data.
>

Tom,

I should have explained myself better. Like you, we store some
standard config information in Flash, so I understand the concept OK.
I used the term "true variable" as one that does just that: vary.
Obviously it can't do this if stored in Flash, hence my question.

The other (separate) point I was making was that using "const" will
on most compilers place the variable in a read-only section, which
most linker setups will by default store along with the code in
Flash. As it's much simpler and doesn't require any modification to
the defaults on most setups, I thought it worth mentioning.

Having said all that, your specific example of how to place variables
in particular sections and ensure they're located at specific flash
locations is very useful. In fact we do something very similar to
ensure our factory config, version numbers, build date/time etc. are
always at a fixed location.

Brendan
Brendan Murphy wrote:
>
> --- In lpc2000@yahoogroups .com ,
> Tom Walsh wrote:
> > > Can't see the point of holding true variables in Flash myself.
> > >
> > > If you do something like:
> > >
> > > const int foo = 23;
> > >
> > > isn't it placed in flash by default on most systems?
> > >
> > > Or am I missing something?
> > >
> > Yes, the use of Flash as a config block that is factory written
> with
> > unique data.
> > Tom,
>
> I should have explained myself better. Like you, we store some
> standard config information in Flash, so I understand the concept OK.
> I used the term "true variable" as one that does just that: vary.
> Obviously it can't do this if stored in Flash, hence my question.
>

Yeah, his question wasn't very clear as to what it was that would be
stored into Flash. So, I had to assume that the issue dealt with the
more obscure (difficult) task of placing a block of data into flash.
Something like a large table of data. The const thing should pretty
much apparent to most people though.

Um, maybe not, we do have all levels of expertise here in this group.
Those that have been banging bits for many years / compilers /etc. And
then, there are the relative newcomers who find the job of getting a
Makefile built to be somewhat overwhelming. So, from the original
message, it was hard to gauge what specifically they were asking for.

Regards,

TomW

> The other (separate) point I was making was that using "const" will
> on most compilers place the variable in a read-only section, which
> most linker setups will by default store along with the code in
> Flash. As it's much simpler and doesn't require any modification to
> the defaults on most setups, I thought it worth mentioning.
>
> Having said all that, your specific example of how to place variables
> in particular sections and ensure they're located at specific flash
> locations is very useful. In fact we do something very similar to
> ensure our factory config, version numbers, build date/time etc. are
> always at a fixed location.
>
> Brendan
>
>
--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."
----------------
ya
but do u have any idea about Keil

What do u say which softwar should we used for compiling & Debugging ARm LPC2148 ?

Tom Walsh wrote:
Pratik Shah wrote:
>
> Can any one tell me How to assign any particular vairable & function
> in Flash ?
> Also if anyone can provide me small assembly function so that i can go
> through the method of writing assembly language in Keil Compiler.
>
In the GNU gcc compiler / bintools, it is very easy to do:

1. edit the loader script and put a reference in to the Flash block,
then a label to the struct.

=============== LOADER.LD =============MEMORY
{
CODE (rx) : ORIGIN = 0x00010000, LENGTH = 0x0001FFFF
SRAM(rw) : ORIGIN = 0x81008000, LENGTH = 0xEFFF
HEAPTOP(rw) : ORIGIN = 0x8100F000, LENGTH = 0x4
STACK(rw) : ORIGIN = 0x8100FFF0, LENGTH = 0x4
CONFIG(rw) : ORIGIN = 0x3a000, LENGTH = 0x1FFF
}

...
...
.configuration :
{
PROVIDE (sysConfig = .);
} > CONFIG

=============== snip ==================
2. add your extern reference in your code:

================ loader.c ===============...
...
extern setup_config_t sysConfig; // this is in Flash @ 0x3a000.
...
...
================= snip ================
Since you have such an odd compiler, you will probably have to do this
much differently.

Regards,

TomW

--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."
----------------

---------------------------------
Get your own web address.
Have a HUGE year through Yahoo! Small Business.

---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
Ok in Keil assuming you're using RealView as the compiler, here's a simple
example of how to put a constant value into the flash at a specific
location.
For this example I'll simply use the method used to insert the CRP value at
0x1FC.

in a file for this example named abs_address.c you have:
#pragma push
#pragma Ono_remove_unused_constdata
unsigned int const Security_Value = 0x87654321;
#pragma pop

then in microvision under the linker settings for the linker:
Untick 'Use Memory Layout From Target Dialog'
edit the Scatter File to look something like this:
LR_IROM1 0x00000000 0x00080000 { ; load region
ER_IROM1 0x00000000 { ; load address = execution address
*.o (RESET, +First)
.ANY (*)
}

ABS_ADDRESS 0x1FC FIXED 4 {
abs_address.o (*)
}

ER_IROM2 +0 0x80000 {
* (+RO)
.ANY(*)
}

RW_IRAM1 0x40000000 0x00008000 { ; RW data
* (+RW +ZI)
}
}

lastly under Misc Controls for the Linker set:
--keep abs_address.o(.constdata)

This will now cause any compilation to force the value 'Security_Value' into
address 0x1FC with surrounding addresses of flash free to be used by your
code.
Normally, data that is const (ie read only) and accessed by the program will
naturally be placed in flash by the linker anyway - the only reason for the
above solution is that if there isn't anywhere in the code that accesses the
security value then under normal conditions the linker will remove the
constant as it will deem it unused and effectively superfluous. Since this
constant is required for CRP at this specific address it's easier simply to
manually direct the linker to include it in this case. For most
circumstances you should simply be able to direct the linker to locate the
code segments by manipulating the scatter file if it's really required.

Andy

-----Original Message-----
From: l... [mailto:l...]On Behalf Of
Pratik Shah
Sent: 24 March 2007 17:42
To: l...
Subject: Re: [lpc2000] Assigning variables in Flash
ya
but do u have any idea about Keil

What do u say which softwar should we used for compiling & Debugging ARm
LPC2148 ?

Tom Walsh wrote:
Pratik Shah wrote:
>
> Can any one tell me How to assign any particular vairable & function
> in Flash ?
> Also if anyone can provide me small assembly function so that i can go
> through the method of writing assembly language in Keil Compiler.
>
In the GNU gcc compiler / bintools, it is very easy to do:

1. edit the loader script and put a reference in to the Flash block,
then a label to the struct.

=============== LOADER.LD ============= MEMORY
{
CODE (rx) : ORIGIN = 0x00010000, LENGTH = 0x0001FFFF
SRAM(rw) : ORIGIN = 0x81008000, LENGTH = 0xEFFF
HEAPTOP(rw) : ORIGIN = 0x8100F000, LENGTH = 0x4
STACK(rw) : ORIGIN = 0x8100FFF0, LENGTH = 0x4
CONFIG(rw) : ORIGIN = 0x3a000, LENGTH = 0x1FFF
}

...
...
.configuration :
{
PROVIDE (sysConfig = .);
} > CONFIG

=============== snip ==================
2. add your extern reference in your code:

================ loader.c =============== ...
...
extern setup_config_t sysConfig; // this is in Flash @ 0x3a000.
...
...
================= snip ================
Since you have such an odd compiler, you will probably have to do this
much differently.

Regards,

TomW

--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net http://cyberiansoftware.com http://openzipit.org
"Windows? No thanks, I have work to do..."
----------------

---------------------------------
Get your own web address.
Have a HUGE year through Yahoo! Small Business.

---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

Memfault Beyond the Launch