Is simulink model is independent of microcontrollers?

조회 수: 4 (최근 30일)
Jerry
Jerry 2025년 7월 10일
이동: Walter Roberson 2025년 7월 28일
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
Jerry
Jerry 2025년 7월 21일
이동: Walter Roberson 2025년 7월 28일
Jerry
Jerry 2025년 7월 21일
이동: Walter Roberson 2025년 7월 28일

댓글을 달려면 로그인하십시오.

채택된 답변

Aditya
Aditya 2025년 7월 15일
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.

추가 답변 (1개)

Nithin
Nithin 2025년 7월 28일
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!

Translated by