Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPARK: Simulink & STM32 Power Electronics Application Resource Kit

MCU IDE MATLAB Language License Status

NUCLEO-G474RE-PowerElectronics-Guide


SPARK Banner

A comprehensive guide to getting started with the STM32 NUCLEO-G474RE development board for power electronics applications. This repository provides tutorials, examples, and best practices for developing power electronics projects using STM32CubeIDE and MATLAB Embedded Coder.

📋 Table of Contents

🎯 Overview

This guide is designed for engineers and developers who want to learn how to build power electronics applications on the STM32 NUCLEO-G474RE board. Whether you're working with motor control, DC-DC converters, inverters, or other power electronics applications, you'll find practical examples and comprehensive tutorials.

The NUCLEO-G474RE is particularly suited for power electronics due to its:

  • Advanced PWM capabilities (multiple timers with complementary outputs)
  • High-resolution ADC for sensing and feedback
  • Floating-point math co-processor (FPU)
  • Sufficient computational power for real-time control algorithms

✨ Features

  • STM32CubeIDE Projects: Complete, ready-to-use project templates
  • MATLAB Integration: Selected examples with MATLAB Embedded Coder support
  • Power Electronics Focus: PWM generation, ADC sampling, feedback control, protection mechanisms
  • Step-by-Step Tutorials: Beginner-friendly guides with detailed explanations
  • Real-World Examples: Practical implementations of common power electronics circuits
  • Best Practices: Firmware development guidelines for power electronics applications
  • Documentation: Comprehensive comments and external documentation

📦 Prerequisites

Knowledge

  • Basic understanding of embedded C programming
  • Familiarity with STM32 microcontroller concepts
  • Introductory power electronics knowledge (PWM, ADC, feedback control)
  • (Optional) MATLAB/Simulink experience for MATLAB Embedded Coder examples

Hardware

  • STM32 NUCLEO-G474RE development board
  • USB cable for programming and debugging
  • ST-Link programmer (built-in on NUCLEO board)
  • FTDI Breakout board.

Software

  • STM32CubeIDE (version 1.10 or later)
  • STM32CubeMX (typically included with CubeIDE)
  • MATLAB R2021b or later with Embedded Coder toolbox

🔧 Hardware Requirements

Component Specification
Microcontroller STM32G474RE
Flash Memory 512 KB
RAM 160 KB
Operating Voltage 2.0V - 3.6V
ADC Resolution 12-bit
Timer Channels Multiple advanced timers with complementary outputs
Debug Interface ST-Link V2-1 (on-board)

🛠️ Recommended Test Equipment & Components

To build, test, and debug the examples in this guide (especially the high-frequency switching and closed-loop control projects), the following test equipment, breakout boards, and discrete components are highly recommended:

1. Oscilloscope & Software

An oscilloscope is essential for verifying high-frequency PWM duty cycles, complementary switching, dead-time, and filtering noise.

  • Hardware: Hantek 6022BL USB Oscilloscope (or similar 2-channel oscilloscope).
  • Software: OpenHantek6022 — Open-source software that is highly recommended and offers much better performance and usability than the default Hantek software.

2. Logic Analyzer (Budget Alternative)

If a physical oscilloscope is not available, a USB logic analyzer is a quick and cost-effective fix to capture digital states. While it cannot measure analog signals or voltage noise like an oscilloscope, it is excellent for timing and protocol debugging.

3. USB-to-UART (FTDI) Breakout Boards

To transmit logging data and telemetry from the NUCLEO board to a PC. Ensure your chosen serial adapter supports at least 3 MBaud for high-speed logging. It doesn't strictly need to use an official FTDI chip. For FTDI-based chips, the FT232RL is the most widely available and cost-effective module supporting up to 3 MBaud.

Caution

Before connecting any USB-to-UART breakout board to your active power stage, please review the safety precautions in the FTDI Breakout Board Safety Guidelines to prevent ground loops that could destroy your PC or hardware.

4. Prototyping & Discrete Components

For breadboarding the example hardware setups:

  • Dupont jumper wires (Male-to-Male and Male-to-Female).
  • Tactile push buttons (for controls like start/stop/direction).
  • External LEDs with matching current-limiting resistors (e.g., 220Ω, 330Ω).
  • Pull-up / pull-down resistors (e.g., 4.7kΩ, 10kΩ) for digital state definition.

💻 Software Requirements

Tool Version Purpose
STM32CubeIDE 1.10+ Development environment and debugging
STM32CubeMX Included Pin and peripheral configuration
ARM GCC Compiler Included C/C++ compilation
MATLAB Embedded Coder R2021b+ (Optional) Code generation from Simulink

🚀 Getting Started

Step 1: Clone the Repository

git clone https://github.com/Anmol-G-K/NUCLEO-G474RE-PowerElectronics-Guide.git
cd NUCLEO-G474RE-PowerElectronics-Guide

Step 2: Install STM32CubeIDE

  1. Download from STMicroelectronics official website
  2. Install following the official documentation
  3. Ensure ST-Link drivers are installed

Step 3: Open Your First Project

  1. Launch STM32CubeIDE
  2. Go to FileOpen Projects from File System
  3. Navigate to the Examples/01_Basic_Led_Blink folder
  4. Select the project and click Finish

Step 4: Build and Flash

  1. Right-click on the project → Build Project
  2. Connect the NUCLEO board via USB
  3. Right-click on the project → Run AsSTM32 C/C++ Application
  4. Verify the LED blinks on the board

Step 5: (Optional) MATLAB Setup

For examples using MATLAB Embedded Coder:

  1. Install MATLAB with Embedded Coder toolbox
  2. Configure MATLAB to use the ARM GCC compiler
  3. Navigate to MATLAB examples in the specific folder
  4. Follow the specific tutorial documentation

📁 Project Structure

NUCLEO-G474RE-PowerElectronics-Guide/
│
├── Assets/                              # Project assets (e.g., banner image)
│   └── power_electronics_guide.png
│
├── Examples/                            # Hands-on power electronics examples
│   ├── 01_Basic_Led_Blink/              # Simple GPIO and user LED control (C & Simulink)
│   ├── 02_ADC_Basic/                    # Analog-to-digital conversion & sampling
│   ├── 03_PWM_Generation/               # High-resolution PWM generation & dead-time insertion
│   ├── 04_Timer_Basics/                 # Timer-driven interrupt service routines (ISRs)
│   ├── 05_H_Bridge_Control/             # Bidirectional H-bridge control using complementary PWM
│   ├── 06_Buck_Converter_Closed_Loop/   # Closed-loop Buck converter voltage control
│
├── CONTRIBUTING.md                      # Contribution guidelines
├── Debugging_Tips.md                    # Troubleshooting and debugging tips
├── LICENSE                              # MIT License
└── README.md                            # Main project documentation

📚 Examples

1. Basic LED Blink

Location: Examples/01_Basic_Led_Blink

Get familiar with the development environment by blinking the user LED on the board. This example introduces basic GPIO configuration, pin mapping, and the repository's C/MATLAB workflow.

2. ADC Sampling

Location: Examples/02_ADC_Basic

Read analog values from a potentiometer or sensor using the microcontroller's ADC. It explains sampling, trigger modes, and data resolution, which are essential for feedback loops in power electronics.

3. PWM Generation

Location: Examples/03_PWM_Generation

Configure PWM signals to drive power semiconductors (MOSFETs or IGBTs). This example demonstrates how to set switching frequency, adjust duty cycle, configure complementary channels, and safely insert dead-time.

4. Timer Basics and ISR

Location: Examples/04_Timer_Basics

Implements an event-driven system utilizing timer interrupts and external GPIO interrupts on the NUCLEO board. Demonstrates how to write ISRs to toggle states and cycle through LED blinking speeds dynamically.

5. H-Bridge Motor Control

Location: Examples/05_H_Bridge_Control

Implements a bidirectional H-bridge driver using the High-Resolution Timer (HRTIM) to generate 40 kHz complementary PWM signals with 1 μs dead-time. Features active ADC duty modulation, a soft-stop ramp, and a state machine for direction control.

6. Closed-Loop Buck Converter

Location: Examples/06_Buck_Converter_Closed_Loop

Implements closed-loop voltage control of a synchronous Buck converter. It showcases how to design control algorithms in MATLAB Simulink and use Embedded Coder to automatically generate high-performance C code for real-time control on the STM32G474.

📖 Documentation

Comprehensive documentation guides and templates are available in the repository:

  • Debugging Tips - Troubleshooting and debugging techniques for STM32 and Simulink.
  • Documentation Guide - Guidelines on writing project documentation using LaTeX, drawing tools, and compilation options.

🤝 Contributing

Contributions are welcome! Whether it's adding new examples, improving documentation, or reporting bugs:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/YourFeatureName)
  3. Commit your changes (git commit -m 'Add your feature')
  4. Push to the branch (git push origin feature/YourFeatureName)
  5. Open a Pull Request

Please ensure your contributions:

  • Follow the existing code style and structure
  • Include meaningful comments in the code
  • Add documentation for new examples
  • Test thoroughly on actual hardware

See CONTRIBUTING.md for more details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

This allows for both commercial and personal use with proper attribution.

🆘 Support

Resources

Getting Help

  • Issues: Check existing GitHub Issues or create a new one
  • Discussions: Use GitHub Discussions for questions and knowledge sharing

Troubleshooting

  • Compilation Errors: Check Debugging Tips
  • Hardware Issues: Verify connections and power supply
  • STM32CubeIDE Problems: Update to the latest version

Tutorials

Reference Manuals:


📝 Citation

If you use this guide in your projects or research, please cite:

SPARK: Simulink & STM32 Power Electronics Application Resource Kit (formerly NUCLEO-G474RE-PowerElectronics-Guide)
https://github.com/Anmol-G-K/NUCLEO-G474RE-PowerElectronics-Guide

👨‍💻 Author

Anmol Govindarajapuram Krishnan

🙏 Acknowledgments

  • STMicroelectronics for excellent microcontrollers and tools
  • The embedded systems and power electronics community
  • Contributors and users who provide feedback

Last Updated Activity Repo Size Stars

For the latest updates and announcements, watch this repository! ⭐

About

A guide to power electronics with the STM32 NUCLEO-G474RE, featuring projects using STM32CubeIDE and MATLAB

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors