This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP432P401R: delay implementation

Part Number: MSP432P401R


Tool/software: TI C/C++ Compiler

void Delay(uint16_t msec){
    uint32_t i=0;
    uint32_t time=(msec/1000)*(SYSTEM_CLOCK_SPEED/15);

    for(i=0;i<time;i++);
}

This is the delay used in the grlib example for the Kentec touchscreen. I notice that I is not even marked volatile. Shouldn't this get optimized away? Do I need to be careful if I add optimization? Is the compiler smart enough to see the word "delay" and leave it alone? 8^)

  • Keith Barkley said:
    Shouldn't this get optimized away?

    It does get optimized away if --opt_level=2 or higher is used.

    Keith Barkley said:
    I notice that I is not even marked volatile.

    While a bit of a hack, marking the variable i volatile is a good solution here.

    I will find the team responsible for this code and let them know about the problem.

    Thanks and regards,

    -George

**Attention** This is a public forum