MATLAB Answers


HDL Code generation - exclusion of code

Asked by David Amor on 22 Oct 2013
Latest activity Commented on by Tim McBrayer on 23 Oct 2013
Is there a way to exclude "Embedded Matlab blocks" in Simulink from code generation
Illegal "Embedded Matlab" code generation for cell array reference:
How do I exclude code from code generation similar to
Many thanks, Dave


Sign in to comment.

1 Answer

Answer by Tim McBrayer on 22 Oct 2013
Edited by Tim McBrayer on 23 Oct 2013
 Accepted Answer

There is not a direct way to have a MATLAB Function block participate in Simulink simulation while not generating any HDL code for it. There are a couple of indirect ways, however.
One way is to reorganize your design so that the MATLAB Function block is not inside the subsystem you are generating HDL code for. This will have the side effect of changing the I/O interface to your generated code. This is probably the best approach; if you do not want code generated for a particular block, then that block should probably not be part of the design you generate code for.
A second way is to wrap the MATLAB Function block inside an additional subsystem. This subsystem can be marked as having a Black Box implementation. What this means is that no HDL code will be generated for the subsystem or its contents. HDL Coder will generate a module instance with the interface of the subsystem, but no code for the contents. This is intended to allow the user to insert their own handwritten HDL code into a design.
There is no way to pick and choose what MATLAB code in a function block gets HDL code generated for it.


Many thanks for your reply Tim.
I didn't hold much hope :)
To clarify my posting, the Matlab function block is NOT inside the subsystem I am generating HDL code for.
I have two Matlab blocks in my model, the design block that models the HDL/FPGA (and as such the code is restricted to EML that can be passed through the code generator) and a block for stimulus - and a scope observing it all. so obviously the stimulus block does not need to be passed through the code generator, this is as sensible as trying to generate code for the scope...
When I run the simulation - the code within the stimulus block is put under the same scrutiny as the design under test.
The scope, pulse generator and other "un-generatable" items are ignored. I was hoping there was a way of forcing Matlab/Simulink to ignore "user-defined function" blocks.
Many thanks for your help.
It sounds like you are generating code for the entire model. if this is the case, a better approach would be to place all blocks that you want to generate code for into a subsystem, and leave all the rest of the model outside. In particular, the non-generatable MATLAB Function block will reside outside the subsystem, along with your scopes etc.
Assume you have model 'mymodel', Fcn block 'Stimulus', Fcn block 'Design', and scope 'Scope'. All the blocks reside at the top level of your model:
>> find_system('mymodel')
ans =
Select all the blocks that you want to generate HDL code for (in this case, 'mymodel/Design'), and type Ctrl-g to place them in a subsystem:
>> find_system('mymodel')
ans =
Note that 'Design' is now inside 'Subsystem'. Now you can generate HDL code for 'Subsystem' alone; 'Stimulus' won't even be analyzed by HDL Coder. You can generate code via the command line 'makehdl' command, via the Simulink Code menu (make sure that you set the HDL Configuration parameters to generate code for 'mymodel/Subsystem'), the context menu of mymodel/Subsystem, or the HDL Workflow Advisor.

Sign in to comment.