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.
- Overview
- Features
- Prerequisites
- Hardware Requirements
- Recommended Test Equipment
- Software Requirements
- Getting Started
- Project Structure
- Examples
- Documentation
- Contributing
- License
- Support
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
- 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
- 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
- STM32 NUCLEO-G474RE development board
- USB cable for programming and debugging
- ST-Link programmer (built-in on NUCLEO board)
- FTDI Breakout board.
- STM32CubeIDE (version 1.10 or later)
- STM32CubeMX (typically included with CubeIDE)
- MATLAB R2021b or later with Embedded Coder toolbox
| 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) |
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:
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.
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.
- Premium Option: Saleae Logic (Professional, extremely clean software interface, but expensive).
- Budget Options:
- Decoder Software:
- Saleae Logic Software
- Sigrok PulseView (Open-source logic analysis software)
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.
- Recommended Listings:
- Quartz Components FT232RL USB to TTL Module (Budget-friendly)
- SparkFun FTDI Basic Breakout (3.3V) (Standard development breakout)
- Adafruit FT232H Breakout Module (Premium high-speed FT232H series, much nicer)
- DigiKey USB Serial Adapters/Converters & USB Modules (Alternative interface modules and converters)
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.
| 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 |
git clone https://github.com/Anmol-G-K/NUCLEO-G474RE-PowerElectronics-Guide.git
cd NUCLEO-G474RE-PowerElectronics-Guide- Download from STMicroelectronics official website
- Install following the official documentation
- Ensure ST-Link drivers are installed
- Launch STM32CubeIDE
- Go to
File→Open Projects from File System - Navigate to the
Examples/01_Basic_Led_Blinkfolder - Select the project and click
Finish
- Right-click on the project →
Build Project - Connect the NUCLEO board via USB
- Right-click on the project →
Run As→STM32 C/C++ Application - Verify the LED blinks on the board
For examples using MATLAB Embedded Coder:
- Install MATLAB with Embedded Coder toolbox
- Configure MATLAB to use the ARM GCC compiler
- Navigate to MATLAB examples in the specific folder
- Follow the specific tutorial documentation
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
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.
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.
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.
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.
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.
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.
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.
Contributions are welcome! Whether it's adding new examples, improving documentation, or reporting bugs:
- Fork the repository
- Create a feature branch (
git checkout -b feature/YourFeatureName) - Commit your changes (
git commit -m 'Add your feature') - Push to the branch (
git push origin feature/YourFeatureName) - 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.
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.
- STM32:
- Matlab:
- Issues: Check existing GitHub Issues or create a new one
- Discussions: Use GitHub Discussions for questions and knowledge sharing
- Compilation Errors: Check Debugging Tips
- Hardware Issues: Verify connections and power supply
- STM32CubeIDE Problems: Update to the latest version
- Get Started with Embedded Coder
- Embedded Coder Documentation
- Getting Started with STMicroelectronics STM32 Processor Based Boards
- STMicroelectronics STM32 Documentation
- STM32 G474RE User Manual
- STM32G474xE Datasheet
- STM32 G474RE Reference Manual
- Application note - HRTIM Cookbook
- Description of STM32G4 HAL and low-layer drivers
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
Anmol Govindarajapuram Krishnan
- GitHub: @Anmol-G-K
- Email: cb.en.u4eee23103@cb.students.amrita.edu
- STMicroelectronics for excellent microcontrollers and tools
- The embedded systems and power electronics community
- Contributors and users who provide feedback
For the latest updates and announcements, watch this repository! ⭐
