coder.EmbeddedCodeConfig class

Package: coder
Superclasses: coder.CodeConfig

codegen configuration object that specifies code generation parameters for code generation with an Embedded Coder license

Description

A coder.EmbeddedCodeConfig object contains the configuration parameters that the codegen function requires to generate standalone C/C++ libraries and executables for an embedded target. Use the -config option to pass this object to the codegen function.

Construction

cfg = coder.config('lib') creates a code generation configuration object for C/C++ static library generation. If the Embedded Coder® product is installed, it creates a coder.EmbeddedCodeConfig object. Otherwise, it creates a coder.CodeConfig object.

cfg = coder.config('dll') creates a code generation configuration object for C/C++ dynamic library generation. If the Embedded Coder product is installed, it creates a coder.EmbeddedCodeConfig object. Otherwise, it creates a coder.CodeConfig object.

cfg = coder.config('exe') creates a code generation configuration object for C/C++ executable generation. If the Embedded Coder product is installed, it creates a coder.EmbeddedCodeConfig object. Otherwise, it creates a coder.CodeConfig object.

cfg = coder.config(output_type, 'ecoder', false) creates a coder.CodeConfig object for the specified output type even if the Embedded Coder product is installed.

cfg = coder.config(output_type, 'ecoder', true) creates a coder.EmbeddedCodeConfig object for the specified output type even if the Embedded Coder product is not installed. However, you cannot generate code using a coder.EmbeddedCodeConfig object unless an Embedded Coder license is available.

Properties

BuildConfiguration

Specify build configuration. 'Faster Builds', 'Faster Runs', 'Debug', 'Specify'.

Default: 'Faster Builds'

CastingMode

Specify data type casting level for variables in the generated C/C++ code.

ValueDescription
'Nominal'

Generate C/C++ code that uses default C compiler data type casting. For example:

short addone(short x)
{
  int i0;
  i0 = x + 1;
  if (i0 > 32767) {
    i0 = 32767;
  }

  return (short)i0;
}

'Standards'

Generate C/C++ code that casts data types to conform to MISRA® standards. For example:

short addone(short x)
{
  int i0;
  i0 = (int)x + (int)1;
  if (i0 > (int)32767) {
    i0 = (int)32767;
  }

  return (short)i0;
}

'Explicit'

Generate C/C++ code that casts data type values explicitly. For example:

short addone(short x)
{
  int i0;
  i0 = (int)x + 1;
  if (i0 > 32767) {
    i0 = 32767;
  }

  return (short)i0;
}

Default: 'Nominal'

CodeExecutionProfiling

Enable execution-time profiling during a software-in-the-loop (SIL) or processor-in-the-loop (PIL) execution.

Default: false

CodeTemplate

Specify a code generation template for file and function banners in the generated code. This parameter is a handle to a coder.MATLABCodeTemplate object constructed from a code generation template (CGT) file.

This parameter is empty by default. If you do not set this parameter to a coder.MATLABCodeTemplate object, the code generator produces default banners.

CodeReplacementLibrary

Specify a code replacement library for the generated code.

ValueDescription
'None'

Does not use a code replacement library.

'GNU C99 extensions'

Generates calls to the GNU® gcc math library, which provides C99 extensions as defined by compiler option -std=gnu99.

'Intel IPP for x86-64 (Windows)'

Generates calls to the Intel® Performance Primitives (IPP) library for the x86-64 Windows® platform.

'Intel IPP/SSE for x86-64 (Windows)'

Generates calls to the IPP and Streaming SIMD Extensions (SSE) libraries for the x86-64 Windows platform.

'Intel IPP for x86-64 (Windows using MinGW compiler)'

Generates calls to the IPP library for the x86-64 Windows platform and MinGW compiler.

'Intel IPP/SSE for x86-64 (Windows using MinGW compiler)'

Generates calls to the IPP and SSE libraries for the x86-64 Windows platform and MinGW compiler.

'Intel IPP for x86/Pentium (Windows)'

Generates calls to the IPP library for the x86/Pentium Windows platform.

'Intel IPP/SSE x86/Pentium (Windows)'

Generates calls to the IPP and SSE libraries for the x86/Pentium Windows platform.

'Intel IPP for x86-64 (Linux)'

Generates calls to the IPP library for the x86-64 Linux® platform.

'Intel IPP/SSE with GNU99 extensions for x86-64 (Linux)'

Generates calls to the GNU libraries for IPP and SSE, with GNU C99 extensions, for the x86-64 Linux platform.

Compatible libraries depend on these parameters:

  • TargetLang

  • TargetLangStandard

  • ProdHWDeviceType in the hardware implementation configuration object.

Embedded Coder offers more libraries and the ability to create and use custom code replacement libraries.

MATLAB® Coder™ generates the minimal set of #include statements for header files required by the selected code replacement library.

Before setting this parameter, verify that your compiler supports the library that you want to use. If you select a parameter value that your compiler does not support, compiler errors can occur.

    Note:   MATLAB Coder software does not support TLC callbacks.

Default: 'None'

CommentStyle

Specify comment style in the generated C or C++ code.

ValueDescription
'Auto'For C, generate multiline comments. For C++, generate single-line comments.
'Single-line'Generate single-line comments preceded by //.
'Multi-line'Generate single or multiline comments delimited by /* and */.

For C code generation, specify the single-line comment style only if your compiler supports it.

Dependency: GenerateComments enables this parameter.

Default: 'Auto'

CompileTimeRecursionLimit

For compile-time recursion, control the number of copies of a function that are allowed in the generated code. To disallow recursion in the MATLAB code, set CompileTimeRecursionLimit to 0. The default compile-time recursion limit is high enough for most recursive functions that require this type of recursion. If code generation fails because of the compile-time recursion limit, and you want compile-time recursion, try to increase the limit. Alternatively, change your MATLAB code so that the code generator uses run-time recursion. See Compile-Time Recursion Limit Reached.

Default: integer, 50

ConvertIfToSwitch

Select whether to convert if-elseif-else patterns to switch-case statements. This optimization works only for integer and enumerated type inputs.

Default: false

ConstantFoldingTimeout

Specify the maximum number of instructions that the constant folder executes before stopping. In some situations, code generation requires specific instructions to be constant. If code generation is failing, increase this value.

Default: 10000

CustomHeaderCode

Specify code to appear near the top of each C/C++ header file generated from your MATLAB algorithm code. Specify code as a character vector.

Default: ''

CustomInclude

Specify a space-separated list of include folders to add to the include path when compiling the generated code. Specify list of include folders as a character vector.

If your list includes Windows paths that contain spaces, enclose each instance in double quotes, for example:

'C:\Project "C:\Custom Files"'

Default: ''

CustomInitializer

Specify code to appear in the initialize function of the generated .c or .cpp file. Specify code as a character vector.

Default: ''

CustomLAPACKCallback

Specify the name of a LAPACK callback class that derives from coder.LAPACKCallback. Specify name as a character vector. If you specify a LAPACK callback class, for certain linear algebra functions, the code generator produces LAPACK calls by using the LAPACKE C interface to your LAPACK library. The callback class provides the name of your LAPACKE header file and the information required to link to your LAPACK library. If this parameter is empty, the code generator produces code for linear algebra functions instead of a LAPACK call.

Default: ''

CustomLibrary

Specify a space-separated list of static library files to link with the generated code. Specify list as a character vector.

Default: ''

CustomSource

Specify a space-separated list of source files to compile and link with the generated code. Specify list of source files as a character vector.

Default: ''

CustomSourceCode

Specify code to appear near the top of the generated .c or .cpp file, outside of a function. Specify list as a character vector.

Default: ''

CustomSymbolStrEMXArray

Customize generated identifiers for EMX Array types (Embeddable mxArray types). See Settings.

Default: 'emxArray_$M$N'

CustomSymbolStrEMXArrayFcn

Customize generated identifiers for EMX Array (Embeddable mxArrays) utility functions. See Settings.

Default: 'emx$M$N'

CustomSymbolStrFcn

Customize generated local function identifiers. See Settings.

Default: 'm_$M$N'

CustomSymbolStrField

Customize generated field names in global type identifiers. See Settings.

Default: '$M$N'

CustomSymbolStrGlobalVar

Customize generated global variable identifiers. See Settings.

Default: '$M$N'

CustomSymbolStrMacro

Customize generated constant macro identifiers. See Settings.

Default: '$M$N'

CustomSymbolStrTmpVar

Customize generated local temporary variable identifiers. See Settings.

Default: '$M$N'

CustomSymbolStrType

Customize generated global type identifiers. See Settings.

Default: '$M$N'

CustomTerminator

Specify code to appear in the terminate function of the generated .c or .cpp file. Specify code as a character vector.

Default: ''

CustomToolchainOptions

Specify custom settings for each tool in the selected toolchain, as a cell array.

Dependencies:

  • Toolchain determines which tools and options appear in the cell.

  • Setting BuildConfiguration to Specify enables the options specified by CustomToolchainOptions.

Start by getting the current options and values. For example:

rtwdemo_sil_topmodel;
set_param(gcs, 'BuildConfiguration', 'Specify')
opt = get_param(gcs, 'CustomToolchainOptions')

Then edit the values in opt.

These values derive from the toolchain definition file and the third-party compiler options. See Custom Toolchain Registration.

Default: cell array

DataTypeReplacement

Specify whether to use built-in C data types or predefined types from rtwtypes.h in generated code.

Set to 'CoderTypeDefs' to use the data types from rtwtypes.h. Otherwise, to use built-in C data types, retain default value or set to 'CBuiltIn'.

Default: 'CBuiltIn'

Description

Description of the coder.EmbeddedCodeConfig object, specified as a character vector.

Default: 'class EmbeddedCodeConfig: C code generation Ecoder configuration objects'

DynamicMemoryAllocation

Control use of dynamic memory allocation for variable-size data.

By default, dynamic memory allocation is enabled for variable-size arrays whose size (in bytes) is greater than or equal to DynamicMemoryAllocationThreshold. codegen allocates memory for this variable-size data dynamically on the heap.

Set this property to 'Off' to allocate memory statically on the stack. Set it to 'AllVariableSizeArrays' to allocate memory for all variable-size arrays dynamically on the heap. You must use dynamic memory allocation for unbounded, variable-size data.

Dependencies:

  • EnableVariableSizing enables this parameter.

  • Setting this parameter to 'Threshold' enables the DynamicMemoryAllocationThreshold parameter.

Default: 'Threshold'

DynamicMemoryAllocationThreshold

Specify the size threshold in bytes.codegen allocates memory on the heap for variable-size arrays whose size is greater than or equal to this threshold.

Dependency:

  • Setting DynamicMemoryAllocation to 'Threshold' enables this parameter.

Default: 65536

EnableAutoExtrinsicCalls

Specify whether MATLAB Coder must treat common visualization functions as extrinsic functions. When this option is enabled, MATLAB Coder detects calls to many common visualization functions, such as plot, disp, and figure. For MEX code generation, MATLAB Coder calls out to MATLAB for these functions. For standalone code generation, MATLAB Coder does not generate code for these visualization functions. This capability reduces the amount of time that you spend making your code suitable for code generation. It also removes the requirement to declare these functions extrinsic using the coder.extrinsic function.

Default: true

EnableMemcpy

Enable the memcpy optimization. To optimize code that copies consecutive array elements, the memcpy optimization replaces the code with a memcpy call. A memcpy call can be more efficient than code, such as a for-loop or multiple, consecutive element assignments. The code generator invokes the memcpy optimization when the following conditions are true:

  • EnableMemcpy is true.

  • The number of bytes to copy is greater than or equal to MemcpyThreshold. The number of bytes to copy is the number of array elements multiplied by the number of bytes required for the C/C++ data type.

See memcpy Optimization.

Default: true

EnableOpenMP

If possible, enable OpenMP. Using the OpenMP library, the C/C++ code that MATLAB Coder generates for parfor-loops can run on multiple threads. With OpenMP disabled, MATLAB Coder treats parfor-loops as for-loops and generates C/C++ code that runs on a single thread.

Default: true

EnableRuntimeRecursion

Allow recursive functions in generated code. If your MATLAB code requires run-time recursion and this parameter is false, code generation fails.

Some coding standards, such as MISRA, do not allow recursion. To increase the likelihood of generating code that is compliant with MISRA C®, set EnableRuntimeRecursion to false.

Default: true

EnableSignedLeftShifts

Specify whether to replace multiplications by powers of two with signed left bitwise shifts in the generated C/C++ code. Some coding standards, such as MISRA, do not allow bitwise operations on signed integers. To increase the likelihood of generating MISRA C compliant code, set this option to false.

When this option is true, MATLAB Coder uses signed left shifts for multiplication by powers of two. Here is an example of generated C code that uses signed left shift for multiplication by eight:

i <<= 3;

When this option is false, MATLAB Coder does not use signed left shifts for multiplication by powers of two. Here is an example of generated C code that does not use signed left shift for multiplication by eight:

i = i * 8;

Default: true

EnableSignedRightShifts

Specify whether to allow signed right bitwise shifts in the generated C/C++ code. Some coding standards, such as MISRA, do not allow bitwise operations on signed integers. To increase the likelihood of generating MISRA-C:2004 compliant code, set this option to false.

When this option is true, MATLAB Coder uses signed right shifts. Here is an example of generated C code that uses a signed right shift:

i >>= 3

When this option is false, MATLAB Coder replaces right shifts on signed integers with a function call in the generated code.

i = asr_s32(i, 3U);

Default: true

EnableStrengthReduction

Enable optimization that simplifies array indexing in loops in the generated code. When possible, for array indices in loops, this optimization replaces multiply operations with add operations. Multiply operations can be expensive. This optimization is useful when the C/C++ compiler on the target platform does not optimize the array indexing. Even when the optimization replaces the multiply operations in the generated code, it is possible that the C/C++ compiler can generate multiply instructions.

Default: false

EnableVariableSizing

Enable support for variable-size arrays.

Dependency:

  • This parameter enables the parameter DynamicMemoryAllocation.

Default: true

FilePartitionMethod

Specify whether to generate one C/C++ file for each MATLAB language file ('MapMFileToCFile') or generate all C/C++ functions into a single file ('SingleFile').

Default: 'MapMFileToCFile'

GenerateCodeMetricsReport

Generate a static code metrics report including generated file information, number of lines, and memory usage.

Default: false

GenCodeOnly

Specify code generation versus an executable or library build.

Default: false

GenerateCodeReplacementReport

Generate a code replacements report that summarizes the replacements used from the selected code replacement library. The report provides a mapping between each code replacement instance and the line of MATLAB code that triggered the replacement.

Default: false

GenerateComments

Place comments in the generated files.

Dependencies:

  • Enables CommentStyle.

  • Enables MATLABFcnDesc.

  • Enables MATLABSourceComments.

Default: true

GenerateExampleMain

Specify whether to generate an example C/C++ main function. If example main generation is enabled, MATLAB Coder generates source and header files for the main function in the examples subfolder of the build folder. For C code generation, it generates the files main.c and main.h. For C++ code generation, it generates the files main.cpp and main.h.

The example main function declares and initializes data. It calls entry-point functions but does not use values returned from the entry-point functions.

Before you use the example main files, copy them to another location and modify them to meet the requirements of your application.

ValueDescription
'DoNotGenerate'

Does not generate an example C/C++ main function.

'GenerateCodeOnly'

Generates an example C/C++ main function but does not compile it.

'GenerateCodeAndCompile'

Generates an example C/C++ main function and compiles it to create a test executable. This executable does not return output.

If the GenCodeOnly parameter is true, MATLAB Coder does not compile the C/C++ main function.

Default: 'GenerateCodeOnly'

GenerateMakefile

Specify whether to generate a makefile during the build process.

Default: true

GenerateReport

Default: false

Hardware

Handle to coder.Hardware object that specifies the hardware board for processor-in-the-loop (PIL) execution. Use coder.hardware to create the coder.Hardware object. For example:

cfg = coder.config('lib','ecoder',true);
hw = coder.hardware('BeagleBone Black');
cfg.Hardware = hw;

Dependencies:

  • Setting Hardware sets HardwareImplementation to a coder.HardwareImplementation object customized for the hardware specified by Hardware.

HardwareImplementation

Handle to coder.HardwareImplementation object that specifies hardware-specific configuration parameters for C/C++ code generation.

If you set the Hardware property, HardwareImplementation is set to a coder.HardwareImplementation object customized for the hardware that is specified by Hardware. If you do not set the Hardware property, HardwareImplementation defaults to a coder.HardwareImplementation object with properties that are set for the MATLAB host computer.

Dependency:

Setting Hardware sets HardwareImplementation to a coder.HardwareImplementation object customized for the hardware that is specified by Hardware.

HighlightPotentialDataTypeIssues

Highlight potential data type issues in the code generation report. If this option is enabled, the code generation report highlights MATLAB code that results in single-precision or double-precision operations in the generated C/C++ code. If you have a Fixed-Point Designer™ license, the report also highlights expressions in the MATLAB code that result in expensive fixed-point operations in the generated code.

Default: false

IncludeTerminateFcn

Generate a terminate function.

If you set this property to false but a terminate function is required, for example, to free memory, MATLAB Coder issues a warning.

Default: true

IndentSize

Specify the number of characters per indentation level. Specify an integer from 2 to 8.

Default: 2

IndentStyle

Specify the style for the placement of braces in the generated C/C++ code.

ValueDescription
'K&R'

For blocks within a function, an opening brace is on the same line as its control statement. For example:

void addone(const double x[6], double z[6])
{
  int i0;
  for (i0 = 0; i0 < 6; i0++) {
    z[i0] = x[i0] + 1.0;
  }
}

'Allman'

For blocks within a function, an opening brace is on its own line at the same indentation level as its control statement. For example:

void addone(const double x[6], double z[6])
{
  int i0;
  for (i0 = 0; i0 < 6; i0++)
  {
    z[i0] = x[i0] + 1.0;
  }
}

Default: 'K&R'

InitFltsAndDblsToZero

Enable the memset optimization for assignment of float or double 0 to consecutive array elements. To optimize code that assigns a constant value to consecutive array elements, the memset optimization replaces the code with a memset call. A memset call can be more efficient than code, such as a for-loop or multiple, consecutive element assignments. To assign float or double 0 to consecutive array elements, the code generator invokes the memset optimization when the following conditions are true:

  • InitFltsAndDblsToZero is true.

  • The number of bytes to assign is greater than or equal to MemcpyThreshold. The number of bytes to assign is the number of array elements multiplied by the number of bytes required for the C/C++ data type.

See memset Optimization.

Default: true

InlineStackLimit

Specify the stack size limit on inlined functions. This specification determines the amount of stack space allocated for local variables of the inlined function.

Specifying a limit on the stack space constrains the amount of inlining allowed. For out-of-line functions, stack space for variables local to the function is released when the function returns. However, for inlined functions, stack space remains occupied by the local variables even when the function returns.

This feature is especially important for embedded processors, where stack size can be limited.

Default: 4000

InlineThreshold

Specify function size for inline threshold. Unless there are conflicts with other inlining conditions, MATLAB Coder inlines functions that are smaller than this size.

The function size is measured in terms of an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. You must experiment with this parameter to obtain the inlining behavior that you want. For instance, if the default setting for this parameter is leading to large functions being inlined, you can tune the parameter in steps until you are satisfied with the inlining behavior.

Default: 10

InlineThresholdMax

Specify the maximum size of functions after inlining. If the size of the calling function after inlining exceeds InlineThresholdMax, MATLAB Coder does not inline the called function.

The function size is measured in terms of an abstract number of instructions, not actual MATLAB instructions or instructions in the target processor. You must experiment with this parameter to obtain the inlining behavior that you want. For instance, if the default setting for this parameter is leading to the inlining of large functions, you can tune the parameter in steps until you are satisfied with the inlining behavior.

Default: 200

LaunchReport

Specify whether to display a report after code generation is complete or an error occurs.

Default: true

MATLABFcnDesc

Include MATLAB function help text in a function banner in generated code. If not selected, MATLAB Coder treats the help text as a user comment.

Dependencies:

  • GenerateComments enables this parameter.

Default: true

MATLABSourceComments

Include MATLAB source code as comments in the generated code.

Dependencies:

  • GenerateComments enables this parameter.

Default: false

MaxIdLength

Specify maximum number of characters in generated function, type definition, and variable names. To avoid truncation of identifiers by the target C compiler, specify a value that matches the maximum identifier length of the target C compiler.

This parameter does not apply to exported identifiers, such as the generated names for entry-point functions or emxArray API functions. If the length of an exported identifier exceeds the maximum identifier length of the target C compiler, the target C compiler truncates the exported identifier.

Minimum is 31. Maximum is 256.

Default: 31

MemcpyThreshold

Specify the minimum number of bytes for the code generator to invoke the memcpy optimization or the memset optimization. To optimize generated code that copies consecutive array elements, the code generator tries to replace the code with a memcpy call. To optimize generated code that assigns a literal constant to consecutive array elements, the code generator tries to replace the code with a memset call. A memcpy or memset call can be more efficient than code, such as a for-loop or multiple, consecutive element assignments.

The number of bytes is the number of array elements to copy or assign multiplied by the number of bytes required for the C/C++ data type.

See memcpy Optimization and memset Optimization.

Default: 64

MultiInstanceCode

Generate reusable, multi-instance code that is reentrant.

Default: false

Name

Name of the configuration object.

Default: character vector, 'EmbeddedCodeConfig'

OutputType

Specify whether to generate a standalone C/C++ static library, dynamic library, or executable. Set to 'LIB' to generate a static library, 'DLL' to generate a dynamic library or 'EXE' to generate an executable.

Default: 'LIB'

ParenthesesLevel

Specify the parenthesization level in the generated C/C++ code.

ValueDescription
'Minimum'

Inserts parentheses where required by ANSI® C or C++, or to override default precedence. For example:

Out = In2 - In1 > 1.0 && In2 > 2.0;

If you generate C/C++ code using the minimum level, for certain settings in some compilers, you can receive compiler warnings. To eliminate these warnings, try the nominal level.

'Nominal'

Inserts parentheses to balance readability and visual complexity. For example:

Out = ((In2 - In1 > 1.0) && (In2 > 2.0));

'Maximum'

Includes parentheses to specify meaning without relying on operator precedence. Code generated with this setting conforms to MISRA requirements. For example:

 Out = (((In2 - In1) > 1.0) && (In2 > 2.0));

Default: 'Nominal'

PassStructByReference

Specify whether to pass structures by reference to entry-point functions. Set to true to pass structures by reference. You thereby reduce memory usage and execution time by minimizing the number of copies of parameters at entry-point function boundaries. Set to false to pass structures by value.

This parameter applies only to entry-point functions.

If you set this parameter to true, an entry-point function that writes to a field of a structure parameter overwrites the input value.

Default: true

PostCodeGenCommand

Specify command to customize build processing after code generation using codegen. Specify command as a character vector.

Default: ''

PreserveExternInFcnDecls

Specify whether the declarations of external functions generated by codegen include the extern keyword.

Default: true

PreserveVariableNames

Specify which variable names the code generator must preserve in the generated code.

ValueDescription
'None'

The code generator does not have to preserve any variable names. It can reuse any variables that meet the requirements for variable reuse.

If your code uses large structures or arrays, setting PreserveVariableNames to 'None' can reduce memory usage or improve execution speed.

'UserNames'

The code generator preserves names that correspond to variables that you define in the MATLAB code. It does not replace your variable name with another name and does not use your name for another variable. To improve readability, set PreserveVariableNames to 'UserNames'. Then, you can more easily trace the variables in the generated code back to the variables in your MATLAB code.

Setting PreserveVariableNames to 'UserNames' does not prevent an optimization from removing your variables from the generated code or prevent the C/C++ compiler from reusing the variables in the generated binary code.

'All'

Preserve all variable names. This parameter value disables variable reuse. Use it only for testing or debugging, not for production code.

Default: 'None'

PurelyIntegerCode

Specify whether to generate floating-point data and operations.

Default: false

ReservedNameArray

Enter a space-separated list of names that MATLAB Coder is not to use for naming functions or variables. Specify list as a character vector.

Default: ''

RuntimeChecks

Enable run-time error detection and reporting in the generated C/C++ code. If you select this option, the generated code checks for errors such as out-of-bounds array indexing.

The error reporting software uses fprintf to write error messages to stderr. It uses abort to terminate the application. If fprintf and abort are not available, you must provide them. The abort function abruptly terminates the program. If your system supports signals, you can catch the abort signal (SIGABRT) so that you can control the program termination.

Error messages are in English.

Default: false

SaturateOnIntegerOverflow

Overflows saturate to either the minimum or maximum value that the data type can represent. Otherwise, the overflow behavior depends on your target C compiler. Most C compilers wrap on overflow.

This parameter applies only to MATLAB built-in integer types. It does not apply to doubles, singles, or fixed-point data types.

Default: true

SILDebugging

Enable debugger to observe code behavior during a software-in-the-loop (SIL) execution.

The software supports the following debuggers:

  • On Windows, Microsoft® Visual C++® debugger.

  • On Linux, GNU Data Display Debugger (DDD).

Default: false

StackUsageMax

Specify the maximum stack usage per application in bytes. Set a limit that is lower than the available stack size. Otherwise, a run-time stack overflow can occur. The C compiler detects and reports overflows.

Default: 200000

SupportNonFinite

Specify whether to generate nonfinite data and operations.

Default: true

TargetLang

Specify the target language. Set to 'C' to generate C code. Set to C++ to generate C++ code. If you specify C++, MATLAB Coder wraps the C code into .cpp files so that you can use a C++ compiler and interface with external C++ applications. It does not generate C++ classes.

Default: 'C'

TargetLangStandard

Specify a standard math library for the generated code. Options include 'C89/C90 (ANSI)', 'C99 (ISO)', and 'C++03 (ISO)'.

Before setting this parameter, verify that your compiler supports the library that you want to use. If you select a parameter value that your compiler does not support, compiler errors can occur.

Default: 'C89/C90 (ANSI)' for C, 'C++03 (ISO)' for C++.

Toolchain

Specify the toolchain to use. If you do not specify a toolchain, MATLAB Coder automatically locates an installed toolchain.

Default: 'Automatically locate an installed toolchain'

Verbose

Display code generation progress.

Default: false

VerificationMode

Specify code verification mode.

  • 'None' — Normal execution

  • 'SIL' — Software-in-the-loop (SIL) execution

  • 'PIL' — Processor-in-the-loop (PIL) execution

Default: 'None'

Settings

Enter a macro that specifies the format of the generated identifier. The macro can include valid C identifier characters and a combination of the following format tokens:

TokenDescription
$M

Code generator inserts name mangling text to avoid naming collisions.

Required.

$N

Code generator inserts name of object (global variable, global type, local function, local temporary variable, or constant macro) for which identifier is generated.

Improves readability of generated code.

$R

Code generator inserts root project name into identifier, replacing unsupported characters with the underscore (_) character.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB documentation.

Examples

Generate a standalone C/C++ static library from a MATLAB function that is suitable for code generation.

    Note:   To generate code for this example, you must have an Embedded Coder license.

  1. Write a MATLAB function, coderand, that generates a random scalar value from the standard uniform distribution on the open interval (0,1).

    function r = coderand() %#codegen
    % The directive %#codegen declares that the function
    % is intended for code generation
    r = rand();

  2. Create a code generation configuration object to generate a static library.

    cfg = coder.config('lib')
    This command creates a coder.EmbeddedCodeConfig object.

  3. Set the PurelyIntegerCode parameter to true to enable generation of integer-only code.

    cfg.PurelyIntegerCode = true;

  4. Generate the C library files in the default folder (codegen/lib/coderand). Use the -config option to specify the configuration object.

    codegen -config cfg coderand

Alternatives

Use the coder function to create a MATLAB Coder project. The project provides a user interface that facilitates adding MATLAB files, defining input parameters, and specifying build parameters.

Was this topic helpful?