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.
- 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
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 |
This repository includes modular, well-documented examples illustrating the following functionalities:
- 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
- Digital input reading from GPIO pins for pushbuttons
- Software debouncing techniques
- Interrupt-driven pushbutton detection for responsive control
- Configuration of EXTI lines to trigger on rising edges from pushbuttons or sensors
- EXTI Interrupt Service Routines (ISR) to handle events asynchronously
- Reading and writing digital pins for sensor inputs and actuator outputs
- Using GPIO registers for fast bit manipulation
- Simple LED blinking loops for system status or debugging
- Control via GPIO output pins with delay-based timing
- 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
- H-bridge style direction control via GPIO pins
- Speed control through PWM duty cycle modulation
- Deadband handling and safety stop implementation
- Generate project code using STM32CubeMX: configure clocks, GPIO, ADC, EXTI, TIM4 for PWM.
- Open the generated project in Keil uVision.
- Add source files from this repository into the Keil project.
- Build the project with ARM Compiler.
- Flash the firmware via ST-Link or compatible programmer.
- Connect peripherals: pushbuttons, LEDs, motors, potentiometer as per schematic.
- Run and test functionality as per examples.
- STM32CubeMX - Code generation and peripheral configuration
- Keil MDK-ARM - Compiler and IDE for ARM Cortex-M MCUs
- STM32F4 Reference Manual
- STM32F407 Datasheet
- Application notes from ST for motor control, ADC, EXTI, and timer usage
Happy embedded programming and motor control with STM32F4!