Upside Down

STM32 Button Reads Inverted Debug

Symptom

The simplest test for a button on a new board is a lamp that lights only while the button is held. A colleague wrote that program for this board, and it is broken.

What it should do: button on PA0 held -> LED on PA5 on button up -> LED off

What it does instead: the LED is on while nobody touches the button, and goes off while the button is held.

Find the mistake in main.c and fix it. While your program runs, the button is pressed and released, and a logic analyzer records PA5.

Circuit

Block diagram: R2 10k pulls the BTN wire up to +3V3 and SW1 pushbutton joins it to ground when pressed; BTN goes into U1 STM32F4 pin PA0, and pin PA5 drives R1 330R into D1 LED to ground, with a TP1 logic analyzer probe on the PA5 net

Pass condition

From power-up on, for as long as the board runs: button held -> PA5 high; button up -> PA5 low. PA5 changes only when the button does. Timing is not graded.

Expected output: two shaded bands where the button is held, and PA5 high during each band and low otherwise, four edges in all

Related challenges

Loading the interactive arena.