Fix: the debugger cannot connect any more
Configuring one pin overwrites the mode of every other pin of the port, the debug pins included. An easy embedded C problem (GPIO), run and graded in the…
easy · GPIO · find-the-bug · driver · gpio · swd · read-modify-write
Bug report. Since the LED code was added, the LED on PA5 works, but the debugger can no longer connect to the board after reset, and the UART on PA2 and PA3 stopped working too. The port is simulated like an STM32F4's, and it reports what happened to the debug pins. Fix it by changing one line.
Starter code
void led_init(void) {
GPIOA->MODER = 1u << (LED_PIN * 2);
}
void led_on(void) {
GPIOA->BSRR = 1u << LED_PIN;
}Example tests
Turn the LED on
led_init();
led_on();Expected output:
gpioa: pin 5 highLearn it first
- GPIO · Pin modes, push-pull versus open-drain, pulls, edge interrupts and debouncing.
More GPIO problems
- Update several pins at once · Write new levels to the pins selected by a mask and leave every other pin alone.
- Toggle an LED · Flip one pin with a single XOR, whatever its current level.
- Read an active-low button · A button wired to ground reads 0 when pressed. Report it as pressed.
- Configure pin modes · Set the direction and pull-up bits for one pin as input, input with pull-up or output.
- Driver: drive an LED through GPIO registers · Make a pin an output without disturbing its neighbours, then set, clear and toggle it atomically.
- Driver: a debounced button on PC13 · Configure an input with its pull-up, then report each press once, ignoring contact bounce.
- Smart doorbell: one ring per press · Debounce a bouncing button sampled every millisecond, so one press rings once.