Embedded coder code generation for STM32 devics

29 visualizzazioni (ultimi 30 giorni)
sourav
sourav il 22 Gen 2026 alle 12:58
Risposto: Samhitha il 29 Gen 2026 alle 15:33
I have prepared a SVPWM module in simulink. I want to generate code via embedded coder and use it in keil IDE to generate svpwm in stm32 device. I want to make the code independent from HW. So i do not use any stm32 block.
So this module takes rpm and generates dutycycle counter.
My idea is to integrate generated code in keil ide and run it inside a timer interrupt of stm32 and generate svpwm. Could you please help me the necessary srtting in embedded coder to generate c code which is compatible to build the project in keil IDE for stm32?
  2 Commenti
sourav
sourav il 22 Gen 2026 alle 13:16
Modificato: sourav il 22 Gen 2026 alle 13:28
This is my code generation setting. Please let me know what other setting i need to take care?
build output image
sourav
sourav il 22 Gen 2026 alle 13:17
This is the model for which i want to generate c code.

Accedi per commentare.

Risposte (1)

Samhitha
Samhitha il 29 Gen 2026 alle 15:33
To generate hardware-independent C code from your SVPWM Simulink model and use it safely inside Keil for STM32, configure Embedded Coder to act only as an algorithm generator. Use the ert.tlc system target file, set Hardware Implementation to None, disable any STM32 or hardware support packages, and enable “Generate code only” . In Code Generation → Interface, select Reusable function so you get clean functions. Turn off the example main file and scheduler, use fixed-step discrete solver, and keep SingleTasking mode. Then, copy the generated .c/.h files into Keil, call the generated function once in main(), and another funcion inside a timer interrupt. Use the outputs to update STM32 timer CCR registers to generate SVPWM.
For more details you can look into the following File-Exchange documentation:
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by