Does HAL callbacks save r0-r3 registers? Is it needed?
Hello,
We have random HardFaults on an STM32H750, maybe after several hours of uptime.
It seems caused by an access to a wrong RAM location, whose address is fetched from the stack and stored in r2.
But the stack seems OK.
This happens in a function frequently interrupted by a higher priority HAL DMA callback.
Inspecting it AFAIK registers r0-r3 are not preserved by GCC optimized at -O2.
It could be that sometimes this interrupt takes place between loading of r2 and its use, overwriting it with a wrong value.
Inside my callback function there are calls to other functions. Is this OK? I read somewhere that GCC saves only the registers it uses in the main function of the ISR and doesn't take care of register's use in called function. Don't know if it makes sense.
Adding __attribute__((interrupt)) does not seem to make any difference.
For now I added push and pop of the scratch registers in the callback and it seems to work, but I'm not completely sure because a slight timing difference could be enough to mask the problem.
It is also inconvenient, because the HAL library needs to be patched.
I am not convinced of anything I wrote before because it would break most code and it would have been spotted long ago.
Any comment?
Thanks and regards.
Alberto
