Select GPIO pin and click on that and select GPIO Output Option

We are going to create a LED Blink Program for stm32f103 microcontroller which comes with stm32 Bluepill  development board which is cheap and handy to use. stm32 led blink program will help you to understand the basics of GPIO’s of STM32 platform and help you to understand some basics of using these GPIO as Output.

Introduction:

LED Blinking is considered the Hello world Program for any embedded development project. If you are using stm32 Cortex M series first time then this article is for you. Any Person who want to start any kind of microcontroller programming and want to understand the programming concept of that programming language will had to create first hello world program and in our case or in embedded development case the LED Blinking program.

This program will help us to understand following concepts required as a foundation of this cortex m series microcontrollers.

  • Help us to understand how to create and build a project using Cubemx software from ST
  • How to use GPIOs of STM32F103 microcontroller?
  • How to program a GPIO as an OUTPUT ?
  • What different Options are available for us by using any PIN as an Output?
  • How to use Delay and how to create a simple infinite loop?

So lets just get started…

another good instructable on this topic could be found here

Creating our project in STM32 CubeMX

  1. First of all Open Cubemx software and after clicking on “new project” select your microcontroller which in our case is stm32f103c8.

    select part number
    select microcontroller from the cube mx part list
  2. Now double click on name of microcontroller from right panel.
  3. After that a new window will open from here change RCC of High Speed Clock or HSC to Crystal/ceramic type

    rcc and sys debug options
    selecting clock and debug sources
  4. and change Debug option from SYS menu to Serial Wire
  5. Now from right panel where the chip is shown click on the pin to which you want to attach LED on, and later want to blink that LED, and click on that pin which in our case is PB9 and select GPIO_output from the menu which will appear in result of clicking.

    selecting PB9 as GPIO output
    Select GPIO pin and click on that and select GPIO Output Option
  6. Now go to project settings and here select your compiler which is MDK4 in our case and type the name of the project and change the location of that project if you want and click OK.

    Select your compiler in our case it is Keil vu4 or MDK4

Thats all. Now You had successfully created your project go to the directory your told cubemx to save project into, and load your project in Keil uV4 or other compiler if you created for some compiler other then keil uVision 4.

Coding in Keil for stm32 LED blink

Now Open the project in Keil uVision 4 and goto Application/User and select main file

Choosing main file from application/user folder

And finally these two lines will do rest of the magic

HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_9); //Toggle LED At GPIOB, pin9
HAL_Delay(1000); //Delay 1 Seconds
stm32 led blink
LED blinking code

 

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.