メインコンテンツ

Supported MATLAB Functions with CMSIS Library for ARM Cortex-M Processors

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.

  • If you encounter situations where the ARM Cortex-M CMSIS CRL does not provide code replacements due to the input vector length being below the threshold, you can enable CMSIS function generation for all input lengths. To do this, set the environment variable DISABLE_ARMCORTEXM_CMSIS_CRL_THRESHOLDS to true using the following command:

    setenv('DISABLE_ARMCORTEXM_CMSIS_CRL_THRESHOLDS','true')

    To generate optimized code, thresholds are introduced . Forcing CMSIS function generation for all input lengths using this command can degrade performance.

Basic Math Operations

Basic Math Operations

Operation Wrappers calling CMSIS function Supported data typesInput/Output specificationsReplaced MATLAB® code
Absolutemw_arm_abs_f32 single
  • Vector or matrix

  • Real inputs

abs(a)
Additionmw_arm_add_f32 single
  • Vector and matrix

  • Real and complex inputs

a+b
mw_arm_add_q31 fixdt(true,32,31)
  • Vector and matrix

  • Real and complex inputs

fimath_q31 = fimath('SumMode','SpecifyPrecision',...
                    'OverflowAction','Saturate',...
                    'RoundingMethod','Floor',...
                    'SumWordLength',32,'SumFractionLength',31);
add(fimath_q31,a,b);
mw_arm_add_q15 fixdt(true,16,15)
  • Vector and matrix

  • Real and complex inputs

fimath_q15 = fimath('SumMode','SpecifyPrecision',...
                    'OverflowAction','Saturate',...
                    'RoundingMethod','Floor',...
                    'SumWordLength',16,'SumFractionLength',15);
add(fimath_q15,a,b);
mw_arm_add_q7 fixdt(true,8,7)
  • Vector and matrix

  • Real and complex inputs

fimath_q7 = fimath('SumMode','SpecifyPrecision',...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor',...
                   'SumWordLength',8,'SumFractionLength',7);
add(fimath_q7,a,b);
Bias/Offsetmw_arm_bias_1_f32single
  • Real inputs

  • First input must be a scalar.

  • Second input must be a vector or matrix.

a+b
mw_arm_bias_1_q31fixdt(true,32,*)
  • Real inputs

  • First input must be a scalar.

  • Second input must be a vector or matrix.

  • Supports different input word lengths.

  • Supports different input fraction lengths.

FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'SumWordLength',32,'SumFractionLength',31,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
add(FimathObj,a,b);
mw_arm_bias_1_q15fixdt(true,16,*)
FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'SumWordLength',16,'SumFractionLength',15,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
add(FimathObj,a,b);
mw_arm_bias_1_q7fixdt(true,8,*)
FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'SumWordLength',8,'SumFractionLength',7,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
add(FimathObj,a,b);
mw_arm_bias_2_f32single
  • Scalar inputs

  • Vector or matrix

  • Real inputs

  • First input must be a vector or matrix.

  • Second input must be a scalar.

a+b
mw_arm_bias_2_q31fixdt(true,32,*)
  • Vector or matrix

  • Real inputs

  • First input must be a vector or matrix.

  • Second input must be a scalar.

  • Supports different input word lengths.

  • Supports different input fraction lengths.

FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'SumWordLength',32,'SumFractionLength',31,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
add(FimathObj,a,b);
mw_arm_bias_2_q15fixdt(true,16,*)
FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'SumWordLength',16,'SumFractionLength',15,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
add(FimathObj,a,b);
mw_arm_bias_2_q7fixdt(true,8,*)
FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'SumWordLength',8,'SumFractionLength',7,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
add(FimathObj,a,b);
Exponentialmw_arm_vexp_f32single
  • Vector and matrix

  • Real inputs

exp(a)
Logarithmmw_arm_vlog_f32single
  • Vector and matrix

  • Real inputs

log(a)
Multiplicationmw_arm_mult_f32 single
  • Vector and matrix

  • Real inputs

a.*b
mw_arm_mult_q15 fixdt(true,16,*)
  • Vector and matrix

  • Real inputs

  • For multiplication operation, specify one input as a vector and the other as 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.

FimathObj = fimath('ProductMode','SpecifyPrecision',...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor',...
                   'ProductWordLength',16,'ProductFractionLength',15);
mpy(FimathObj,a,b);
mw_arm_mult_q7 fixdt(true,8,*)
  • Vector and matrix

  • Real inputs

  • For multiplication operation, specify one input as a vector and the other as 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.

FimathObj = fimath('ProductMode','SpecifyPrecision',...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor',...
                   'ProductWordLength',8,'ProductFractionLength',7);
mpy(FimathObj,a,b);
Scale/Gainmw_arm_scale_1_f32single
  • Vector and matrix

  • Real inputs

  • First input is a vector or matrix.

  • Second input is a scalar.

a.*b
mw_arm_scale_1_q15fixdt(true,16,*)
  • Vector and matrix

  • Real inputs

  • First input is a vector or matrix.

  • Second input is a scalar.

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

FimathObj = fimath('ProductMode','SpecifyPrecision',...
                   'ProductWordLength',16,...
                   'ProductFractionLength',15,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
mpy(FimathObj,a,b);
mw_arm_scale_1_q7fixdt(true,8,*)
FimathObj = fimath('ProductMode','SpecifyPrecision',...
                   'ProductWordLength',8,...
                   'ProductFractionLength',7,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
mpy(FimathObj,a,b);
mw_arm_scale_2_f32single
  • Vector and matrix

  • Real inputs

  • First input is a vector or matrix.

  • Second input is a scalar.

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

a.*b
mw_arm_scale_2_q15fixdt(true,16,*)
FimathObj = fimath('ProductMode','SpecifyPrecision',...
                   'ProductWordLength',16,...
                   'ProductFractionLength',15,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
mpy(FimathObj,a,b);
mw_arm_scale_2_q7fixdt(true,8,*)
FimathObj = fimath('ProductMode','SpecifyPrecision',...
                   'ProductWordLength',8,...
                   'ProductFractionLength',7,...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor');
mpy(FimathObj,a,b);
Subtraction mw_arm_sub_f32 single
  • Vector and matrix

  • Real and complex inputs

a-b
mw_arm_sub_q31 fixdt(true,32,31)
  • Vector and matrix

  • Real and complex inputs

FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor',...
                   'SumWordLength',32,'SumFractionLength',31);
sub(FimathObj,a,b);
mw_arm_sub_q15 fixdt(true,16,15)
  • Vector and matrix

  • Real and complex inputs

FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor',...
                   'SumWordLength',16,'SumFractionLength',15);
sub(FimathObj,a,b);
mw_arm_sub_q7 fixdt(true,8,7)
  • Vector and matrix

  • Real and complex inputs

FimathObj = fimath('SumMode','SpecifyPrecision',...
                   'OverflowAction','Saturate',...
                   'RoundingMethod','Floor',...
                   'SumWordLength',8,'SumFractionLength',7);
sub(FimathObj,a,b);
Square rootmw_arm_sqrt_f32 single
  • Vector and matrix

  • Real inputs

sqrt(a)
Unary minus/Negatemw_arm_uminus_f32single
  • Vector and matrix

  • Real inputs

uminus(a)
mw_arm_uminus_q31fixdt(true,32,*)
mw_arm_uminus_q15fixdt(true,16,*)
mw_arm_uminus_q7fixdt(true,8,*)

Shift Operations

Shift Operations

Operation Wrappers calling CMSIS function Supported data types Input/Output specificationsReplaced MATLAB code
Left shiftmw_arm_shift_q31 fixdt(true,32,*)
  • Vector and matrix

  • Real inputs

cast(a,'like',b)
mw_arm_shift_q15 fixdt(true,16,*)
mw_arm_shift_q7 fixdt(true,8,*)

Data Cast Operations

Data Cast Operations

Operation Wrappers calling CMSIS function Supported data types Input/Output specificationsReplaced MATLAB code
Cast float to fixed pointmw_arm_float_to_q15single
  • Vector and matrix

  • Real inputs

cast(a,'like',b)
mw_arm_float_to_q7single
  • Vector and matrix

  • Real inputs

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

  • Real inputs

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

  • Real inputs

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

  • Real inputs

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

  • Real inputs

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

  • Real inputs

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

  • Real inputs

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

  • Real inputs

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

  • Real inputs

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

  • Real inputs

Complex Math Operations

Complex Math Operations

Operation Wrappers calling CMSIS function Supported data typesInput/Output specificationsReplaced MATLAB code
Complex conjugatemw_arm_cmplx_conj_f32 single
  • Vector and matrix

  • Complex inputs

conj(a)
Complex-by-complex multiplicationmw_arm_cmplx_mult_cmplx_f32 single
  • Vector and matrix

  • Both inputs must be complex

a.*b
Complex-by-real multiplicationmw_arm_cmplx_mult_real_f32 single
  • Vector and matrix

  • Real and complex inputs

  • One input must be complex and the other must be real.

a.*b

Logical Operations

Logical Operations

Operation Wrappers calling CMSIS functionSupported data typesInput/Output specificationsReplaced MATLAB code
Logical ANDmw_arm_and_uint32
  • uint32

  • fixdt(false,32,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

bitand(a,b)
mw_arm_and_uint16
  • uint16

  • fixdt(false,16,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

mw_arm_and_uint8
  • uint8

  • fixdt(false,8,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

Logical ORmw_arm_or_uint32
  • uint32

  • fixdt(false,32,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

bitor(a,b)
mw_arm_or_uint16
  • uint16

  • fixdt(false,16,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

mw_arm_or_uint8
  • uint8

  • fixdt(false,8,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

Logical NOTmw_arm_not_uint32
  • uint32

  • fixdt(false,32,*)

  • Vector and matrix

bitcmp(a)
mw_arm_not_uint16
  • uint16

  • fixdt(false,16,*)

  • Vector and matrix

mw_arm_not_uint8
  • uint8

  • fixdt(false,8,*)

  • Vector and matrix

Logical XORmw_arm_xor_uint32
  • uint32

  • fixdt(false,32,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

bitxor(a,b)
mw_arm_xor_uint16
  • uint16

  • fixdt(false,16,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

mw_arm_xor_uint8
  • uint8

  • fixdt(false,8,*)

  • Vector and matrix

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

  • Both inputs must have same fraction length.

Matrix Operations

Matrix Operations

Operation Wrappers calling CMSIS functionSupported data typesInput/Output specificationsReplaced MATLAB code
Matrix multiplicationmw_arm_mat_mult_f32
  • single

  • Vector and matrix

a*b
Complex matrix multiplicationmw_arm_mat_cmplx_mult_f32
  • single

  • Vector and matrix

  • Complex values

a*b
Matrix transposemw_arm_trans_f32
  • single

  • Matrix

  • Real inputs

  • transpose(a)
  • a'
  • ctranspose(a)
  • a.'
mw_arm_trans_q31
  • fixdt(true,32,*)

mw_arm_trans_q15
  • fixdt(true,16,*)

mw_arm_trans_q7
  • fixdt(true,8,*)

mw_arm_mat_cmplx_trans_f32
  • single

  • Matrix

  • Complex inputs

  • transpose(a)
  • a'
mw_arm_mat_cmplx_trans_q31
  • fixdt(true,32,*)

mw_arm_mat_cmplx_trans_q15
  • fixdt(true,16,*)

Fourier Transform Operations

Fourier Transform Operations

MATLAB FunctionSupported Function SignaturesInput specificationsProperty specificationsEquivalent CMSIS Functions
fft

Y = fft(X)

Y = fft(X, n)

Y = fft(X, n, dim)

  • Real or Complex Values

  • Multichannel Input (Multiple columns)

  • single data type

Transform Length n:

  • Real Input: n must be in the range[9 2048] U {4096}-{16}.

  • Complex Input: n must be in the range[5 2048] U {4096}-{8}.

Dimension to operate along dim: dim must be a compile time constant.

  • arm_cfft_f32

  • arm_rfft_fast_init_f32

  • arm_rfft_fast_f32

Wrapper functions, each with an mw_ prefix bridge the library interface.

ifft

X = ifft(Y)

X = ifft(Y, n)

X = ifft(Y, n, dim)

X = ifft(__, symflag)

  • Real or Complex Values

  • Multichannel Input

  • single data type

Transform Length n: Minimum length is 8.

Dimension to operate along dim: dim must be a compile time constant.

Symmetric type symflag: non-symmetric (default)

  • arm_cfft_f32

  • arm_rfft_fast_init_f32

  • arm_rfft_fast_f32

Wrapper functions, each with an mw_ prefix bridge the library interface.

fft2

Y = fft2(X)

Y = fft2(X, m, n)

  • Real or Complex Values

  • Multichannel Input

  • single data type

Number of transform rows m:

  • Minimum length is 8 when input is real.

  • Minimum length is 4 when input is complex.

Number of transform rows n:

  • Minimum length is 8 when input is real.

  • Minimum length is 4 when input is complex.

  • arm_cfft_f32

  • arm_rfft_fast_init_f32

  • arm_rfft_fast_f32

Wrapper functions, each with an mw_ prefix bridge the library interface.

ifft2

X = ifft2(Y)

X = ifft2(Y, m, n)

X = ifft2(__, symflag)

  • Complex Values

  • Multichannel Input

  • single data type

Number of transform rows m:

  • Minimum length is 8

Number of transform rows n:

  • Minimum length is 8

Symmetric type symflag: non-symmetric (default)

  • arm_cfft_f32

  • arm_rfft_fast_init_f32

  • arm_rfft_fast_f32

Wrapper functions, each with an mw_ prefix bridge the library interface.

fftn

Y = fftn(X)

Y = fftn(X, sz)

  • Real or Complex Values

  • Multichannel Input (Multiple columns)

  • single data type

Length of transform dimension sz: Each sz element must have:

  • Minimum value 8 when input is real

  • Minimum value 4 when input is complex

  • arm_cfft_f32

  • arm_rfft_fast_init_f32

  • arm_rfft_fast_f32

Wrapper functions, each with an mw_ prefix bridge the library interface.

ifftn

X = ifftn(Y)

X = ifftn(Y, sz)

X = ifftn(__, symflag)

  • Complex Values

  • Multichannel Input

  • single data type

Length of transform dimension sz: Each sz element must have:

  • Minimum value is 8

  • arm_cfft_f32

  • arm_rfft_fast_init_f32

  • arm_rfft_fast_f32

Wrapper functions, each with an mw_ prefix bridge the library interface.

See Also

Topics