Simvik

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 high

Learn it first

  • GPIO · Pin modes, push-pull versus open-drain, pulls, edge interrupts and debouncing.

More GPIO problems