Skip to main content
SWoon
Associate II
February 27, 2019
Solved

Why does this code not work properly in trueSTUDIO?

  • February 27, 2019
  • 1 reply
  • 792 views

​Hi.

​

I changed the debugging tool from IAR to trueSTUDIO for STM32.

​

There is code that IAR created and completed the operation. However, the same code, but does not work in trueSTUDIO.

​

An example of the code is shown below.

​

int a = 0;

​

void HAL_TIM_PeriodElapsedCallback (TIM_HandleTypeDef * htim)

{

a ++;

}

​

void example_function()

{

 a = 0;

while (a <3)

{

    asm volatile ("NOP");

}

}

​

int main()

{

example_function();

while(1)

{

}

}​

​

I found the cause with a breakpoint in trueSTUDIO, and I can not get out of the while statement with the code below.

 asm volatile ("NOP");

​

What is the difference between IAR and trueSTUDIO?

​

What is the solution to this situation?

​

This topic has been closed for replies.
Best answer by Tesla DeLorean

The variable should be declared volatile. The callback is called under interrupt context, outside normal code flow. GNU/GCC is likely optimizing things out because the variable isn't defined/classified properly.

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
February 27, 2019

The variable should be declared volatile. The callback is called under interrupt context, outside normal code flow. GNU/GCC is likely optimizing things out because the variable isn't defined/classified properly.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..