The Fly

STM32 1ms Timer Interrupt Exercise

Task

Someone uploaded a fly's brain to this board. Every millisecond the brain updates every neuron in one step, then the chip rests until the next one. The beat comes from a timer called SysTick, inside the core. The core is the part of the chip that runs your code. Once a millisecond SysTick interrupts the core, which pauses main, runs a short function called a handler, then picks up where it left off.

Use those interrupts to toggle the LED on PA5 every 50 ms, so anyone watching can see the brain is still ticking: PA5 toggles at 50 ms, 100 ms, 150 ms, and so on, for as long as the board runs Count the interrupts in SysTick_Handler. In main, toggle the LED every 50 of them and sleep between ticks.

Circuit

Block diagram: U1 STM32F4 pin PA5 drives R1 330R into D1 LED to ground, with a TP1 logic analyzer probe on the PA5 net

Pass condition

PA5 toggles every 50 ms, first at 50 ms after reset. The core takes one SysTick interrupt every millisecond and sleeps between them.

Expected output for the quarter-second test: PA5 low at reset, then toggling at 50, 100, 150, 200 and 250 ms, five edges with the first one rising, while the core takes the SysTick interrupt 275 times, once every millisecond

Related challenges

Loading the interactive arena.