My code does not set the GPIOs as inputs on my Nucleo-G071RB. The MODER register ist completly set (0xffffffff) and the GPIOs work as outputs.
What did I wrong?
Code:
#include <libopencm3/stm32/gpio.h>
void setupGpio(void);
void setupGpio(void) {
// set input
gpio_mode_setup(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN, GPIO_ALL);
}
int main(void){
setupGpio();
while (1)
{
// Loop with pin read
}
}
You need to enable peripheral clock first. Not only GPIO but almost all peripherals need this.
Modify your function as below:
void setupGpio(void) {
rcc_periph_clock_enable(RCC_GPIOB); // Enable GPIOB clock
gpio_mode_setup(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLDOWN, GPIO_ALL);
}