Traffic Light

Finite State Machine Exercise

Task

Light the three LEDs one at a time: red on PA0, then yellow on PA1, then green on PA2. Run the sequence twice, then leave all three off. The registers and bit fields are on the Datasheet tab.

Circuit

Block diagram: U1 STM32F4 drives three LEDs, PA2 green, PA1 yellow and PA0 red, each through a 330R resistor to ground, with a TP1 logic analyzer on all three nets

Pass condition

Each light goes out before the next one comes on, in the order red, yellow, green. There are twelve edges, four per pin. Timing is not graded.

Expected trace: PA0, PA1 and PA2 each pulse twice in turn, red, then yellow, then green, twelve edges in all, every light going out before the next comes on

Notes

This question needs no clock enable. Your program is built and run at -O0, then again at -O2, and must pass both.

Related challenges

Loading the interactive arena.