Activate the Processor-in-the-Loop Feature
Each target must have a connectivity configuration for the processor-in-the-loop
(PIL) feature. By default, a connectivity configuration for your target
is created based on the connectivity configuration of the reference
target when you save your target. The target is stored in the ConnectivityConfig.m
file
of this folder:
<targetrootfolder>/matlabshared/+target/+<yourtargetpackage>
Note
The <yourtargetpackage>
folder name
is autogenerated from the name of your target by removing all spaces.
The connectivity configuration is registered with Simulink® via
the rtwTargetInfo.m
file. The rtwTargetInfo.m
file
gets created and stored in the <targetrootfolder>
when
you save your target.
The generated ConnectivityConfig.m
file points
to the connectivity configuration of the reference target. The connectivity
configuration of the reference target was created for a special emulator
interface used by the reference target and most likely not appropriate
for the hardware supported by your target. To customize the connectivity
configuration of your target, see Host-Target Communication for Simulink PIL Simulation.
Caution
Whenever you save a target, the connectivity configuration and
the rtwTargetInfo.m
file are overwritten by the
default implementation described previously. Do not make any manual
changes to the connectivity configuration and customization method
until after you save the target for the final time.
Create and add a new
PIL
object to yourTarget
(Embedded Coder Support Package for ARM Cortex-A Processors) object,tgt
, by callingaddNewPIL
with the name for the PIL connectivity configuration, for example,'MyPIL'
.pil = addNewPIL(tgt,'MyPIL');
Do not delete the
PIL
object from the MATLAB® workspace before you save the target.Confirm that the PIL configuration
'MyPIL'
is added to your target.show(tgt);
My ARM Cortex M Board Display Name My ARM Cortex M Board My New Deployer 1 My Baremetal Scheduler 1 My New PIL 0
The PIL configuration
'My New PIL'
is added to the target. However, the 0 indicates that the PIL configuration is not used for the hardware'My ARM Cortex M Board'
.Map the
PIL
object to theHardware
object,hw
, and to its I/O interface, for example,'My Serial Interface'
.map(tgt,hw,pil,'My Serial Interface');
Confirm that the PIL configuration
'My New PIL'
is used for the hardware'My ARM Cortex M Board'
and its I/O interface'My Serial Interface'
.show(tgt);
My ARM Cortex M Board Display Name My ARM Cortex M Board My New Deployer 1 My Baremetal Scheduler 1 My New PIL My Serial Interface
The PIL configuration
'My New PIL'
is used for the hardware'My ARM Cortex M Board'
, as indicated by'My Serial Interface'
in the corresponding position for the hardware.Save target description information to its framework.
saveTarget(tgt);
At the MATLAB command line, test that the PIL works correctly.
testTarget(tgt,'pil');
Upon completion of the test, a summary result is displayed.
Note
Testing the PIL feature requires opening and deploying several models to your hardware board. This process requires some time to complete.
Confirm the Operation of the PIL Feature
Create a blank Simulink model named
test
.On the Apps tab, click Run on Hardware Board. In the Run on Hardware Board dialog box, set Hardware board to the hardware you registered, for example,
'My ARM Cortex M Board'
.In the Configuration Parameters dialog box, on the Solver pane.
From the Type list, select
Fixed-step
. From the Solver list, selectauto
.Set Code Generation > Verification > Advanced Parameters > Create block to PIL. Then, click OK.
Open the Simulink Library Browser and from the Sources library, add a Constant block to your model.
From the Math Operations library, add the Gain block to your model. Connect the Constant and the Gain block.
Add a Subtract block to your model and connect its first input port to the Gain block.
In the Gain block, select
Create Subsystem from Selection
.In the Subsystem block, select C/C++ Code > Build this Subsystem. Click Build in the dialog box that opens. After the build completes, a library containing the PIL Subsystem block is created. This block is the gateway to the generated code that will run on the hardware.
Copy the PIL Subsystem block from the library to your model. Connect its input to the Constant block and its output to the second input port of the Subtract block.
In the Sinks library, add a Scope block to your model. Connect the Subtract and the Scope block.
Open the Scope block, and then run the model. The PIL simulation runs for 10 seconds, but because the model is so simple, the simulation takes far less time to complete.
After the PIL simulation completes, the Scope block displays the difference between the outputs of the two Subsystem blocks. The difference is constantly 0.
In the original Subsystem block, open the Gain block. Set Gain to 2. Click OK.
Run the model. After the PIL simulation completes, the Scope block displays the difference between the outputs of the two Subsystem blocks. Now, the difference is constantly 1 because the generated code reflects the original Gain block value of 1.