EmbeddedRelated.com
Forums
Memfault Beyond the Launch

CodeWarrior not initializing Vars

Started by Hawker May 31, 2007
Forgive me for I have broken engineering rule 1037.42.878....
For I am a hardware designer trying to write software.

Now that we have that out of the way...

I am using CW 5.1 and targeting a HCS09AW16
If in my global var declaration section I have.
    unsigned char GLOBAL_VAR = 0x00;
When I run the app GLOBAL_VAR is sometimes 00, but more often than not 
something random and not as assigned.

If I have
    unsigned char GLOBAL_VAR = 0x00;
........
void main(void) {
GLOBAL_VAR = 0x00;
.....
}

Everything works fine.
It seems I shouldn't need
GLOBAL_VAR = 0x00;

What am I missing?

Thanx
  Hawker
On May 31, 6:55 pm, Hawker
<Hawker{removethispa...@ashevillecommunity.org> wrote:
> Forgive me for I have broken engineering rule 1037.42.878.... > For I am a hardware designer trying to write software.
Repent!
> > Now that we have that out of the way... > > I am using CW 5.1 and targeting a HCS09AW16 > If in my global var declaration section I have. > unsigned char GLOBAL_VAR = 0x00; > When I run the app GLOBAL_VAR is sometimes 00, but more often than not > something random and not as assigned.
That's not right.
> > If I have > unsigned char GLOBAL_VAR = 0x00; > ........ > void main(void) { > GLOBAL_VAR = 0x00; > ..... > > } > > Everything works fine. > It seems I shouldn't need > GLOBAL_VAR = 0x00;
You're right, you shouldn't.
> > What am I missing?
I don't really know, but maybe I can get you pointed in the right direction... What is your environment? How are you examining the value of GLOBAL_VAR? Is there something in your environment that is interfereing with your application? E.g., a debug monitor whose RAM space overlays your application? What does your linker map file look like? Where is GLOBAL_VAR located? What is the name of the memory section? What does you compiler documentation say about that section? What happens if you remove the "= 0" from the variable declaration? (Uninitialized static data should be zeroed). Have you examined the startup code? You know, the stuff that gets executed before the function "main" gets called? Does your environment support the automatic initialization of global variables? Is such support optional? Do you have such support selected in your build configuration? Do you link in the memory section that contains the initialization records? All just guesswork, but you didn't give me much to work with. HTH, -=Dave
On May 31, 4:55 pm, Hawker
<Hawker{removethispa...@ashevillecommunity.org> wrote:
> Forgive me for I have broken engineering rule 1037.42.878.... > For I am a hardware designer trying to write software. > > Now that we have that out of the way... > > I am using CW 5.1 and targeting a HCS09AW16 > If in my global var declaration section I have. > unsigned char GLOBAL_VAR = 0x00; > When I run the app GLOBAL_VAR is sometimes 00, but more often than not > something random and not as assigned. > > If I have > unsigned char GLOBAL_VAR = 0x00; > ........ > void main(void) { > GLOBAL_VAR = 0x00; > ..... > > } > > Everything works fine. > It seems I shouldn't need > GLOBAL_VAR = 0x00; > > What am I missing? > > Thanx > Hawker
Maybe the name space conflict, use watch window to figure out the exact problem. Did you try to use name other than GLOBAL_VAR? I've never experienced such problem with CW. ali
Hello
Try increasing stack size, maybe it is stack overflow.
How did you create your project, with ANSI startup code or minimal
startup code?
Regards
Petr

Hawker wrote:
>
... snip ...
> > I am using CW 5.1 and targeting a HCS09AW16 > If in my global var declaration section I have. > unsigned char GLOBAL_VAR = 0x00; > When I run the app GLOBAL_VAR is sometimes 00, but more often > than not something random and not as assigned. > > If I have > unsigned char GLOBAL_VAR = 0x00; > ........ > void main(void) { > GLOBAL_VAR = 0x00; > ..... > } > > Everything works fine. It seems I shouldn't need > GLOBAL_VAR = 0x00;
Indeed. It appears as if your system doesn't properly initialize static memory on program start. -- <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt> <http://www.securityfocus.com/columnists/423> <http://www.aaxnet.com/editor/edit043.html> <http://kadaitcha.cx/vista/dogsbreakfast/index.html> cbfalconer at maineline dot net -- Posted via a free Usenet account from http://www.teranews.com
"Hawker" <Hawker{removethispart}@ashevillecommunity.org> a &#4294967295;crit dans le 
message de news: 5c95miF2vlidlU1@mid.individual.net...
> Forgive me for I have broken engineering rule 1037.42.878.... > For I am a hardware designer trying to write software. > > Now that we have that out of the way... > > I am using CW 5.1 and targeting a HCS09AW16 > If in my global var declaration section I have. > unsigned char GLOBAL_VAR = 0x00; > When I run the app GLOBAL_VAR is sometimes 00, but more often than not > something random and not as assigned. > > If I have > unsigned char GLOBAL_VAR = 0x00; > ........ > void main(void) { > GLOBAL_VAR = 0x00; > ..... > } > > Everything works fine. > It seems I shouldn't need > GLOBAL_VAR = 0x00; > > What am I missing? > > Thanx > Hawker
Hi, You have to use the ANSI Initialization when you're creating your project. All the RAM area will be clear to zero BEFORE your main function, your future global variables and your future stack (local variables). Yvan http://www.ybdesign.fr
Hmm. Good suggestion.
My stack is, I think 0x50 bytes long only.  Whatever the default was.
Code is small though, under 1k. Not to many vars.

I'm using the minimal startup code and I have all global vars in zero 
page RAM, of which there isn't much 0x7f - stack (0x50).

On 6/1/2007 2:33 AM, The digits of Petr Cach's hands composed the following:
> Hello > Try increasing stack size, maybe it is stack overflow. > How did you create your project, with ANSI startup code or minimal > startup code? > Regards > Petr >
On 5/31/2007 9:55 PM, The digits of Ali's hands composed the following:
> Maybe the name space conflict, use watch window to figure out the > exact problem. Did you try to use name other than GLOBAL_VAR? I've > never experienced such problem with CW.
Global Var was a made up name to simplify my explanation and not exactly what I am doing. The reality is I am having this issue with a few global vars.
On 6/1/2007 3:53 AM, The digits of Yvan BOURNE's hands composed the 
following:
> "Hawker" <Hawker{removethispart}@ashevillecommunity.org> a &#4294967295;crit dans le > message de news: 5c95miF2vlidlU1@mid.individual.net... >> Forgive me for I have broken engineering rule 1037.42.878.... >> For I am a hardware designer trying to write software. >> >> Now that we have that out of the way... >> >> I am using CW 5.1 and targeting a HCS09AW16 >> If in my global var declaration section I have. >> unsigned char GLOBAL_VAR = 0x00; >> When I run the app GLOBAL_VAR is sometimes 00, but more often than not >> something random and not as assigned. >> >> If I have >> unsigned char GLOBAL_VAR = 0x00; >> ........ >> void main(void) { >> GLOBAL_VAR = 0x00; >> ..... >> } >> >> Everything works fine. >> It seems I shouldn't need >> GLOBAL_VAR = 0x00; >> >> What am I missing? >> >> Thanx >> Hawker > > > > > Hi, > You have to use the ANSI Initialization when you're creating your project. > All the RAM area will be clear to zero BEFORE your main function, your > future global variables and your future stack (local variables). > > Yvan > http://www.ybdesign.fr > >
But wouldn't the fact that I assign the var to 0x00 when defined over ride that need? I'm using the quick start up, not ANSI because I need the processor to start VERY fast so I want as little overhead as possible.
"Hawker" <Hawker{removethispart}@ashevillecommunity.org> wrote in message 
news:5c95miF2vlidlU1@mid.individual.net...
> Forgive me for I have broken engineering rule 1037.42.878.... > For I am a hardware designer trying to write software. > > Now that we have that out of the way... >
<SNIP> Any hardware designer that can't write basic code to help debug their designs should not have a job! Thanks for learning. Keep up the good work. Scott

Memfault Beyond the Launch