MATLAB: Is it possible to log internal signals in the generated code of a Simulink model that has multiple instances of a model reference

Embedded Coder

I have a Simulink model that has multiple instances of the same model reference. In the generated code, I would like to log certain signals for debugging purposes. These signals are internal to the model references. Is it possible to assign individual Simulink.Signal objects to these internal signals and assign their storage class as "Exported Global"? Or are there other ways to do this?
I would ideally like a global variable which can be define exact signal names such that the code can be shared. I would like not to create outports to carry these signals to the top level as this is cumbersome for large models and multiple signals. I am aware of the option to set "DefaultParameterBehavior" to "Tunable" and set "OptimizeBlockIOStorage" to "off". However I would not like to do that, as not all signals with names are to be logged in the generated code.

Best Answer

The workflow is possible in 17b by using one of the following ways:
1. Setting the storage class of the signal to SimulinkGlobal. With this approach, the signal is preserved and its name is not mangled. Please note that in R2018a, SimulinkGlobal was renamed to "Model default".  If the model’s default storage class for internal data is "Default" then the behavior is the same as described above.  If the model’s default storage class is a single-instance-only storage class (like ExportedGlobal) then this will error out.
2. You may enable signal logging by checking the following option on the Model Configuration Parameters: Code Generation > Interface (Advanced Parameters) > MAT-file logging
3. You may enable Testpoint for the signal. Please uncheck the option "Ignore testpoints" setting in ConfigSet or the signal may be optimized away from generated code. With this option, the signal is preserved but name may be mangled.