Blink LED in Arm Cortex Microcontroller using Keil software
Last Updated :
27 Feb, 2024
The ARM Cortex-M4 is a 32-bit processor core that is widely used in microcontrollers for embedded systems. It is designed to be highly efficient, and low-cost. The Cortex-M4 architecture is based on the ARMv7 instruction set architecture and It's capable of handling up to 4GB of memory address space.
In this tutorial, we will demonstrate how to blink the inbuilt LED of an ARM Cortex M4 microcontroller using the Keil software and the C programming language.
Required Software and Hardware
- Keil (MDK-ARM) - This is the software used for programming in ARM-based Microcontrollers. Make sure to install the STMicrocontroller library inside it.
- ARM Cortex M4 microcontroller (STM32F407xx) - This is the hardware that we will be programming.
About Keil Software
Keil uVision is a software development environment that comes with project management, and a powerful, contemporary editor. It contains various tools required to create embedded applications.
µVision offers the following features, which facilitate the development of embedded applications more quickly:
- A feature-rich editor for source code.
- Device Databases for setting up the tool for development.
- A project manager to help you start and finish your work.
- Integrated capabilities for linking, assembling, and compiling your embedded applications with the Make Utility.
- Dialogs for every setting in the development environment.
- A real combined source-level and assembler-level debugger, along with a fast peripheral simulator and CPU.
- Advanced GDI interface for connecting to a Keil ULINK Debug Adapter and software debugging on target hardware.
- A tool for flash programming that allows you to download applications into Flash ROM.
- Connections to user manuals, device datasheets, online assistance, and manuals.
Programmers may quickly and successfully design embedded applications with the help of the many features offered by the µVision IDE and Debugger, which is the core of the Keil development toolchain. You may accomplish your design objectives quickly and easily with the aid of the user-friendly Keil tools.
µVision has a Debug Mode for debugging applications and a Build Mode for generating new ones. Software can be debugged directly on hardware using tools like ULINK Debug , Trace Adapters, or integrated with the µVision Simulator. Other adapters and external third-party tools are available for developers to employ in order to assess programs.
STM32F407xx MicroController
STMicroElectronics' STM32F407xx family is based on the high-performance 32-bit RISC engine ARM® CortexTM-M4, operating at frequencies up to 168 MHz. The single-precision floating point unit (FPU) in the Cortex-M4 core supports all ARM single-precision data processing instructions and data inputs. It also uses the Memory Protection Unit (MPU) and all DSP commands to secure the application.
The STM32F407xx series includes two APB buses, three AHB buses and a 32-bit multi-AHB bus matrix, as well as a variety of I/O upgrades and peripherals. It also includes high-speed onboard storage (up to 1 MB flash memory, up to 192 KB SRAM), up to 4 KB spare SRAM, and more. The entire hardware includes three 12-bit ADCs, two DACs, one low-power RTC, 12 target 16-bit timers (including two PWM timers for motor control), two target 32-bit timers and a true random number generator (RNG). ). They also have sophisticated and complex communication skills.
Based on the ARMv7 instruction set, this microcontroller is popular in embedded systems due to its cost effectiveness, performance and 32-bit processing capability. The special model STM32F407xx has features suitable for many applications.
Circuit Diagram

Inbuilt Led location for reference:

The Above circuits Diagrams
- At the core of the circuit lies the ARM Cortex-M4 Microcontroller (STM32F407xx). It follows specified orders to run the LED.
- A Type A to Type B Cable is used here. It links the microcontroller to the PC- acting as a bridge for programming and identifying errors. This cable facilitates both data movement and power supply to the microcontroller. One end of the cable plugs into the PC and the other into the microcontroller.
- The built-in LED of the microcontroller is the end product for this project. This LED illuminates when the corresponding GPIO pin is activated to high.
Connection Steps
- Connect PC to the microcontroller using a Type A to Type B USB cable. This connection enables the Keil software to communicate with the microcontroller for various functionality.
- See the inbuilt LED on STM Microcontroller which will glow/blink with the delay according to the program written by the user.
- Program and configure the STM32F407xx microcontroller with the help of Keil Software.
- Flash the code to the microcontroller after compiling the code successfully and doing necessary configuration settings.
- The inbuilt LED on the microcontroller should start blinking according to the program flashed into it. This shows that the setup is good and working correctly.
Steps for Interfacing
1.Open Keil software ->project->New uVisionProject.

2.Check the following options as shown and click on OK.

3.Type stm32f407vgtx in search bar click on OK

4. On the left panel right click on source group and click on add new item as shown.

5. Click on C file and give a name and click on OK.

6.Write the following code in the writing are and save it and also connect the Microcontroller to the pc.
C
#include "stm32f4xx.h"
void delay (int n);
int main(void) {
RCC->AHB1ENR |=8; //enable clock to GPIOD
GPIOD->MODER |=0X55000000; //set pin to output mode
while(1) {
GPIOD->ODR ^=0X0000F000; // turn on all LED's
delay(300);
}
}
void delay(int n){
int i,j;
for(j=0;j<n;j++)
for(i=0;i<3195;i++); //16MHz System Clock
}
7. Now again in left panel right click on Target and select options for Target.

8. Go to Target tab and choose V6.19 in ARM compiler.

9.Now to to Debug tab Use-> ST-Link Debugger. And click on settings.

10.Go to Flash Download -> Check Reset and run. Click on OK in all.

11. Press ctrl + s to save. Build the project and verify. i.e click on first three options one by one after each gets completed without any error. And click on load.

You can see the internal LED Blinking on the microcontroller.
Conclusion
In this tutorial, we have successfully demonstrated how to blink the inbuilt LED of an Arm Cortex M4 microcontroller using the Keil software and the C programming language. By following the step-by-step instructions outlined above, you should now have a working understanding of creating a new project, configuring the target settings, writing and saving C code, and using the ST-Link Debugger for flashing the microcontroller. This project serves as a foundational exercise for those venturing into embedded systems and microcontroller programming.
Similar Reads
How to Create a Project in Keil Microvision Software? A Keil Microvision software is an IDE for executing assembly language programs and embedded c programs you can create a hex file in Keil Microvision software, that's why it is the best software for creating projects that are related to hex files such as LCD Interfacing, Stepper motor interfacing, tr
5 min read
Applications of microcontroller IntroductionMicrocontrollers commonly known as microprocessors or controllers are known to be the control section of embedded systems. These are small shaped electronic devices that are intended to perform Specific control processes within an electrically operated machine or system and facilitate au
13 min read
Time Delay in AVR Microcontroller In this article, we will see how to create delays for the AVR. Also, we will discuss the instruction pipeline. Delay Calculation for AVR : In Assembly Language instructions, to create a time delay one must consider two important factors. The crystal frequency - The frequency of the crystal oscillato
3 min read
Introduction to 8051 Microcontroller 8051 is one of the first and most popular microcontrollers also known as MCS-51. Intel introduced it in the year 1981. Initially, it came out as an N-type metal-oxide-semiconductor (NMOS) based microcontroller, but later versions were based on complementary metal-oxide-semiconductor(CMOS) technology
8 min read
Branch Instructions in AVR Microcontroller In this article, we will be discussing looping in AVR and branch instructions, both Conditional and Unconditional. Looping in AVR : A repeated operation or a set of instructions is known as a loop in programming. It is one of the most fundamental techniques which comes in very handy in writing code.
3 min read
How to Create Eye Blink Animation using Flash? Animations are used for a number of purposes like entertainment, advertisement, business, etc so animators use different types of tools but the most effective and efficient software is Flash. It makes the process of animation effortless and also saves time using functionalities like symbols through
2 min read
8051 MicroController Architecture For many years, the 8051 microcontroller architecture is vital and important component in embedded systems design due to its common use. Its strong architecture and multiple uses in a variety of industries from consumer electronics to industrial automation are the main causes of its appeal.What is 8
6 min read
Microcontrollers - 8051 Interrupts 8051 Microcontroller is a widely used embedded system, that incorporates a robust interrupt system which are important for external communications and real-time applications. Interrupts are the important feature of a microcontroller which enables the microcontroller to respond to the external events
15+ min read
LED Blinking Using Arduino We will interface an LED (light-emitting diode) to the Arduino UNO board. An LED is a simple diode that emits light in a forward bias. We will write an LED-blinking program on the Arduino IDE and download it to the microcontroller board. The program simply turns ON and OFF LED with some delay betwee
7 min read
Microkernel Architecture Pattern - System Design The Microkernel Architecture Pattern is a system design approach where a small, core system the microkernel manages essential functions. It allows for flexibility by letting additional features and services be added as needed. This design makes the system adaptable and easier to maintain because new
10 min read