Sign in

username:

password:



Not a member?

Search msp430



Search tips

Subscribe to msp430



Ads

Discussion Groups

Discussion Groups | MSP430 | Static int declaration and initialization

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

Static int declaration and initialization - Mirko Viviani - Sep 2 9:17:12 2008

Using IAR on a MSP430F1611 (MSP430 family) this piece of code does not work
(printf will print something else than 23)
I cannot split the inizialization from declaration (source code cannot be
modified): any idea?

static int i=23;
void main()
{
printf("%d",i);
}

Obviously splitting initialization from declaration works.

--
-- Mirko Viviani --
GPG-PGP Public Key: 0xE4E8FAB1
Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
***********************************************
""Machines take me by surprise with great frequency." A. Turing
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )


Re: Static int declaration and initialization - old_cow_yellow - Sep 2 10:34:03 2008

I suspect that printf("%d",23); will also print something else than
23. Can you try that?

--- In m...@yahoogroups.com, "Mirko Viviani" wrote:
>
> Using IAR on a MSP430F1611 (MSP430 family) this piece of code does
not work
> (printf will print something else than 23)
> I cannot split the inizialization from declaration (source code
cannot be
> modified): any idea?
>
> static int i=23;
> void main()
> {
> printf("%d",i);
> }
>
> Obviously splitting initialization from declaration works.
>
> --
> -- Mirko Viviani --
> GPG-PGP Public Key: 0xE4E8FAB1
> Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
> ***********************************************
> ""Machines take me by surprise with great frequency." A. Turing
> [Non-text portions of this message have been removed]
>

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Re: Static int declaration and initialization - Mirko Viviani - Sep 2 10:37:20 2008

it prints correctly 23 ;)

2008/9/2 old_cow_yellow

> I suspect that printf("%d",23); will also print something else than
> 23. Can you try that?
> --- In m...@yahoogroups.com , "Mirko Viviani"
> wrote:
> >
> > Using IAR on a MSP430F1611 (MSP430 family) this piece of code does
> not work
> > (printf will print something else than 23)
> > I cannot split the inizialization from declaration (source code
> cannot be
> > modified): any idea?
> >
> > static int i=23;
> > void main()
> > {
> > printf("%d",i);
> > }
> >
> > Obviously splitting initialization from declaration works.
> >
> > --
> > -- Mirko Viviani --
> > GPG-PGP Public Key: 0xE4E8FAB1
> > Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
> > ***********************************************
> > ""Machines take me by surprise with great frequency." A. Turing
> >
> >
> > [Non-text portions of this message have been removed]
> >
>

--
-- Mirko Viviani --
GPG-PGP Public Key: 0xE4E8FAB1
Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
***********************************************
""Machines take me by surprise with great frequency." A. Turing
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Static int declaration and initialization - old_cow_yellow - Sep 2 11:30:33 2008

I cannot try printf(). But "static int i=23;" works for me.

Specifically, the compiler did the following:

a) Assigned a word in RAM for the variable "i"
b) Assigned a word in FLASH and stored a constant "23" (0x0017) in it.
c) In the c startup code, call "__data16_memcpy()" to copied the
constant "23" to the variable "i".
--- In m...@yahoogroups.com, "Mirko Viviani" wrote:
>
> Using IAR on a MSP430F1611 (MSP430 family) this piece of code does
not work
> (printf will print something else than 23)
> I cannot split the inizialization from declaration (source code
cannot be
> modified): any idea?
>
> static int i=23;
> void main()
> {
> printf("%d",i);
> }
>
> Obviously splitting initialization from declaration works.
>
> --
> -- Mirko Viviani --
> GPG-PGP Public Key: 0xE4E8FAB1
> Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
> ***********************************************
> ""Machines take me by surprise with great frequency." A. Turing
> [Non-text portions of this message have been removed]
>

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Static int declaration and initialization - Anders Lindgren - Sep 3 5:32:01 2008

Hi!

Just to eliminate the obvious -- did you include the header file "stdio.h"?

If not, then you should have listened to the compiler warnings (they are
there for a reason). On the other hand, if you did include it you should
have included it in the example you posted here.

If we assume that that is not the issue, what is the value of the
variable "i" if you debug the application?

What settings do you use? (Optimization levels, data models etc.)

-- Anders Lindgren, IAR Systems

Mirko Viviani wrote:
> Using IAR on a MSP430F1611 (MSP430 family) this piece of code does not work
> (printf will print something else than 23)
> I cannot split the inizialization from declaration (source code cannot be
> modified): any idea?
>
> static int i=23;
> void main()
> {
> printf("%d",i);
> }
>
> Obviously splitting initialization from declaration works.

--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Static int declaration and initialization - Mirko Viviani - Sep 4 2:35:20 2008

the problem was in the custom cstartup code.
By replacing it with the default one, no more problems occurred.

Thanks a lot for the tips!

2008/9/3 Anders Lindgren

> Hi!
>
> Just to eliminate the obvious -- did you include the header file "stdio.h"?
>
> If not, then you should have listened to the compiler warnings (they are
> there for a reason). On the other hand, if you did include it you should
> have included it in the example you posted here.
>
> If we assume that that is not the issue, what is the value of the
> variable "i" if you debug the application?
>
> What settings do you use? (Optimization levels, data models etc.)
>
> -- Anders Lindgren, IAR Systems
> Mirko Viviani wrote:
> > Using IAR on a MSP430F1611 (MSP430 family) this piece of code does not
> work
> > (printf will print something else than 23)
> > I cannot split the inizialization from declaration (source code cannot be
> > modified): any idea?
> >
> > static int i=23;
> > void main()
> > {
> > printf("%d",i);
> > }
> >
> > Obviously splitting initialization from declaration works.
>
> --
> Disclaimer: Opinions expressed in this posting are strictly my own and
> not necessarily those of my employer.
>
>
>

--
-- Mirko Viviani --
GPG-PGP Public Key: 0xE4E8FAB1
Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
***********************************************
""Machines take me by surprise with great frequency." A. Turing
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Static int declaration and initialization - "Richard (UK)" - Sep 4 6:28:35 2008

>>> the problem was in the custom cstartup code. By replacing it with the
>>> default one, no more problems occurred.

... but ... but ... but ... you didn't tell us that you had changed the
startup code!

If you change a very major part of the system such as the startup code and
then basic C code stops working, then maybe just maybe you might have broken
something!

If you had provided FULL information then maybe you would have had an
instant & correct reply.

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Re: Static int declaration and initialization - Mirko Viviani - Sep 4 7:00:53 2008

I though at cstartup code only after the old_cow_yellow response.
Anyway, thanks to everybody!

2008/9/4 Richard (UK)

> >>> the problem was in the custom cstartup code. By replacing it with
> the
> >>> default one, no more problems occurred.
>
> ... but ... but ... but ... you didn't tell us that you had changed the
> startup code!
>
> If you change a very major part of the system such as the startup code and
> then basic C code stops working, then maybe just maybe you might have
> broken
> something!
>
> If you had provided FULL information then maybe you would have had an
> instant & correct reply.
>
>
>

--
-- Mirko Viviani --
GPG-PGP Public Key: 0xE4E8FAB1
Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
***********************************************
""Machines take me by surprise with great frequency." A. Turing
[Non-text portions of this message have been removed]
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Custom startup routine Re: Static int declaration and initialization - Stuart_Rubin - Sep 4 8:56:41 2008

My experience has been that custom startup code causes more problems
than it's worth. To the original poster, would you please give us
some insight as to why you needed to customize it?

My (limited) experience has been that any optimizations are
overwhelmed by the complications and potential for problems (as shown
by the poster). If you need RAM or some hardware initialized in some
special way, why didn't you just do it at the top of main()? On an
MSP430, there is so little RAM, and I'm sure very little of it get
pre-initialized.

The only time I've seen a custom startup routine make sense (and I
actually don't agree that it was the best way to do it) was in an
avionics application where a restart was implicitly due to a power
blip and certain hardware had to be initialized quickly.

This is not a criticism, but I really do want to know what drove that
design decision.

Thanks.

Stuart
--- In m...@yahoogroups.com, "Mirko Viviani" wrote:
>
> the problem was in the custom cstartup code.
> By replacing it with the default one, no more problems occurred.
>
> Thanks a lot for the tips!
>
> 2008/9/3 Anders Lindgren > Hi!
> >
> > Just to eliminate the obvious -- did you include the header file
"stdio.h"?
> >
> > If not, then you should have listened to the compiler warnings
(they are
> > there for a reason). On the other hand, if you did include it you
should
> > have included it in the example you posted here.
> >
> > If we assume that that is not the issue, what is the value of the
> > variable "i" if you debug the application?
> >
> > What settings do you use? (Optimization levels, data models etc.)
> >
> > -- Anders Lindgren, IAR Systems
> >
> >
> > Mirko Viviani wrote:
> > > Using IAR on a MSP430F1611 (MSP430 family) this piece of code
does not
> > work
> > > (printf will print something else than 23)
> > > I cannot split the inizialization from declaration (source code
cannot be
> > > modified): any idea?
> > >
> > > static int i=23;
> > > void main()
> > > {
> > > printf("%d",i);
> > > }
> > >
> > > Obviously splitting initialization from declaration works.
> >
> > --
> > Disclaimer: Opinions expressed in this posting are strictly my own and
> > not necessarily those of my employer.
> >
> >
> > --
> -- Mirko Viviani --
> GPG-PGP Public Key: 0xE4E8FAB1
> Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
> ***********************************************
> ""Machines take me by surprise with great frequency." A. Turing
> [Non-text portions of this message have been removed]
>

------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )

Custom startup routine Re: Static int declaration and initialization - Stuart_Rubin - Sep 4 10:04:43 2008

All, I do want to clarify that on the projects which used custom
startup routines were NOT MSP430-based systems. They happen to have
been 68HC12 and ARM9 boards, but I still maintain that the
customizations had questionable utility at best.

Stuart

--- In m...@yahoogroups.com, "Stuart_Rubin" wrote:
>
> My experience has been that custom startup code causes more problems
> than it's worth. To the original poster, would you please give us
> some insight as to why you needed to customize it?
>
> My (limited) experience has been that any optimizations are
> overwhelmed by the complications and potential for problems (as shown
> by the poster). If you need RAM or some hardware initialized in some
> special way, why didn't you just do it at the top of main()? On an
> MSP430, there is so little RAM, and I'm sure very little of it get
> pre-initialized.
>
> The only time I've seen a custom startup routine make sense (and I
> actually don't agree that it was the best way to do it) was in an
> avionics application where a restart was implicitly due to a power
> blip and certain hardware had to be initialized quickly.
>
> This is not a criticism, but I really do want to know what drove that
> design decision.
>
> Thanks.
>
> Stuart
> --- In m...@yahoogroups.com, "Mirko Viviani" wrote:
> >
> > the problem was in the custom cstartup code.
> > By replacing it with the default one, no more problems occurred.
> >
> > Thanks a lot for the tips!
> >
> > 2008/9/3 Anders Lindgren
> >
> > > Hi!
> > >
> > > Just to eliminate the obvious -- did you include the header file
> "stdio.h"?
> > >
> > > If not, then you should have listened to the compiler warnings
> (they are
> > > there for a reason). On the other hand, if you did include it you
> should
> > > have included it in the example you posted here.
> > >
> > > If we assume that that is not the issue, what is the value of the
> > > variable "i" if you debug the application?
> > >
> > > What settings do you use? (Optimization levels, data models etc.)
> > >
> > > -- Anders Lindgren, IAR Systems
> > >
> > >
> > > Mirko Viviani wrote:
> > > > Using IAR on a MSP430F1611 (MSP430 family) this piece of code
> does not
> > > work
> > > > (printf will print something else than 23)
> > > > I cannot split the inizialization from declaration (source code
> cannot be
> > > > modified): any idea?
> > > >
> > > > static int i=23;
> > > > void main()
> > > > {
> > > > printf("%d",i);
> > > > }
> > > >
> > > > Obviously splitting initialization from declaration works.
> > >
> > > --
> > > Disclaimer: Opinions expressed in this posting are strictly my
own and
> > > not necessarily those of my employer.
> > >
> > >
> > >
> >
> >
> >
> > --
> > -- Mirko Viviani --
> > GPG-PGP Public Key: 0xE4E8FAB1
> > Fingerprint: 14D3 A373 E926 7737 DF32 502B A4C4 1CE2 E4E8 FAB1
> > ***********************************************
> > ""Machines take me by surprise with great frequency." A. Turing
> >
> >
> > [Non-text portions of this message have been removed]
>
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )