Main Content

Supported Simulink Blocks with CMSIS Library for ARM Cortex-M Processors

The Embedded Coder® Support Package for ARM® Cortex®-M Processors provides a code replacement library (CRL) for common microcontroller software interface standard (CMSIS) functions.

CMSIS CRL supports these processors:

  • Cortex-M0

  • Cortex-M0+

  • Cortex-M3

  • Cortex-M4

  • Cortex-M7

  • Cortex-M33

To improve the simulation speed of your models and performance of the generated code, you can set the model configuration parameters under the Code Generation>Optimization category. For more information on how to set the model parameters, see Model Configuration Parameters: Code Generation Optimization.

Note

  • To get the code replacement, in the code generation configuration settings, set CodeReplacementLibrary to ARM Cortex-M.

  • Select the Saturate on integer overflow option in Simulink® blocks for CRL replacements. Refer to Enable Saturate on Integer Overflow on a Block section in Collect Saturation on Integer Overflow Coverage (Simulink Coverage).

  • All CRLs have been tested with CMSIS version 5.9.

Basic Math Operations

Operation Wrappers calling CMSIS function Supported data typesInput specificationsParameter specificationsReplaced Simulink block
Absolutemw_arm_abs_f32 single
  • Vector and matrix

  • Real inputs

-Abs
mw_arm_abs_q31 fixdt(true,32,31)
  • Vector and matrix

  • Real inputs

mw_arm_abs_q15 fixdt(true,16,15)
  • Vector and matrix

  • Real inputs

mw_arm_abs_q7 fixdt(true,8,7)
  • Vector and matrix

  • Real inputs

Additionmw_arm_add_f32 single
  • Vector and matrix

  • Real and complex inputs

Note

Using a vector input and a vector bias value in the Bias block will also trigger code replacement.

-Add
mw_arm_add_q31 fixdt(true,32,*)
  • Vector and matrix

  • Real and complex inputs

  • Fraction length of inputs must be same.

Note

For real inputs, the CRL generates code replacement when the word length is 32, even if the fraction length of the inputs differ.

mw_arm_add_q15 fixdt(true,16,*)
  • Vector and matrix

  • Real and complex inputs

  • Fraction length of inputs must be same.

Note

For real inputs, the CRL generates code replacement when the word length is 16, even if the fraction length of the inputs differ.

mw_arm_add_q7 fixdt(true,8,*)
  • Vector and matrix

  • Real and complex inputs

  • Fraction length of inputs must be same.

Note

For real inputs, the CRL generates code replacement when the word length is 8, even if the fraction length of the inputs differ.

Bias/Offsetmw_arm_bias_1_f32single
  • Scalar input

  • Real inputs

Bias parameter in the Bias block can be vector and matrix.Bias
mw_arm_bias_1_q31fixdt(true,32,*)
  • Scalar input

  • Real inputs

  • Supports different input and bias word lengths.

  • Supports different input and bias fraction length

mw_arm_bias_1_q15fixdt(true,16,*)
mw_arm_bias_1_q7fixdt(true,8,*)
mw_arm_bias_2_f32single
  • Vector and matrix

  • Real inputs

Bias parameter in the Bias block must be a scalar.
mw_arm_bias_2_q31fixdt(true,32,*)
  • Vector and matrix

  • Real inputs

  • Supports different input and bias word lengths.

  • Supports different input and bias fraction length

mw_arm_bias_2_q15fixdt(true,16,*)
mw_arm_bias_2_q7fixdt(true,8,*)
Dot productmw_arm_dot_f32single
  • Vector

  • Real inputs

  • Both inputs must have same fraction length

-Dot Product
mw_arm_dot_q15fixdt(true,16,*)
  • Vector

  • Real inputs

  • Both inputs must have same fraction length

Note

  • Set the output word length to 64 for an input word length of 16.

  • Fraction length of output must be sum of input fraction lengths.

mw_arm_dot_q7fixdt(true,8,*)
  • Vector

  • Real inputs

  • Both inputs must have same fraction length

Note

  • Set the output word length to 32 for an input word length of 8.

  • Fraction length of output must be sum of input fraction length.

Exponentialmw_arm_vexp_f32single
  • Vector and matrix

  • Real inputs

Set the Function parameter of Math Function block to exp.

Math Function
Logarithmmw_arm_vlog_f32single
  • Vector and matrix

  • Real inputs

Set the Function parameter of Math Function to log.

Math Function
Multiplicationmw_arm_mult_f32 single
  • Vector and matrix

  • Real inputs

Note

For multiplication operation, one input can be a vector while the other input can be a matrix.

-Product, Matrix Multiply
mw_arm_mult_q15 fixdt(true,16,*)
  • Vector and matrix

  • Real inputs

Note

  • For multiplication operation, one input can be a vector while the other input can be a matrix.

  • Sum of input fraction length must be greater than 15.

  • Fraction length of output must be 15 less than sum of input fraction length.

mw_arm_mult_q7 fixdt(true,8,*)
  • Vector and matrix

  • Real inputs

Note

  • For multiplication operation, one input can be a vector while the other input can be a matrix.

  • Sum of input fraction length must be greater than 7.

  • Fraction length of output must be 7 less than sum of input fraction length.

Saturate/Limit/Clippingmw_arm_saturate_f32single
  • Vector and matrix

  • Real inputs

Upper and lower limits of the Saturation block must be scalar values

Saturation
mw_arm_saturate_q31fixdt(true,32,*)
  • Vector and matrix

  • Real inputs

  • Upper and lower limits of the Saturation block must be scalar values.

  • The word length of input, upper limit, and lower limit must be 32.

  • The fraction length of input, upper limit, and lower limit can be different.

mw_arm_saturate_q15fixdt(true,16,*)
  • Vector and matrix

  • Real inputs

  • Upper and lower limits of the Saturation block must be scalar values.

  • The word length of input, upper limit, and lower limit must be 16.

  • The fraction length of input, upper limit, and lower limit can be different.

mw_arm_saturate_q7fixdt(true,8,*)
  • Vector and matrix

  • Real inputs

  • Upper and lower limits of the Saturation block must be scalar values.

  • The word length of input, upper limit, and lower limit must be 8.

  • The fraction length of input, upper limit, and lower limit can be different.

Scale/Gainmw_arm_scale_1_f32single
  • Vector and matrix

  • Real inputs

  • Set the Multiplication parameter in the Gain block to Matrix(K*u).

  • The Gain parameter value of the Gain must be a scalar

Gain
mw_arm_scale_1_q15fixdt(true,16,*)
  • Vector and matrix

  • Real inputs

  • Supports different input, scalar gain value, and word lengths.

  • The fraction length of output must be less than the sum of fraction length of inputs.

  • Set the Multiplication parameter in the Gain block to Matrix(K*u).

  • The Gain parameter value of the Gain block must be a scalar

mw_arm_scale_1_q7fixdt(true,8,*)
mw_arm_scale_2_f32single
  • Vector and matrix

  • Real inputs

  • One input can be a vector or matrix, while the other input to the Product, Matrix Multiply block must be a scalar.

Set the Multiplication parameter in the Product, Matrix Multiply block to Element-wise(.*).

mw_arm_scale_2_q15fixdt(true,16,*)
mw_arm_scale_2_q7fixdt(true,8,*)
Subtraction mw_arm_sub_f32 single
  • Vector and matrix

  • Real and complex inputs

-Sub
mw_arm_sub_q31 fixdt(true,32,*)
  • Vector and matrix

  • Real and complex inputs

  • Fraction length of inputs must be same.

Note

For real inputs, the CRL generates code replacement when the word length is 32, even if the fraction lengths of the inputs differ.

mw_arm_sub_q15 fixdt(true,16,*)
  • Vector and matrix

  • Real and complex inputs

  • Fraction length of inputs must be same.

Note

For real inputs, the CRL generates code replacement when the word length is 16, even if the fraction lengths of the inputs differ.

mw_arm_sub_q7 fixdt(true,8,*)
  • Vector and matrix

  • Real and complex inputs

  • Fraction length of inputs must be same.

Note

For real inputs, the CRL generates code replacement when the word length is 8, even if the fraction lengths of the inputs differ.

Square rootmw_arm_sqrt_f32 single
  • Vector and matrix

  • Real inputs

-Sqrt
Unary minus/Negatemw_arm_uminus_f32single
  • Vector and matrix

  • Real inputs

-Unary Minus
mw_arm_uminus_q31fixdt(true,32,*)
mw_arm_uminus_q15fixdt(true,16,*)
mw_arm_uminus_q7fixdt(true,8,*)

Shift Operations

Operation Wrappers calling CMSIS function Supported data types Input specificationsReplaced Simulink block
Right shiftmw_arm_shift_q31 fixdt(true,32,31)
  • Vector and matrix

  • Real inputs

Shift Arithmetic
mw_arm_shift_q15 fixdt(true,16,15)
  • Vector and matrix

  • Real inputs

mw_arm_shift_q7 fixdt(true,8,7)
  • Vector and matrix

  • Real inputs

Data Cast Operations

Operation Wrappers calling CMSIS function Supported data types Input specificationsParameter specificationsReplaced Simulink block
Cast float to fixed pointmw_arm_float_to_q15single
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,16,15)

Data Type Conversion
mw_arm_float_to_q7single
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,8,7)

Cast q31 to floatmw_arm_q31_to_float fixdt(true,32,31)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to single

Cast q31 to q15mw_arm_q31_to_q15 fixdt(true,32,31)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,16,15)

Cast q31 to q7mw_arm_q31_to_q7 fixdt(true,32,31)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,8,7)

Cast q15 to floatmw_arm_q15_to_float fixdt(true,16,15)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to single

Cast q15 to q31mw_arm_q15_to_q31 fixdt(true,16,15)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,32,31)

Cast q15 to q7mw_arm_q15_to_q7 fixdt(true,16,15)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,8,7)

Cast q7 to floatmw_arm_q7_to_float fixdt(true,8,7)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to single

Cast q7 to q31mw_arm_q7_to_q31 fixdt(true,8,7)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,32,31)

Cast q7 to q15mw_arm_q7_to_q15fixdt(true,8,7)
  • Vector and matrix

  • Real inputs

The Output data type parameter of Data Type Conversion block must be set to fixdt(1,16,15)

Trigonometric Operations

Operation Wrappers calling CMSIS function Supported data typesInput specificationsParameter specificationsReplaced Simulink block
sine mw_arm_sin_f32 single
  • Vector and matrix

  • Real inputs

  • The Approximation method parameter of Trigonometric Function block must be set to Lookup

  • Look-up table errors cause a numerical mismatch on the order of 5e-03.

Trigonometric Function
cosine mw_arm_cos_f32 single

Complex Math Operations

Operation Wrappers calling CMSIS function Supported data typesInput specificationsParameter specificationsReplaced Simulink block
Complex conjugatemw_arm_cmplx_conj_f32 single
  • Vector and matrix

  • Complex inputs

Set the Function parameter of Math Function to conj.

Math Function
mw_arm_cmplx_conj_q31 fixdt(true,32,31)
mw_arm_cmplx_conj_q15 fixdt(true,16,15)
Complex-by-complex multiplicationmw_arm_cmplx_mult_cmplx_f32 single
  • Vector and matrix

  • Both inputs must be complex

Set the Multiplication parameter of Math Function in the Product, Matrix Multiply block to Elementwise(.*).

Product, Matrix Multiply
mw_arm_cmplx_mult_cmplx_q31 fixdt(true,32,31)
  • Vector and matrix

  • Both inputs must be complex

mw_arm_cmplx_mult_cmplx_q15 fixdt(true,16,15)
  • Vector and matrix

  • Both inputs must be complex

Complex-by-real multiplicationmw_arm_cmplx_mult_real_f32 single
  • Vector and matrix

  • Real and complex inputs

  • One input should be complex, and the other input should be real.

Set the Multiplication parameter in the Product, Matrix Multiply block to Elementwise(.*).

Product, Matrix Multiply
mw_arm_cmplx_mult_real_q31 fixdt(true,32,31)
  • Vector and matrix

  • Real and complex inputs

  • One input should be complex, and the other input should be real.

mw_arm_cmplx_mult_real_q15 fixdt(true,16,15)
  • Vector and matrix

  • Real and complex inputs

  • One input should be complex, and the other input should be real.

Logical Operations

Operation Wrappers calling CMSIS functionSupported data typesInput specificationsParameter specificationsReplaced Simulink block
Logical ANDmw_arm_and_unit32
  • unit32

  • fixdt(false,32,*)

  • Vector and matrix

  • Both inputs must be unit32 or fixdt(false,32,*).

  • Both inputs must have same fraction length.

Set the Operator parameter in the Bitwise Operator block to AND.

AND
mw_arm_and_unit16
  • unit16

  • fixdt(false,16,*)

  • Vector and matrix

  • Both inputs must be unit16 or fixdt(false,16,*).

  • Both inputs must have same fraction length.

mw_arm_and_unit8
  • unit8

  • fixdt(false,8,*)

  • Vector and matrix

  • Both inputs must be unit8 or fixdt(false,8,*).

  • Both inputs must have same fraction length.

Logical ORmw_arm_or_unit32
  • unit32

  • fixdt(false,32,*)

  • Vector and matrix

  • Both inputs must be unit32 or fixdt(false,32,*).

  • Both inputs must have same fraction length.

Set the Operator parameter in the Bitwise Operator block to OR.

OR
mw_arm_or_unit16
  • unit16

  • fixdt(false,16,*)

  • Vector and matrix

  • Both inputs must be unit16 or fixdt(false,16,*).

  • Both inputs must have same fraction length.

mw_arm_or_unit8
  • unit8

  • fixdt(false,8,*)

  • Vector and matrix

  • Both inputs must be unit8 or fixdt(false,8,*).

  • Both inputs must have same fraction length.

Logical NOTmw_arm_not_unit32
  • unit32

  • fixdt(false,32,*)

  • Vector and matrix

Set the Operator parameter in the Bitwise Operator block to NOT.

NOT
mw_arm_not_unit16
  • unit16

  • fixdt(false,16,*)

  • Vector and matrix

mw_arm_not_unit8
  • unit8

  • fixdt(false,8,*)

  • Vector and matrix

Logical XORmw_arm_xor_unit32
  • unit32

  • fixdt(false,32,*)

  • Vector and matrix

  • Both inputs must be unit32 or fixdt(false,32,*).

  • Both inputs must have same fraction length.

Set the Operator parameter in the Bitwise Operator block to XOR.

XOR
mw_arm_xor_unit16
  • unit16

  • fixdt(false,16,*)

  • Vector and matrix

  • Both inputs must be unit16 or fixdt(false,16,*).

  • Both inputs must have same fraction length.

mw_arm_xor_unit8
  • unit8

  • fixdt(false,8,*)

  • Vector and matrix

  • Both inputs must be unit8 or fixdt(false,8,*).

  • Both inputs must have same fraction length.

Matrix Operations

Operation Wrappers calling CMSIS functionSupported data typesInput specificationsParameter specificationsReplaced Simulink block and MATLAB® function
Matrix multiplicationmw_arm_mat_mult_f32
  • single

  • Vector and matrix

-Product, Matrix Multiply
mw_arm_mat_mult_q15
  • fixdt(true,16,15)

  • Vector and matrix

  • Both inputs must be fixdt(true,16,*).

  • Both inputs must have same fraction length.

Note

The output with CRL replacement differs from the Simulink output because the CMSIS APIs use a higher accumulator, whereas Simulink uses an accumulator with a size equal to the input word length

mw_arm_mat_mult_q7
  • fixdt(true,8,7)

  • Vector and matrix

  • Both inputs must be fixdt(true,8,*).

Note

The output with CRL replacement differs from the Simulink output because the CMSIS APIs use a higher accumulator, whereas Simulink uses an accumulator with a size equal to the input word length

Matrix transposemw_arm_trans_f32
  • single

  • Matrix

  • Real inputs

-Transpose
mw_arm_trans_q31
  • fixdt(true,32,31)

mw_arm_trans_q15
  • fixdt(true,16,15)

mw_arm_trans_q7
  • fixdt(true,8,7)

mw_arm_mat_cmplx_trans_f32
  • single

  • Matrix

  • Complex inputs

transpose
mw_arm_mat_cmplx_trans_q31
  • fixdt(true,32,31)

mw_arm_mat_cmplx_trans_q15
  • fixdt(true,16,15)