I have created a new STM32 project using cube. I have changed
main.cpp and enabled
--cpp in the compiler. If something complains I add extern c so c++ can see it.
I have c++ code running "fine". However now that I started using interrupts I'm experiencing some problems.
I am using UART and HAL. I have defined
extern "C" void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart). When there is a new character in UART the interrupt is executed and the function called correctly. As far as I understand my code is running in c++ in the callback and should be able to access my objects methods.
I want to execute
m.onReceiveCharacter() from the callback where
m for now is a global variable in the
main.cpp file. The object has the method I try to call. I add that line to the interrupt and I can see with the debugger that the function is called and I can go trough it correctly.
However what happens is that sometimes (I still haven't found the logic) some of the members of
m change for no apparent reason. For example I have a private member
UART_HandleTypeDef* huart that is pointed to the right huart at the beggining when I initialize and after an interrupt (before even the
m.onReceiveCharacter() is executed) changes "randomly" to another address.
Usually, if I have a function in the main loop doing some operations on
m and the interrupt comes then suddenly the value of
huart is changed. The value of
huart is never changed in any way in the code and this happens before the interrupt code inside the function is called (but the callback function already entered to). I have seen similar issues with other variables that are also not to be changed.
Summary: Some of the members of my object change "randomly" to new values when an interrupt comes. What are the possible causes? I am using STM32F030R8, with a project generated by Cube, in Keil compiler version 5.