Main Content

PIL Execution at the Command Line UsingMATLABCoder

This example shows how to set up a processor-in-the-loop (PIL) execution to verify generated code from a MATLAB®function usingMATLAB Coder™at the command line.

You can use PIL executions to verify generated code that you deploy to the STMicroelectronics®Discovery™ and STMicroelectronics Nucleo boards by using aMATLAB Coderprocedure. You can profile algorithm performance and speed of your generated code on the hardware board. To verify generated code, you must have MATLAB Coder and an Embedded Coder®license.

This PIL execution is supported with these hardware support packages.

  • Embedded Coder Support Package for BeagleBone®Black Hardware

  • Embedded Coder Support Package for ARM®Cortex®-A Processors

  • Embedded Coder Support Package for ARM Cortex-M Processors

  • 金宝app®Coder Support Package for STMicroelectronics Nucleo Boards

  • Embedded Coder Support Package for STMicroelectronics Discovery Boards

To set up a PIL execution:

  1. In the Command Window, select the hardware for PIL execution.

    hw = coder.hardware('STM32F4-Discovery')
    hw = Hardware with properties: Name: 'STM32F4-Discovery' CPUClockRate: 168 PILCOMPort: 'COM1' PILInterface: 'ST-LINK'

  2. Add the hardware to the MATLAB Coder configuration object.

    cfg = coder.config('lib','ecoder',true); cfg.VerificationMode ='PIL'; cfg.Hardware = hw;

    The memory of the hardware board is limited, and a default value of20000is beyond the stack size available in the hardware. We recommend you to set theStackUsageMaxvalue to512. However, specify an appropriate stack usage based on your algorithm.

    cfg。StackUsageMax = 512;
  3. Generate the PIL code for a function,averaging_filter.

    codegen-configcfgaveraging_filter-args{zeros(1,16)}

    For more information on theaveraging_filterfunction, see the exampleAveraging Filter.

For another example of PIL verification, see theProcessor-in-the-Loop Verification of MATLAB Functionsexample in the documentation of theEmbedded Coder Support Package for STMicroelectronics Discovery Boards.

To install theEmbedded Coder Support Package for STMicroelectronics Discovery Boards, seeEmbedded Coder Supported Hardware.