AnsweredAssumed Answered

freegcc compiler segmnetation fault

Question asked by colla.ivan on Dec 28, 2015
Latest reply on Jan 20, 2016 by Erwan Y
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.

Outcomes