Is simulink model is independent of microcontrollers?

5 views (last 30 days)
Is it possible to create a Simulink model that is independent of specific microcontrollers?
For example, in the model, the STM32 block is used for CAN transmission. But if I want to deploy the same model to an Arduino, I have to replace the STM32 block with an Arduino-compatible one.
So, is it possible to create a custom block or abstraction that works across multiple microcontrollers like STM32, PIC32, and Arduino without changing the hardware-specific block each time?
  3 Comments

Sign in to comment.

Accepted Answer

Aditya
Aditya on 15 Jul 2025
Hi Jerry ,
It is not possible to create a single, universal Simulink block that works across all microcontrollers (like STM32, PIC32, and Arduino) for hardware-specific features such as CAN transmission, because each hardware platform requires its own support package with unique driver blocks. However, you can achieve a level of portability by using abstraction techniques:
  • Create wrapper subsystems : for each hardware, each containing the appropriate microcontroller-specific block.
  • Use Simulink Variant Subsystems: to switch between hardware-specific implementations based on the target platform.
  • Employ custom S-Functions or MATLAB System blocks: though this requires you to manage hardware drivers and code generation for each platform.
While this approach does not create a truly universal block, it allows you to keep your main model hardware-independent and only change the variant selection when switching targets, greatly reducing the effort required for multi-platform deployment.
I hope this helps.

More Answers (1)

Nithin
Nithin on 28 Jul 2025
One approach that you can try is with variant subsystems as mentioned earlier, which should solve your problem. Refer to the documentation for more details: https://in.mathworks.com/help/simulink/slref/variantsubsystem.html
With this, you can keep the FDCAN blocks for multiple targets within the variant subsystem and implement an expression to control which variant is active based on the target hardware selection in the model config set. With this approach, the model remains the same, however you will have to change the config set based on the desired target.

Community Treasure Hunt

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

Start Hunting!