How to generate code for model which uses an export-function reference model?

I am using Matlab R2024a prerelease version to build a stateflow chart that generates function call to call the export-function submodel.
I can generate code for the reference model as well as run simulation of the top model. But generating code for the top model gives this error message:
Model 'MainComponent', which is not an Export Function model, may not generate code because it contains a reference model 'SubComponent' that is set up as a multi-instance Export Function. Consider setting the 'Total number of instances allowed per top model' model configuration parameter from 'SubComponent' to 'One' or ensure that the model 'MainComponent' is an Export Function model.
How can I generate code for the top model?

9 件のコメント

Sebastian Lucaci
Sebastian Lucaci 2024 年 3 月 26 日
This is a very good question that I have seen was also asked by other people in the past (2019). Since Matlab has evolved a lot in the last 5 years, if there is a solution, me and my team would also be interested to find it out.
Thank you in advance!
Fangjun Jiang
Fangjun Jiang 2024 年 3 月 26 日
Are you open to, and did you try one of those two options?
1. Set the 'Total number of instances allowed per top model' model configuration parameter for 'SubComponent' to 'One'
2. Make the model 'MainComponent' an Export Function model
Cornelia Costea
Cornelia Costea 2024 年 3 月 26 日
Thank you for your answer but I have already tried this two options.
  1. Code interface packaging for 'MainComponent' is set as reusable function so I can't set the 'Total number of instances allowed per top model' for 'SubComponent' to 'One'.
  2. The 'MainComponent' is set as Export Function model.
Fangjun Jiang
Fangjun Jiang 2024 年 3 月 26 日
Okay, if you've done 2 then what is the new error message.
Cornelia Costea
Cornelia Costea 2024 年 3 月 26 日
The 'MainComponent' was already set as export function model when I got the error mentioned above.
Fangjun Jiang
Fangjun Jiang 2024 年 3 月 26 日
The error message indicates the contrary. Make sure you've gone through this and confirm there is a "f()" icon at the low left corner of the root level of 'MainComponent'.
Cornelia Costea
Cornelia Costea 2024 年 3 月 26 日
編集済み: Cornelia Costea 2024 年 3 月 26 日
There is a f() icon at the low left corner of 'MainComponent'. If I use system target file ert.tlc I am able to generate code, but I need to use autosar.tlc.
Anamaria Popa
Anamaria Popa 2024 年 3 月 27 日
編集済み: Anamaria Popa 2024 年 3 月 27 日
Hello,
I am using MATLAB 2023a and I also have the same problem when trying to generate code using system target file autosar.tlc:
Is there any solution for this?
Fangjun Jiang
Fangjun Jiang 2024 年 3 月 27 日
Contact the Mathworks tech support with your example model to see if this is a bug, or there are more settings need to be done for autosar.tlc.

サインインしてコメントする。

回答 (1 件)

Akshat Dalal
Akshat Dalal 2024 年 4 月 10 日

0 投票

Hi Cornelia,
I believe the error you're getting is a documented limitation mentioned here - https://in.mathworks.com/help/rtw/ug/code-generation-limitations-for-model-reference.html
It is a limitation specific to code generation for model references. As mentioned, if the model uses exported Stateflow graphical functions, you need to set the 'Total number of instances allowed per top model' parameter to 'one'. But you already mentioned you cannot do that, so you might need to contact MathWorks Technical Support to see if there's any workaround.
It is also mentioned that "If you generate code for an atomic subsystem as a reusable function, inputs or outputs that connect the subsystem to a referenced model might prevent code reuse, as described in Generate Reentrant Code from Subsystems.". I am not sure if it applies to your case, but you might want to have a look at this too.
I hope this helps in figuring out the issue.

カテゴリ

ヘルプ センター および File ExchangeRun Model Advisor Checks についてさらに検索

製品

リリース

R2024a

質問済み:

2024 年 3 月 25 日

回答済み:

2024 年 4 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by