Tutorial: STM32F746 (STM32F7 Discovery) – how to turn on/off LED by button

This is another continue of STM32 tutorial (STM32F746 tutorial). I would like to show example code for turn on/off LED with button.

This example code is able to use for another microcontrollers by ST as STM32L100, L152, STM32F103, F407 and more.

LED is connected to PORT I, GPIO 1. Button is connected to PORT I, GPIO 11.

Other tutorials with STM32F7:
Tutorial: STM32F746 (STM32F7 Discovery) – how to turn on/off LED by button
Tutorial: STM32F746 (STM32F7 Discovery) – how to turn on LED (controlling GPIO)
STM32F746 discovery and AC6 (System Workbench for STM32)
How to begin with STM32 and why – tutorial

Button pinout is showed on these pictures:

The example code will be describe with comments.
main.h



main.c

Be careful if you have LED and BUTTON on same PORT. Don’t reset peripheral again.

You can use this code for setting of OSPEEDR of PORT.

If you have LED on another PORT then BUTTON, you shall enable both peripherals (I mean enable e.g. PORTx and PORTy)

Project by AC6 System Workbench for STM32 is here.

Other tutorials with STM32F7:
Tutorial: STM32F746 (STM32F7 Discovery) – how to turn on/off LED by button
Tutorial: STM32F746 (STM32F7 Discovery) – how to turn on LED (controlling GPIO)
STM32F746 discovery and AC6 (System Workbench for STM32)
How to begin with STM32 and why – tutorial

Share the article:
Show your
Maker soul!
Buy a T-Shirt
Coffee for Chiptron
Give a boost to the next article

Related Articles

The first article from Tutorial: STM32F746 (STM32F7 Discovery) serie. I would like to describe how to turn on LED simply controlling GPIO. Why I began to write this tutorial and why I don’t want to use HAL or Standard Peripheral…

We wrote a news about STM32F746 discovery and IDE by openstm32.org on the google+. https://time4ee.com/ got development board STM32F7 discovery by ST. We want to show MULTIPLATFORM (Linux – Ubuntu, Windows) development tools by http://openstm32.org Other tutorials with STM32F7: Tutorial:…

Digital Discovery is a crucial add-on if you have been using Analog Discovery 2, but its sampling rate was insufficient, there were not enough digital channels available, or there was too much noise to read data sent at higher speeds.…

A new member to STM32F7 family (e.g. also STM32F746 and STM32F769). STM32F723. STM32F723 is based on ARM? Cortex?-M7 32-bit RISC core with up to 216 MHz frequency. The microcontroller includes 512 kB FLASH and 256 kB SRAM. Clock, reset and…

The first article about STM32duino described “How to start with STM32 like Arduino. The second article of tutorial describes how to control GPIO – digital input, output and also PWM output. All articles about STM32duino: STM32duino I. – How to…