EmbeddedRelated.com
Forums

CONST IAR optimization

Started by FB December 28, 2007
Dnia 28-12-2007, pi o godzinie 10:47 -0300, FB pisze:
> Thanks!
> I tried use volatile keyword and IAR tries to store the variable in
> RAM. :(
> Any other suggestion ?
Put variable declaration in other source module as:
const ....
and use it with extern (without const) ?

Albert
>

Beginning Microcontrollers with the MSP430

Why not only just define a banc of memory and you say
firts segment is for the new calibration value, and
the next segment contain the default value of the
calibration, and the next segment is my flag to know
is all ready was calibrate my module. The rest is part
of the you logical application you decide.

I know that it's a waste of memory, but is only to be
clear, if you want only use a segment, you can do it
;).

If you dont know how to manage the flash, read the
data sheet or an application note you dont need more,
all that you need is there. If the problems persist
now you can made a question about of how to
write/erase from flash :D.

Bye Bye and "Have a happy new year :D".
--- FB wrote:

> I need to store my variable in flash because it is a
> calibration value which
> will change when we calibrate the system.
> Probably I will put it into Information Memory.
>
>
> _____
>
> From: m...
> [mailto:m...] On Behalf Of
> Kipton Moravec
> Sent: Viernes, 28 de Diciembre de 2007 11:12 a.m.
> To: m...
> Subject: Re: [msp430] Re: CONST IAR optimization
>
> I do not know why you feel you need to store the
> variable in flash and
> access it as such.
>
> You can't just go in and change the flash value.
> Most likely you will
> have to recompile. And if you have to recompile then
> why does it matter?
>
> The other option is to put the value in a EEPROM
> which can be changed
> outside the program.
>
> I have both used const and #define for constants
> that may change in the
> lifetime of the program and both seem to work fine
> for me. I do have a
> case where we put values in EEPROM and as we are
> fine tuning we can
> change the values in EEPROM without recompiling.
>
> I feel you are looking at a solution and not looking
> at the problem.
>
> Kip
>
> On Fri, 2007-12-28 at 13:58 +0000, tintronic wrote:
> > What I meant was for you to declare the variable
> as
> > const volatile float dT = { 2 };
> >
> > Have you considered the implications of changing a
> value stored in
> > flash? I mean, you will have to erase the whole
> segment flash and then
> > write the new value. Maybe you should think of
> something like
> >
> > float dT = { 2 } @ ;
> >
> > don't know if you will be needing 'volatile'
> and/or 'const'.
> >
> > Michael Kusch
> >
> > --- In HYPERLINK
>
"mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com,
> "FB" wrote:
> > >
> > > Thanks!
> > > I tried use volatile keyword and IAR tries to
> store the variable in
> > RAM. :(
> > > Any other suggestion ?
> > >
> > > _____
> > >
> > > From: HYPERLINK
>
"mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com
> [mailto:HYPERLINK
>
"mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com]
> On
> > Behalf Of
> > > tintronic
> > > Sent: Viernes, 28 de Diciembre de 2007 10:29
> a.m.
> > > To: HYPERLINK
>
"mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com
> > > Subject: [msp430] Re: CONST IAR optimization
> > >
> > >
> > >
> > > I think you need to declare the variable as
> volatile. That way, the
> > > compiler doesn't assume the value to be fixed
> and uses the address
> > > instead of the default value.
> > >
> > > Michael K.
> > >
> > > --- In HYPERLINK
> "mailto:msp430%-40yahoogroups.-com"msp430@-...,
> > > "FB" wrote:
> > > >
> > > > Hi!
> > > > Hi!
> > > > I have a software that need to have some
> values stored in flash.
> > > > As an example I defined:
> > > > const float dT = { 2 };
> > > >
> > > > Obviously 2 is the default value.
> > > > Now, when I pass the address of that variable
> to a function the
> > > > compiler do the right thing (In this case I
> can see dT defined in
> > > the .map
> > > > file)
> > > > When I use the variable in any other part of
> the code (not passing
> > > > it as reference to a function) the compiler
> uses the default value
> > > instead
> > > > the reference to a memory address.
> > > >
> > > > All this with high optimization option.
> > > >
> > > > I would like to know if you have a solution
> for me. How can I define
> > > > that variable so the compiler use it as
> reference in any case of
> > usage.
> > > >
> > > > Thanks
> > > > Bukitoo
> > > >
> > > >
> > > > Internal Virus Database is out-of-date.
> > > > Checked by AVG Free Edition.
> > > > Version: 7.5.503 / Virus Database: 269.17.5 -
> Release Date:
> > > 19/12/2007 12:00
> > > > a.m.
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Internal Virus Database is out-of-date.
> > > Checked by AVG Free Edition.
> > > Version: 7.5.503 / Virus Database: 269.17.5 -
> Release Date:
> > 19/12/2007 12:00
> > > a.m.
> > >
> > >
> > >
> > > Internal Virus Database is out-of-date.
> > > Checked by AVG Free Edition.
> > > Version: 7.5.503 / Virus Database: 269.17.5 -
> Release Date:
> > 19/12/2007 12:00
> > > a.m.
> > >
> > >
> > >
> > > [Non-text portions of this message have been
> removed]
> > >
> >
> >
> >
> >
> > "m...@-egroups.com
> >
> >
> >
Thanks!
I tried use volatile keyword and IAR tries to store the variable in RAM. :(
Any other suggestion ?

_____

From: m... [mailto:m...] On Behalf Of
tintronic
Sent: Viernes, 28 de Diciembre de 2007 10:29 a.m.
To: m...
Subject: [msp430] Re: CONST IAR optimization

I think you need to declare the variable as volatile. That way, the
compiler doesn't assume the value to be fixed and uses the address
instead of the default value.

Michael K.

--- In HYPERLINK "mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com,
"FB" wrote:
>
> Hi!
> Hi!
> I have a software that need to have some values stored in flash.
> As an example I defined:
> const float dT = { 2 };
>
> Obviously 2 is the default value.
> Now, when I pass the address of that variable to a function the
> compiler do the right thing (In this case I can see dT defined in
the .map
> file)
> When I use the variable in any other part of the code (not passing
> it as reference to a function) the compiler uses the default value
instead
> the reference to a memory address.
>
> All this with high optimization option.
>
> I would like to know if you have a solution for me. How can I define
> that variable so the compiler use it as reference in any case of usage.
>
> Thanks
> Bukitoo
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.17.5 - Release Date:
19/12/2007 12:00
> a.m.
>

Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.

Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.
> I have a software that need to have some values stored in flash.
> As an example I defined:
> const float dT = { 2 };
>
> Obviously 2 is the default value.
> Now, when I pass the address of that variable to a function the
> compiler do the right thing (In this case I can see dT defined in the .map
> file)
> When I use the variable in any other part of the code (not passing
> it as reference to a function) the compiler uses the default value instead
> the reference to a memory address.
>
> All this with high optimization option.
>
> I would like to know if you have a solution for me. How can I define
> that variable so the compiler use it as reference in any case of usage.

Hi Bukitoo!

The standard solution is the one that Albert suggested, place the
variable with its initalization in one source file and declare it in a
header file. That way the compiler will not assume that it knows the
value of the variable.

The reason why "const + volatile" doesn't work is because the standard
explicitly states that such variables may not be placed in ROM.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
Let me know if I made a mistake.

I declare in "tables.c" :
const float a = 2.0;

and then in every "XXX.c" where need the reference to "a" i declare:
extern const float a;

and I get this message:
Error[e46]: Undefined external "a" referred in XXX( ..\Debug\Obj\XXX.r43 )

It seems that the compiler is using a reference (in fact I can see that into
compiled asm; lst file) of that variable but then It can't find it.
:(

_____

From: m... [mailto:m...] On Behalf Of
Anders Lindgren
Sent: Micoles, 02 de Enero de 2008 05:56 a.m.
To: m...
Subject: Re: [msp430] CONST IAR optimization

> I have a software that need to have some values stored in flash.
> As an example I defined:
> const float dT = { 2 };
>
> Obviously 2 is the default value.
> Now, when I pass the address of that variable to a function the
> compiler do the right thing (In this case I can see dT defined in the .map
> file)
> When I use the variable in any other part of the code (not passing
> it as reference to a function) the compiler uses the default value instead
> the reference to a memory address.
>
> All this with high optimization option.
>
> I would like to know if you have a solution for me. How can I define
> that variable so the compiler use it as reference in any case of usage.

Hi Bukitoo!

The standard solution is the one that Albert suggested, place the
variable with its initalization in one source file and declare it in a
header file. That way the compiler will not assume that it knows the
value of the variable.

The reason why "const + volatile" doesn't work is because the standard
explicitly states that such variables may not be placed in ROM.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.


Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.

Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.





You shouldn't get that error. Did you declare "a" as a global
variable? did you include "tables.c" in your project?
Still, I don't understand why you don't use the '@' operator to place
the variable in info-flash. You eventually will have to.

Michael Kusch

--- In m..., "FB" wrote:
>
> Let me know if I made a mistake.
>
> I declare in "tables.c" :
> const float a = 2.0;
>
> and then in every "XXX.c" where need the reference to "a" i declare:
> extern const float a;
>
> and I get this message:
> Error[e46]: Undefined external "a" referred in XXX(
..\Debug\Obj\XXX.r43 )
>
> It seems that the compiler is using a reference (in fact I can see
that into
> compiled asm; lst file) of that variable but then It can't find it.
> :(
>
> _____
>
> From: m... [mailto:m...] On
Behalf Of
> Anders Lindgren
> Sent: Micoles, 02 de Enero de 2008 05:56 a.m.
> To: m...
> Subject: Re: [msp430] CONST IAR optimization
>
>
>
> > I have a software that need to have some values stored in flash.
> > As an example I defined:
> > const float dT = { 2 };
> >
> > Obviously 2 is the default value.
> > Now, when I pass the address of that variable to a function the
> > compiler do the right thing (In this case I can see dT defined in
the .map
> > file)
> > When I use the variable in any other part of the code (not passing
> > it as reference to a function) the compiler uses the default value
instead
> > the reference to a memory address.
> >
> > All this with high optimization option.
> >
> > I would like to know if you have a solution for me. How can I define
> > that variable so the compiler use it as reference in any case of
usage.
>
> Hi Bukitoo!
>
> The standard solution is the one that Albert suggested, place the
> variable with its initalization in one source file and declare it in a
> header file. That way the compiler will not assume that it knows the
> value of the variable.
>
> The reason why "const + volatile" doesn't work is because the standard
> explicitly states that such variables may not be placed in ROM.
>
> -- Anders Lindgren, IAR Systems
> --
> Disclaimer: Opinions expressed in this posting are strictly my own and
> not necessarily those of my employer.
>
>
>
>
>
>
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.17.5 - Release Date:
19/12/2007 12:00
> a.m.
>
>
>
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.17.5 - Release Date:
19/12/2007 12:00
> a.m.
>
>
>
>
>



Yes is a Global variable.
Yes I 've included tables.c into my project.
As a comment, the declaration as I told you is an example. I have several
const declarations where there are some using the @ operator (and still
causing the same Error).


_____

From: m... [mailto:m...] On Behalf Of
tintronic
Sent: Micoles, 02 de Enero de 2008 03:16 p.m.
To: m...
Subject: [msp430] Re: CONST IAR optimization

You shouldn't get that error. Did you declare "a" as a global
variable? did you include "tables.c" in your project?
Still, I don't understand why you don't use the '@' operator to place
the variable in info-flash. You eventually will have to.

Michael Kusch

--- In HYPERLINK "mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com,
"FB" wrote:
>
> Let me know if I made a mistake.
>
> I declare in "tables.c" :
> const float a = 2.0;
>
> and then in every "XXX.c" where need the reference to "a" i declare:
> extern const float a;
>
> and I get this message:
> Error[e46]: Undefined external "a" referred in XXX(
..\Debug\Obj\-XXX.r43 )
>
> It seems that the compiler is using a reference (in fact I can see
that into
> compiled asm; lst file) of that variable but then It can't find it.
> :(
>
> _____
>
> From: HYPERLINK "mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com
[mailto:HYPERLINK "mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com]
On
Behalf Of
> Anders Lindgren
> Sent: Micoles, 02 de Enero de 2008 05:56 a.m.
> To: HYPERLINK "mailto:msp430%40yahoogroups.com"msp430@yahoogroups.-com
> Subject: Re: [msp430] CONST IAR optimization
>
>
>
> > I have a software that need to have some values stored in flash.
> > As an example I defined:
> > const float dT = { 2 };
> >
> > Obviously 2 is the default value.
> > Now, when I pass the address of that variable to a function the
> > compiler do the right thing (In this case I can see dT defined in
the .map
> > file)
> > When I use the variable in any other part of the code (not passing
> > it as reference to a function) the compiler uses the default value
instead
> > the reference to a memory address.
> >
> > All this with high optimization option.
> >
> > I would like to know if you have a solution for me. How can I define
> > that variable so the compiler use it as reference in any case of
usage.
>
> Hi Bukitoo!
>
> The standard solution is the one that Albert suggested, place the
> variable with its initalization in one source file and declare it in a
> header file. That way the compiler will not assume that it knows the
> value of the variable.
>
> The reason why "const + volatile" doesn't work is because the standard
> explicitly states that such variables may not be placed in ROM.
>
> -- Anders Lindgren, IAR Systems
> --
> Disclaimer: Opinions expressed in this posting are strictly my own and
> not necessarily those of my employer.
>
>
>
>
>
>
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.17.5 - Release Date:
19/12/2007 12:00
> a.m.
>
>
>
> Internal Virus Database is out-of-date.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.17.5 - Release Date:
19/12/2007 12:00
> a.m.
>
>
>
>
>


Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.

Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.





FB wrote:
> Let me know if I made a mistake.
>
> I declare in "tables.c" :
> const float a = 2.0;
>
> and then in every "XXX.c" where need the reference to "a" i declare:
> extern const float a;
>
> and I get this message:
> Error[e46]: Undefined external "a" referred in XXX( ..\Debug\Obj\XXX.r43 )
>
> It seems that the compiler is using a reference (in fact I can see that into
> compiled asm; lst file) of that variable but then It can't find it.
> :(

Hi,

First, you should never put declarations in .c files, they should be in
a header file that the .c files (including tables.c) use.

The scheme seems correct, and I don't understand why you get the error
message. Let's check the basics:

* Is `table.c' included in the project? Does it contain any #ifdef:s
that could exclude the definition?

* Do you use C++? In C++, a "const float a = 2.0;" does not define a
variable object. (C++ recommends using this instead of #define.) There
are a number of tricks you can use to force this to be a variable
object: use the __root keyword, declare another variable that points to
"a", or use the keep_definition pragma.

* Do you mix C and C++? If so, you must use `extern "C"' around the
definition or declaration when C++ is used.

If it's none of the above, can you check the list file of `tables.c' if
the variable is generated?

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
REPLY IN RED BELOW
* Is `table.c' included in the project? Does it contain any #ifdef:s
that could exclude the definition?
YES
* Do you use C++? In C++, a "const float a = 2.0;" does not define a
variable object. (C++ recommends using this instead of #define.) There
are a number of tricks you can use to force this to be a variable
object: use the __root keyword, declare another variable that points to
"a", or use the keep_definition pragma.
I USE C++ ONLY.
I USED __ROOT AND THE ERROR IS THE SAME. WITHOUT __ROOT ALSO.

* Do you mix C and C++? If so, you must use `extern "C"' around the
definition or declaration when C++ is used.

If it's none of the above, can you check the list file of `tables.c' if
the variable is generated?
TABLES.LST HAS THE VARIABLE.
I TRANSFORMED TABLES.C INTO TABLES.H AND I INCLUDE IT IN THE .C WHERE ARE
USE MY VARIABLES AND IT WORKED.
________________________________

From: m... [HYPERLINK mailto:m...
mailto:m...] On Behalf Of Anders Lindgren
Sent: Jueves, 03 de Enero de 2008 07:40 a.m.
To: m...
Subject: Re: [msp430] CONST IAR optimization

FB wrote:
> Let me know if I made a mistake.
>
> I declare in "tables.c" :
> const float a = 2.0;
>
> and then in every "XXX.c" where need the reference to "a" i declare:
> extern const float a;
>
> and I get this message:
> Error[e46]: Undefined external "a" referred in XXX( ..\Debug\Obj\XXX.r43 )
>
> It seems that the compiler is using a reference (in fact I can see that
into
> compiled asm; lst file) of that variable but then It can't find it.
> :(

Hi,

First, you should never put declarations in .c files, they should be in
a header file that the .c files (including tables.c) use.

The scheme seems correct, and I don't understand why you get the error
message. Let's check the basics:

* Is `table.c' included in the project? Does it contain any #ifdef:s
that could exclude the definition?

* Do you use C++? In C++, a "const float a = 2.0;" does not define a
variable object. (C++ recommends using this instead of #define.) There
are a number of tricks you can use to force this to be a variable
object: use the __root keyword, declare another variable that points to
"a", or use the keep_definition pragma.

* Do you mix C and C++? If so, you must use `extern "C"' around the
definition or declaration when C++ is used.

If it's none of the above, can you check the list file of `tables.c' if
the variable is generated?

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.

Internal Virus Database is out-of-date.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.17.5 - Release Date: 19/12/2007 12:00
a.m.
Hi FB!

> If it's none of the above, can you check the list file of `tables.c' if
> the variable is generated?
>
> TABLES.LST HAS THE VARIABLE.

OK, NEXT STEP, CAN you list the object code and see if the object file
really contains the entry.
> I TRANSFORMED TABLES.C INTO TABLES.H AND I INCLUDE IT IN THE .C WHERE ARE
> USE MY VARIABLES AND IT WORKED.

I DOUBT that it really WORKED, at least if the idea is that real
variable object should be used and not the initial value.

-- Anders Lindgren, IAR Systems
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.