It does not enter an if statement

Sysprogs forums Forums VisualGDB It does not enter an if statement

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13024
    Hideto Naito
    Participant

    Hi all,

    I am in trouble because the if statement does not work.
    When we implemented simple Blinky using Ticker, it did not work as intended only at release build.
    Even with exactly the same source code, in the case of debug build and build of mbed homepage, it works as intended.

    The attached source code is the source code I wrote.It is a simple source code that the LED glows at 0.5 second intervals.

    Device:Archmax
    Toolchain:ARM toolchain Embedded toolchain(GCC 7.2.0; GDB 8.0.1) 7.2.0/8.0.1/r2

    #13028
    Hideto Naito
    Participant

    #include <mbed.h>

    /*sub routine registration———-*/

    void Blinky();
    void ActivateFlagLoop();
    DigitalOut myled(LED1);

    //Timer Setting
    Ticker intvTimer; // インターバルタイマ
    int BlinkCount = 0;

    bool FlagLoopFunction = false;
    /*mein program———————-*/
    int main()
    {
    //Cycle Setting

    intvTimer.attach_us(&ActivateFlagLoop, 10000); //100Hz
    while (true)
    {

    if (FlagLoopFunction) {
    //8msec

    //DebugOUT = true;

    FlagLoopFunction = false;

    Blinky();

    }
    else {
    }
    }
    }

    void Blinky()
    {
    BlinkCount += 1;
    if (BlinkCount > 50)
    {
    myled = !myled;
    BlinkCount = 0;
    }
    else
    {

    }
    }

    void ActivateFlagLoop() {

    if(!FlagLoopFunction) FlagLoopFunction = true;
    }

    #13029
    support
    Keymaster

    Hi,

    We would advise switching the output to disassembly and checking the assembly code that got produced. Most likely the GCC optimizer has optimized out some instructions modifying global variables.

    If this is the case, we would advise declaring those variables with the ‘volatile’ keyword to explicitly tell the optimizer that each access to them should be preserved.

    #13042
    Hideto Naito
    Participant

    Hi,

    It works.
    Thanks a lot.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.