Topic : Variable Initialisation Issues

Forum : 8051

Original Post
Post Information Post
February 4, 2010 - 6:03pm
Guest

Hi,

I have been observing some very strange behaviour with my installation of Raisonance (RIDE: 06.10.22; 80C51: 6.4.53) whilst used with a SiLabs C8051F310. I have the following initialisation code in my C file, it's a global variable, where the enumerate mentioned has a hard coded value and the __NUM_MEM_DEV is #defined to be 4.

const tDeviceList SpiMemoryDevices[ __NUM_MEM_DEV ]= {{/*"Flash_0",*/1,1,eNumonyxM25P32,0,0,0},
{/*"Flash_1",*/1,2,eNumonyxM25P32,0,0,0},
{/*"Flash_2",*/1,3,eNumonyxM25P32,0,0,0},
{/*"Flash_3",*/1,4,eNumonyxM25P32,0,0,0}};

First Problem:

I have seen this mentioned in the forum before, but no explanation as to the cause. When the string was present in the structure, the build seemed to fail to complete correctly. When I could get the code to run I suffered from behaviour that seemed to look like stack corruption, returning to the wrong place etc. Removing code libraries built at the same time, removing other objects made no difference. I removed the string from the structure, and the compiler informed me of two basic syntax errors it had previously failed to find and then ran fine, including when previously removed libraries were returned to the code. This makes me think the initialisation of static data in the compiler had somehow been knocked over by the inclusion of string data in the startup.... Does this sound probable?

Second Problem:

Having got the code to run minus my strings, I found that my data didn't seem to be correct. So I looked in the forum at some other topics and found some relating to data initialisation... Following the suggestion in that topic I started the code up using the simulator, rather than the target hardware. I found that the data gets initialised in the simulator, but NOT in the target hardware... I base this on starting the code up, taking a couple of steps and looking at the values in the global variable.

Erm help....

Cheers,

Rob

Replies
Post Information Post
+1
0
-1
February 5, 2010 - 3:56pm
Raisonance Support Team

Hi Rob,

It seems to be a startup problem in the data initialization, but could you provide us more information?

What is the memory space of your variable? Or what memory model do you use?
And what is the address of your variable in the memory map (information is available in the linker map file)?

If you also want us to give you some information about your string problem, could you give us the declaration of tDeviceList ?

Regards,

Stéphane

+1
0
-1
February 5, 2010 - 4:10pm
Guest

Hi Stephane,

I am still getting used to this idea of placing code on a public forum to get tech support.... ;)

The structure definition is :

typedef enum { eWibbleDev = 0x01, eNumonyxM25P32=0x00 } tSupportedMemDev;

typedef struct {
//char DevName[12];
unsigned_8 PortNumber;
unsigned_8 ChipSelectPin;
tSupportedMemDev DeviceType;
unsigned_8 __devicesRemaining; // Reserved.
unsigned_32 __startAddress; // Reserved.
unsigned_32 __endAddress; // Reserved.

}tDeviceList;

I am using the Large memory model, the address of the variable in memory seems to change depending on if the problem is currently present or not. I noticed that when the problem is present the address is very low in Xdata, when it isn't it's up about 0x0100 in xdata.

I noticed that when the char[] was not commented out the startup code seemed to fail to complete at all. The RIDE environment sat with a Red running light on and the green GO never appeared. This looks very like an "undocumented feature"....

Forgive my daft question, but are you from Raisonance or are you a user like myself? I'd be quite happy to share more info with the company in a private forum, but I have to be careful with my client confidentiality in submitting code in public.

Any help you can offer is very welcome, please feel free to ask for more info if it would help. I will just have to be careful what I can post on here. ;)

Cheers,

Rob

+1
0
-1
February 5, 2010 - 5:21pm
Raisonance Support Team

Yeap Rob, I'm a Raisonance guy ;o)

We try to figure out your issue with a little sample, but XData initialization is always okay and by the way DevName initialization with string doesn't make any trouble.

Is it possible for you to send your whole project to Raisonance support (support@raisonance.com)?

Stéphane

+1
0
-1
February 5, 2010 - 6:11pm
Guest

Hi Stephane,

An e-mail address.. ;)

OK, what I can do is bundle a copy of the project that is failing and send it to you. That would be the best way I think. I will try to recreate a version which is failing in the two differing ways. I am working with the Silicon Labs C8051 Development Kit board at the moment, the USB one. I will need to peruse it for anything I shouldn't send, so I am guessing I will get it over to you on Monday.

Cheers,

Rob

+1
0
-1
February 8, 2010 - 4:02pm
Raisonance Support Team

Hi Rob,

2 solutions:
-uncheck Use external stack in the Memory Panel of the RC51 options.
or
-add the following line on any C file to tell the startup to properly initialize HPD_ADDR
#pragma DEFJ(HPD_ADDR=0xAA)

See C8051F31x.pdf page 119

Regards,

Stéphane

PS: it's already too late for the e-mail address!