cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

DaHu_285096
Contributor II

Maybe the weather is a bit colder today and this explains it?

   

I am experiencing the compiler optimizing out most of my variables. I have made almost all of them volatile and still cannot prevent it happening. In the attached the array "Sensor[sensorLocation]" does not provide watch elements for the array and when I hover over "sensorLocation" the dialog announces it is "optimized out".

   

I have a variable called "NumSensors" in the header file of a header file. Several other modules access the variable (which is also made volatile).

   

The first module initializes the sensors and sets NumSensors ok. Then the first module calls another module (which does not use NumSensors at all), then when returned back to first module, NumSensors keeps setting back to 0. I had to move the declaration for NumSensors into the first module to prevent it loosing its value.

   

What could be causing this behavior? I never experienced this in Creatore 3.1, then started to get some of these issues with Creator 3.2 and now it appears much worse in 3.2 SP2. Is there some compiler directive or something 3.2 , SP2 is switching on that affects the variable values being held in memory?

0 Likes
1 Solution
JoMe_264151
Expert II

When variables are put into registers for optimization you will not see a correct value in the debugger.

   

I would suggest to

   

set compiler optimization to "None" (Remember you can set build options on a file base!)

   

assign Sensor[sensorlocation] to a variable and check that in debugger

   

 

   

Bob

View solution in original post

0 Likes
5 Replies
JoMe_264151
Expert II

When variables are put into registers for optimization you will not see a correct value in the debugger.

   

I would suggest to

   

set compiler optimization to "None" (Remember you can set build options on a file base!)

   

assign Sensor[sensorlocation] to a variable and check that in debugger

   

 

   

Bob

View solution in original post

0 Likes
DaHu_285096
Contributor II

Thanks Bob,

   

 

   

I did notice an issue with the way I declared the structs in the header files.

   

I thought I could declare the array variable in the header file without specifying the size like this "SensorType Sensor[];" and then specify size of array in the C file. However, it seems I when I do this I cannot view the array in the debugger, but when I explicitly set size in header file I can see the array elements in debugger.

   

typedef struct{
  uint8   fitted;
  uint16  detectedTagID;
  uint8   tripped;
  uint8   type;
  uint8   tripCount;
  uint8   tripLevel;
  uint8   location;
  uint8   lastRssi;
  uint8   noResponseTimeout;
  uint8   noResponseCount;
  uint8   noResponseTripped;
    
}SensorType;

   

extern volatile SensorType Sensor[MAXSENSORS];

0 Likes
JoMe_264151
Expert II

The purpose of C was not to make life easier, but more adventurous. 😉

   

 

   

Bob

0 Likes
DaHu_285096
Contributor II

And don't we all love a good adventure 🙂 

   

BTW: I am not getting email notifications for post replies since the Cypress web update, Is there an option hidden away somewhere I need to select?

   

Thanks

0 Likes
DaHu_285096
Contributor II

Sorry, I was being lazy, I found the setting in my Profile -> Forums