Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Thursday, February 19, 2015

STM32F4 Discovery Tutorial 2 - Simple LED Blinking

In this tutorial, I will explain how to make a simple blinking LED on STM32F4 Discovery. First, you have to make new project from menu Project  New Project. Give the project name and select folder for that project. 


Next, select model based on chip and then search for STM32F407VG.


To make blinking led you must use the I/O port. To do this you can simply check the GPIO checkbox on repository tab. Three checkbox will automatically checked after you checked the GPIO checkbox (M4 CMSIS Core, CMSIS Boot, RCC).


The library for the component that you select in repository tab has been added to your project. The next step is double click main.c to start coding.


There are four built-in LED on STM32F4 Discovery that connected to PD12 – PD15.


In this tutorial I will use orange LED that connected to PD13. This is the code for LED blinking:
#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"

void Delay(__IO uint32_t nCount)
{
    while (nCount--);
}

int main(void)
{
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

    GPIO_InitTypeDef GPIO_InitDef;
    GPIO_InitDef.GPIO_Pin = GPIO_Pin_13;
    GPIO_InitDef.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitDef.GPIO_OType = GPIO_OType_PP;
    GPIO_InitDef.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_InitDef.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_Init(GPIOD, &GPIO_InitDef);

    while (1)
    {
        GPIO_ToggleBits(GPIOD, GPIO_Pin_13);
        Delay(0xFFFFF);
    }
}
After that you can build this project from menu Project → Build or press F7. If there is no error in your code, then plug your STM32F4 board to your PC and upload the code from menu Flash → Program Download.

STM32F4 board also has a debugger, so you can debug your code from menu Debug or press Ctrl+F5.


2 comments :

  1. thank you.internship is very important for engineering students.codebind technologies provide the free and best internship in chennai.visit-https://internshipinchennai.org.in/internship-in-chennai-for-ece.html

    ReplyDelete