How to resolve code generation errors when Simulink functions have multiple instances

I am trying to generate code for a Simulink model where multiple model reference blocks refer to a single model. I would like to ask about the error I'm encountering. Below is the error message (some characters have been replaced):
Error:
Model 'model_xxxxxxxx', which is not an Export Function model, may not generate reusable code because it contains scoped Simulink function 'f_rand_yyyyy' which generates reusable code. Ensure that the model 'model_xxxxxxx' is an Export Function model to generate reusable code or Consider setting the model configuration parameter 'Code interface packaging' to 'Nonreusable function' and 'Total number of instances allowed per top model' to 'One'.
Recommended actions:
Consider setting the model configuration parameter 'Code interface packaging' to 'Nonreusable function'.
Consider setting the model configuration parameter 'Total number of instances allowed per top model' to 'One'.
① The referenced model uses a Simulink Function. Can I assume that is the cause of this error?
I referred to the following MATLAB documentation:
https://jp.mathworks.com/help/rtw/ug/code-generation-limitations-for-model-reference.html

 Accepted Answer

Yes, the error is likely caused by the referenced model including a Simulink Function. There are known limitations when using Simulink Functions in models that are referenced multiple times with the intention of generating reusable code.
Currently, it is not possible to achieve multi-instance behavior or function reuse when placing a Function Caller in the child model that calls a Simulink Function defined in the parent model.
However, this can be achieved by placing the Simulink Function within the referenced model itself, and calling it via a Function Caller inside that same model.
While users often intuitively define functions in the parent model, in scenarios like this, placing the function within the referenced model is the appropriate workaround.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Release

R2023b

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!