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

Circuit: SW1, the stop button, pulses PA0 of U1 STM32F4; PA5 drives the enable input of U3, the motor driver, which runs the motor while PA5 is high; PA6 keys U4, the telemetry radio; a TP1 logic analyzer has CH0 on PA5 and CH1 on PA6

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.

Expected trace: PA6, the radio key, is high for a 4 ms packet at 10, 20 and 30 ms; the stop button pulses PA0 at 12 ms, in the middle of the first packet; PA5, the motor, is high from power-up and goes low within 1 ms of the press, before the packet ends, and the packets carry on

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.

Related challenges

Loading the interactive arena.