uTimerLib icon indicating copy to clipboard operation
uTimerLib copied to clipboard

STM32F103 freezing after a short while - worked fine before.

Open AndKe opened this issue 11 months ago • 4 comments

I set a timer for 50ms The failed function does not need to do anything - it usually just set a variable.

After a short while, the uC will freeze.

This worked fine half a year ago, when I last compiled this program. now it fails after a while.

(I omitted the use of this library to solve it.)

AndKe avatar Mar 13 '25 14:03 AndKe

May marking the variable used inside interrupt as "volatile" solve the issue?

If you share a failing code would be useful; still I'll try to recreate.

Naguissa avatar Mar 13 '25 14:03 Naguissa

I also tried replacing the variable with just delayMicroseconds(1)

The program is big with some custom libraries and dependencies, but the gist is: stm32_core is used. MAVLink library is used (not uC specific) two HW serial ports are used, one in one-wire bidirectional mode. CDC serial is used. a few other libraries that I could disable also proved to be invariant to this issue.

All I needed/used was:

TimerLib.setInterval_us(timer20hzEvent, 50000);

void timer20hzEvent() { timer20hz = true; }

This had worked for years. The main loop checked variable timer20hz. As mentioned, I also tried to replace setting the variable with just a small delay. The main loop runs for a short while (I did not time it - but I doubt it was as much as one sec) - then everything stopped.

It is years since I changed the essential parts of this code.

This could very well be some super-odd case of some incompatibility between updated libraries/compiler...

AndKe avatar Mar 13 '25 14:03 AndKe

If you check the code, it has been 3 years since last change: https://github.com/Naguissa/uTimerLib/tree/master/src/hardware

Using delay inside interrupts is a no-go.

timer20hz variable should be declared as volatile.

As stmt2_core I understand official ST core, right? It's not Roger Clark one.

As implementation has not changed I suspect something changed on ST core; I'll try to recreate when I have some spare time.

Naguissa avatar Mar 13 '25 15:03 Naguissa

Yes, official ST core I also tried older Arduino IDE 2.3.2, and older ST-code, and failed to make it work. ST Core had more releases recently, but if up/downgrade system works as intended - that's not it. Thank you.

AndKe avatar Mar 13 '25 15:03 AndKe

I've overhauled STM32 implementation using volatile static variables and static methods. I've tested on both cores (ST and Roger one) and seems to work like a charm.

Could you test it? It should be available in one or two hours at Arduino IDE or you can download it from releases page, it's version 1.7.4

Cheers!

Naguissa avatar Apr 22 '25 14:04 Naguissa

No response, I understand it's fixed by my tests.

Naguissa avatar Apr 26 '25 14:04 Naguissa