Skip to main content
SWoon
Associate II
Feb 27, 2019 5:25 AM UTC
Solved

Why does this code not work properly in trueSTUDIO?

​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.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Feb 27, 2019 6:20 AM UTC

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..

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Feb 27, 2019 6:20 AM UTC

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..