Skip to content

STM32F4 example projects demonstrating ADC, timer-based ADC, push button handling (polling and interrupt), digital read, external interrupts, LED blinking, PWM, and DC motor control.

License

Notifications You must be signed in to change notification settings

sahilrajpurkar03/STM32F4-Codes

Repository files navigation

STM32F407 Embedded Control Projects

A comprehensive set of STM32F407-based embedded projects showcasing essential peripherals and control techniques including ADC sampling, pushbutton handling with interrupts, digital input reading, LED blinking, PWM signal generation, and bidirectional DC motor control. Developed using STM32CubeMX for hardware configuration and Keil uVision for firmware development.


Development Environment

  • IDE: Keil uVision (latest recommended version)
  • Hardware Abstraction: STM32CubeMX for peripheral initialization and pin configuration
  • Microcontroller: STM32F407VGT6 (ARM Cortex-M4, 168 MHz)
  • Compiler: ARM Compiler (packaged with Keil)
  • Debugger: ST-Link V2 or compatible
  • Clock Setup: Internal and external oscillator with PLL configured for 168 MHz system clock

Supported Hardware & Components

Component Description Reference / Datasheet
STM32F407VGT6 MCU High-performance ARM Cortex-M4 MCU STM32F407 Datasheet
Pushbutton Switch Tactile switch with external interrupt support User-supplied hardware
LEDs (on-board) User LEDs connected to GPIOD pins (e.g., PD12) STM32F4 Discovery or custom board
DC Motor Brushed DC motor Controlled via PWM and direction pins
Rotary Encoder Incremental Rotary Encoder Rotary Encoder

Project Overview

This repository includes modular, well-documented examples illustrating the following functionalities:

ADC Sampling and Conversion

  • Configured ADC1 to sample analog inputs (e.g., potentiometer)
  • Conversion of raw 12-bit ADC data to useful control values (e.g., PWM duty cycle)
  • Blocking and polling-based ADC read example

    📂 Code

Pushbutton Input Handling

  • Digital input reading from GPIO pins for pushbuttons
  • Software debouncing techniques
  • Interrupt-driven pushbutton detection for responsive control

    📂 Code

External Interrupt Configuration

  • Configuration of EXTI lines to trigger on rising edges from pushbuttons or sensors
  • EXTI Interrupt Service Routines (ISR) to handle events asynchronously

    📂 Code

Digital Input/Output Control

  • Reading and writing digital pins for sensor inputs and actuator outputs
  • Using GPIO registers for fast bit manipulation

    📂 Code

LED Blinking and Status Indication

  • Simple LED blinking loops for system status or debugging
  • Control via GPIO output pins with delay-based timing

    📂 Code

PWM Generation using TIM4

  • Initialization of Timer 4 for PWM mode on output compare channels
  • Configuring GPIO pins to alternate function for PWM output
  • Controlling duty cycle dynamically to adjust motor speed

    📂 Code

Bidirectional DC Motor Control

  • H-bridge style direction control via GPIO pins
  • Speed control through PWM duty cycle modulation
  • Deadband handling and safety stop implementation

    📂 Code


How to Build & Deploy

  1. Generate project code using STM32CubeMX: configure clocks, GPIO, ADC, EXTI, TIM4 for PWM.
  2. Open the generated project in Keil uVision.
  3. Add source files from this repository into the Keil project.
  4. Build the project with ARM Compiler.
  5. Flash the firmware via ST-Link or compatible programmer.
  6. Connect peripherals: pushbuttons, LEDs, motors, potentiometer as per schematic.
  7. Run and test functionality as per examples.

References and Tools


Happy embedded programming and motor control with STM32F4!

About

STM32F4 example projects demonstrating ADC, timer-based ADC, push button handling (polling and interrupt), digital read, external interrupts, LED blinking, PWM, and DC motor control.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published