Code Verification and Validation with PIL for STMicroelectronics STM32 Processors Based Boards
This example shows how to use Embedded Coder® Support Package for STMicroelectronics® STM32 Processors for code verification and validation using Processor-in-the-Loop (PIL).
Introduction
In this example you will learn how to configure a Simulink® model to run Processor-in-the-Loop (PIL). In a PIL simulation, the generated code runs on the STM32 processor based boards. The results of the PIL simulation are transferred to Simulink to verify the numerical equivalence of the simulation and the code generation results. The PIL verification process is a crucial part of the development cycle to ensure that the behavior of the deployment code matches the design.
This example introduces the Simulink® code generation and verification workflow by showing you how to configure a Simulink® model to run PIL simulations on the STM32 processor based boards.
Prerequisites
Complete the following tutorials:
Required Hardware
STMicroelectronics NUCLEO-F429ZI board
Micro USB cable
Task 1 - Configure PIL for STM32 Processor Based Boards
The STM32 Processor based boards support serial communication interfaces for PIL.
1. Open the stm32_pil_block model.
2. Press CTRL+E to open Configuration Parameters dialog box. Go to Hardware implementation > Hardware board > Target hardware resources > Connectivity and specify the COM Port and USART.
For the purpose of this example, set USART to USART3.
Note: To see the list of available COM ports on your computer, select Start > Control Panel > Device Manager > Ports (COM &LPT).
3. Configure the same USART3 in the STM32CubeMX project. For more, see Serial Configuration for Monitor & Tune and PIL for STM32 Processor-Based Boards
Task 2 - Verify Generated Code for your Subsystem Using PIL Block
This task shows how to use a PIL block to verify the generated code for a subsystem. With this approach:
You can verify the code generated for a subsystem.
You must provide a test harness model to supply a test vector or stimulus inputs.
You must swap your original subsystem with a generated PIL block; Do not save your model in this state as this will delete your original subsystem
1. Open the stm32_pil_block model. This model is configured for the STM32 Processor based boards target.
The model creates a PIL block out of the Controller subsystem that you later run on the STM32 Processor based boards.
2. Configure the PIL communication interface by completing the steps in Task 1.
3. Enable PIL by completing Step 2 in Task 1 of the Code Verification and Validation with PIL example.
4. Create a PIL block for the Controller subsystem by completing Step 2 in Task 1 of the Code Verification and Validation with PIL example.
5. Run PIL simulation by completing Step 2 in Task 1 of the Code Verification and Validation with PIL example.
6. You can switch between the original subsystem and the PIL block subsystems by double-clicking the Manual Switch block. Double-click the Numerical Differences block to see the difference between the simulated Controller subsystem and the PIL block running on the STM32 Processor based board.
Task 3 - Verify Referenced Model Code Using PIL
This task shows how to verify the generated code for a referenced model by running a PIL simulation. With this approach:
You can verify the code generated for the referenced models.
You must provide a test harness model to provide a test vector or stimulus inputs.
You can easily switch a Model block between the normal and PIL simulation modes.
1. Open the stm32_model_pil_block model. This model is configured for STM32 Processor Based Boards target. Configure one of the Model blocks to run in the PIL simulation mode and the other in the normal mode.
2. Configure a PIL communication interface by completing the steps in Task1.
3. Configure and run CounterA Model block in PIL simulation mode by completing Step 2 in Task of the Code Verification and Validation with PIL example.
4. When the model starts running, Scope1 displays the PIL simulation output running on the STM32 Processor based board, while Scope2 shows the normal mode simulation output.
Task 4 - Verify Top Model Code Using PIL
This tasks shows how to verify the generated code for a model by running a PIL simulation. With this approach:
You can verify code generated for a top model.
You must configure the model to load test vectors or stimulus inputs from the MATLAB™ workspace.
You can easily switch the entire model between the normal and the PIL simulation modes.
1. Open the stm32_top_model_pil model. This model is configured for the STM32 Processor Based Boards target.
2. Configure the PIL communication interface by completing the steps in Task 1.
3. Run the top model PIL simulation by completing step 2 of Task 3 of the Code Verification and Validation with PIL example.
4. When the PIL simulation is completed, a logsOut variable is created in the base workspace. The logsOut data contains PIL simulation results. You can access the logged data for signals count_a and count_b using the following commands:
count_a = get(logsOut,'count_a');
count_a.Values.Data
count_b = get(logsOut,'count_b');
count_b.Values.Data