Chokepoint
STM32 Emergency Stop Too Slow Debug
Symptom
On a conveyor's motor controller, a big red stop button must cut the motor at once, whatever else the chip is doing. Every 10 ms the controller also radios a short status report. That report is a telemetry packet. A colleague wrote the program, and the stop is sometimes late.
What it should do: stop button pressed -> PA5, the motor's power, low within 1 ms
What it does instead: pressed while a packet goes out (PA6 high) -> PA5 stays high until the packet ends, up to 4 ms later pressed between packets -> PA5 low at once
Find the mistake in main.c and fix it.
Circuit
Pass condition
PA5 goes low within 1 ms of a stop press, even in the middle of a packet. The telemetry still goes out every 10 ms.
Notes
The stop button drives PA0 high for 1 ms, once, while your program runs. An interrupt makes the chip pause its work and run a function. It is called a handler. TIM2 is a timer. Each telemetry packet is sent from TIM2's handler and stays there.