cancel
Showing results for 
Search instead for 
Did you mean: 

freegcc compiler segmnetation fault

ivancolla9
Associate III
Posted on December 28, 2015 at 11:14

Good morning,

I have a strange problem with the FreeGCC compiler installed with the release 4.0 of SPC5Studio. The following code give me an internal compielr error: segmentation fault

if (*ubReadWinIndex != 255)
{
/* In the precedent reading cycle I have already found where it is the reading window. */
ulVoltage = ulPendingValues[*ubReadWinIndex];
*ubReadWinIndex = 255;
}
else
{
/* Analyse wave. */
UBYTE i = 1;
for (i = 1; i <= SAMPLES; i++)
{
ULONG y1 = ulPendingValues[i-1];
ULONG y2 = ulPendingValues[i];
/* Approximation of derivative calculated on a delta time of 20 milliseconds, as the span between measures. */
SLONG der = (y2-y1) / TIME_SPAN_IN_SAMPLES;
if (der >= POSITIVE_DERIVATIVE)
{
/* Found a rising front. The signal is flashing. */
isFlashing = TRUE;
systemStatus->ubReadingStatus = FLASHING_SIGNAL;
/* Reading window is after 250 ms*/
*ubReadWinIndex = i + READING_WINDOW;
if (*ubReadWinIndex <= SAMPLES)
{
/* Read the value*/
ulVoltage = ulPendingValues[*ubReadWinIndex];
*ubReadWinIndex = 255;
isToCheck = TRUE;
}
else
{
/* Reading window in the next 500ms. */
*ubReadWinIndex = 25 - *ubReadWinIndex;
isToCheck = FALSE;
}
break;
}
else if (der <= NEGATIVE_DERIVATIVE)
{
isFlashing = TRUE;
}
}
/* If the wave is not flashing, the signal is fixed. */
if(!isFlashing)
{
systemStatus->ubReadingStatus = FIXED_SIGNAL;
ulVoltage = ulPendingValues[READING_WINDOW];
isToCheck = TRUE;
}
}

The code is not yet elegant (it's a first implementation). It analyze a input wave and search the presence of derivative to identify the shape of this wave (continuous or ''flashing''). The problem is that this code, with the trial version of the HighTech compiler, compile. The new installed FreeGCC error give me a segmentation fault of the compiler in the last if [if(!isFlashing)]. The strange thing is that if I rmeove the check on the condition

/* If the wave is not flashing, the signal is fixed. */
//if(!isFlashing)
//{
systemStatus->ubReadingStatus = FIXED_SIGNAL;
ulVoltage = ulPendingValues[READING_WINDOW];
isToCheck = TRUE;
//}

then the code compile. I can also compile if I comment the for cycle. As I already said, the problem arose when I changed compiler. I cannot see where the problem is. Thank you. #compiler-segmentation-fault
3 REPLIES 3
Erwan YVIN
ST Employee
Posted on January 04, 2016 at 11:00

Hello Ivan ,

Could you confirm your options settings ?

Did you use ''-O2'' options  ?

could you try ''-O0'' options  ?

   Best Regards

                          Erwan

ivancolla9
Associate III
Posted on January 19, 2016 at 17:00

Hello wan35fr,

I tried your solution and it works like a charm.

Thank you very much. By the way, do you happen to know why this happens?

Erwan YVIN
ST Employee
Posted on January 20, 2016 at 09:15

Hello Ivan ,

the free compiler is a experimental version. (-O2 is sometimes not supported)

we have created an error report on this subject.

             Best regards

                               Erwan