Code Generation for Model that References an Export Function Model

4 次查看(过去 30 天)
I am having an issue using Embedded Coder to generate code for a model that itself has a reference to an export function model. I am able to open the referenced model independently and build code for it. Here's the setup:
Both models store their configurations in .mat files so they can be loaded into the base workspace, and the models themselves use Configuration References to the base workspace.
Export Model: A Simulink model for control and monitor of an LTC6804 chip. SPI data is fed into it and output from it without actually making direct hardware calls; that is left to the parent model to implement. A project file is set up that runs the .mat configuration file on startup so the configuration exists in the base workspace.
  • "Hardware board" for this is set to "None" so it compiles generic code that can be ported to any target.
  • "Code interface packaging" is set to "Reusable function" since more than one could be on any given target
  • "Total number of instances allowed per top model" is "Multiple" for the same reason.
Parent Model: A Simulink model for monitor and control for a custom target. It also uses a project file. The folders where the model above is stored are added to the project path, but the referenced model's project is NOT a referenced project by the parent project. Rather, the parent model's project file manually loads both the referenced .mat configuration as well as its own, then modifies the referenced configuration to use the same "Hardware board" as the parent model. This allows the parent to implement the referenced export function for code generation without violating the Configuration Parameter requirements laid out in this article: Set Configuration Parameters for Code Generation of Model Hierarchies.
  • "Hardware board" is the custom board we have generated for the custom hardware we are making
  • "Code interface packaging" is set to "Nonreusable function" because one instance will run on the microcontroller
  • "Total number of instances allowed per top model" is "One" for the same reason.
Even though I can Update the model, effectively building it for simulation, I get an error when I attempt to generate code. The error is as follows:
So it seems like the recommended actions are to change the parent model's settings to...what they already are. I have even tried changing the child model's "Code interface packaging" to "Nonreusable function", and it did not change this error in any way. I have spent days trying to figure this one out, and I'm fully at a loss. If anyone has any idea what I might be doing wrong, I'd love to get this resolved.
  2 个评论
Zama Alex
Zama Alex 2024-2-6
I have exactly the same problem when try to generate C code from a multi-instance model that contain reference models. Did you solve the problem?
Thank you in advance.
Dana Schwanke
Dana Schwanke 2024-2-6
Yes and no. The TL;DR is that you cannot reference an export function model (EFM) from a non-EFM. You can reference as many EFMs from within other EFMs as you want, and you can even reference non-EFMs from EFMs, but not the other way around. This is all per internal MathWorks documentation that they shared with us on an internal call but have not publicly displayed on their website.
Essentially, EFMs are supposed to be a way of building modular code that is meant to then be integrated with an external code base. MathWorks DOES recommend that, for a given project, any EFMs you intend to reference are all built under an umbrella top-level EFM rather than building all the individual EFMs separately so that common header files are not recreated and so that Simulink Coder can obfuscate any symbols which share names to avoid code naming collisions.

请先登录,再进行评论。

回答(1 个)

Debadipto
Debadipto 2023-8-11
Hello @Dana,
I understand that you are encountering an issue with Embedded Coder when generating code for a model that has a reference to an export function model. Despite having the correct settings in both the parent and referenced models, you are still getting an error during code generation.
Given the complexity of your setup and the efforts you have already made, it would be beneficial to reach out to MathWorks Technical Support for further assistance. Contacting MathWorks Technical Support will ensure that you receive the most accurate and up-to-date guidance to resolve this issue effectively.

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by