cancel
Showing results for 
Search instead for 
Did you mean: 

Why does this code not work properly in trueSTUDIO?

SWoon
Associate II

​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?

1 ACCEPTED SOLUTION

Accepted Solutions

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
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

1 REPLY 1

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
Up vote any posts that you find helpful, it shows what's working..