Using GPIO on STM32

0. Pin Map

On the STM32F446RET6 Nucleo board, the LD2 LED is connected to PA5, and the USER Button is connected to PC13.

Note: the LED is active high.

We will demonstrate how to set up a generic GPIO output pin with the LED, and a generic GPIO input pin with the user button.

1. Configure STM32

First, set the configuration from the Starter Project.

Click on PA5, set it to "GPIO_Output".

Click on PC13, set it to "GPIO_Input".

Save the .ioc file and generate code.

2. Code

First, add the code from the Starter Project.

In main.c, add the following code

After saving, upload the code

3. Result

We can see LED LD2 blinking, and when we press/release the USER Button, the serial output changes.

Last updated