Mohammad Nabidoust
Published © MIT

Blinking LED Magic with STM32 - Bare-Metal

This project blinks an LED on an STM32 microcontroller using pure bare-metal programming by directly configuring registers.

ExpertFull instructions provided1 hour107
Blinking LED Magic with STM32 - Bare-Metal

Things used in this project

Hardware components

STM32F7 Series
STMicroelectronics STM32F7 Series
×1

Software apps and online services

STMicroelectronics STM32CubIDE

Hand tools and fabrication machines

STMicroelectronics STLink

Story

Read more

Schematics

Schematic

Code

LED blanking Bare-Metal library

C/C++
#include "stm32g474xx.h"

void delay(volatile uint32_t t)
{
    while(t--);
}

int main(void)
{
    /* Enable GPIOF clock */
    RCC->AHB2ENR |= RCC_AHB2ENR_GPIOFEN;

    /* PF2 output */
    GPIOF->MODER &= ~(3U << (2 * 2));
    GPIOF->MODER |=  (1U << (2 * 2));

    /* Push-pull */
    GPIOF->OTYPER &= ~(1U << 2);

    /* LED OFF initially (PF2 = 1) */
    GPIOF->BSRR = ~(1U << 2);

    while (1)
    {
        /* LED ON (PF2 = 0) */
        GPIOF->BSRR = (1U << (2 + 16));
        delay(800000);

        /* LED OFF (PF2 = 1) */
        GPIOF->BSRR = (1U << 2);
        delay(800000);
    }
}

Credits

Mohammad Nabidoust
9 projects • 4 followers
STM32xx projects Design, Circuit PCB Design, Medical, Industrial, Power supply

Comments