This example shows you how to run a processor in the loop (PIL) simulation using the Target for TI HERCULES™ RM48 MCUs package.


First Steps

Before attempting to run this example, make sure that you have gone through the steps to set up the Target for TI HERCULES RM48 MCUs package as described in the User's Guide - Initial Setup section.

Required Hardware

To run this example, you must have a TI RM48 target board such as an HDK or a controlCard. The HDK or controlCard must be powered and there must be both a JTAG and a Serial port connection ready.

If you are using an HDK or controlCard with the on-board XDS100v2 emulator then both of these criteria will be satisfied if the board is powered on and the USB JTAG emulation cable is connected between the host PC and the board.

Also, make sure that you have properly configured the preferences COMPORT and COMBAUD as instructed by the User's Guide - Initial Setup section.

Finally, make sure that the preference TCONF is configured to point to a CCS target configuration file (.ccxml) that matches your target hardware and emulator combination. The default target configuration file included with this package is for the RM48L950 device and the XDS100v2 emulator combination, but it should work with most RM48 series devices. If in doubt, make sure that you can connect to your target board through Composer Studio first, using the same TCONF file that you plan to use with this package.

Note: the COMPORT, COMBAUD, and TCONF preferences are part of the TI_HERCULES_RM48 preference group. Use the matlab command getpref('TI_HERCULES_RM48') to view their current settings.

Open the Example In Simulink

Change the current directory to the examples folder under the target's root folder, and open the model file 'ex1_fir_mdl_tb.slx':


Examine the Top Level (Testbench) Model

The top level model includes these key components:

The four sine wave blocks are configured to generate frequencies of 4KHz, 10KHz, 20KHz and 45KHz which are summed together and passed as stimulus to the filter block.

The filter coefficients are loaded into the workspace varialbe 'Coeff' from the file 'ex1_fir_coeff.mat' by the model's 'PostLoadFcn' callback.

 whos Coeff
ans =


  Name       Size            Bytes  Class     Attributes

  Coeff      1x64              256  single              

The filter is 64-Tap FIR lowpass filter. The coefficients are single single precision floating point, to match the FPU of the RM48 Cortex-R4F CPU. (The CPU supports both single and double precision instructions in hardware, but executes most single precision floating point instructions in a single cycle). Note that the stimulus is also converted to single precision before being passed to the filter block as the signal 'filterInput'.

The model sample rate is configured for 100KHz. You can configure this with the commands:


The magnitude response of the filter can be visualized with the following commands (assuming a 100KHz sample rate):

 Hd = dfilt.dffir(Coeff);
 h = fvtool(Hd);

Based on the frequency response, we expect:

We will verify these expectations are met on the RM48 hardware platform after we run the processor in the loop simulation.

Examine the Model Reference Block

The model reference block contains the filtering function that will be compiled, downloaded, and executed on the RM48 hardware during the PIL simulation.

You can confirm that the block is configured for PIL mode with the command

 set_param('ex1_fir_mdl_tb/ex1_fir_mdl','SimulationMode','processor-in-the-loop (pil)')
ans =

Processor-in-the-loop (PIL)

The Model Reference block links to the model file 'ex1_fir_mdl.slx'. This can be confirmed with the command:

ans =


You can also open and examine the referenced model, which is simply a 'Discrete FIR Filter' block from the DSP System Toolbox Library


Set Model Parameters for RM48 PIL Simulation

For Simulink Embedded Coder to build the Model Reference block using the Target for TI HERCULES RM48 MCUs, certain model parameters must be configured properly.

         tc = 'TI HERCULES RM48 Toolchain v1.0 | gmake (win32)';
         tc = 'TI HERCULES RM48 Toolchain v1.0 | gmake (win64)';
     case('GLNXA64')   % Plan to support in the future
         tc = '';
         str = ['Unsupported Platform: ' computer];
         tc = '';
         str = ['Unsupported Platform: ' computer];

% Additionally:
% * Parameter 'BuildConfiguration' should be set to 'Faster Runs' for
%   optimized code.

 set_param('ex1_fir_mdl_tb','ProdHWDeviceType','Texas Instruments->RM48');
 set_param('ex1_fir_mdl_tb','BuildConfiguration','Faster Runs')
 set_param('ex1_fir_mdl','ProdHWDeviceType','Texas Instruments->RM48');
 set_param('ex1_fir_mdl','BuildConfiguration','Faster Runs')

% Note that this approach uses the standard embedded realtime target (ert),
% as opposed to a custom target file.

Setup Execution Profiling

To configure the model for exeuction profiling, using the CPU's performance monitoring unit cycle counter, the following parameters must be set:


Run the PIL Simulation

Clear the 'slprj' folder to force a rebuild.
Then run the simulation.
stat = rmdir('slprj','s');
simOut = sim('ex1_fir_mdl_tb', ...
             'SaveTime',   'on', 'TimeSaveName',   'tout', ...
             'SaveOutput', 'on', 'OutputSaveName', 'yout', ...
             'SignalLogging', 'on', 'SignalLoggingName', 'logsout' ...
         ) %#ok
### Model reference SIM target (ex1_fir_mdl_msf.mexw64) for model ex1_fir_mdl is out of date because ex1_fir_mdl_msf.mexw64 does not exist.
### Updating model reference SIM target for model: ex1_fir_mdl
### Successfully updated the model reference SIM target for model: ex1_fir_mdl
### Model reference RTW target (ex1_fir_mdl.c) for model ex1_fir_mdl is out of date because ex1_fir_mdl.c does not exist.
### Starting build procedure for model: ex1_fir_mdl
### Successful completion of build procedure for model: ex1_fir_mdl
### Connectivity configuration for referenced model "ex1_fir_mdl": <a href="matlab: targets_hyperlink_manager('run',1);">RM48 HDK PIL Package</a> ###
### Preparing to start PIL simulation ...
### Starting application: slprj\ert\ex1_fir_mdl\pil\ex1_fir_mdl.out
Begin communication with RM48
Launching loadti to download C:\Users\a0321811\home\work\ti_hercules_rm48\TI_HERCULES_RM48\examples\slprj\ert\ex1_fir_mdl\pil\ex1_fir_mdl.out
Launcher command string: C:\Users\a0321811\home\work\ti_hercules_rm48\TI_HERCULES_RM48\utils\loader\loadti
Launcher command arguments: C:\ti\ccsv5\ccs_base\DebugServer C:\Users\a0321811\home\work\ti_hercules_rm48\TI_HERCULES_RM48\utils\loader -r -a -c "C:\Users\a0321811\home\work\ti_hercules_rm48\TI_HERCULES_RM48\src\TI_HERCULES_RM48PilSerial\TI_RM48HDK.ccxml" -x "C:\Users\a0321811\AppData\Local\Temp\tpf8954785_7266_4632_a045_76cad786bb64_loadti_log.xml" "C:\Users\a0321811\home\work\ti_hercules_rm48\TI_HERCULES_RM48\examples\slprj\ert\ex1_fir_mdl\pil\ex1_fir_mdl.out"
***** DSS Generic Loader *****

START: 18:18:26 GMT-0600 (CST)

Configuring Debug Server for specified target...
TARGET: Texas Instruments XDS100v2 USB Emulator_0
Connecting to target...
CortexR4: GEL Output: 	Memory Map Setup for Flash @ Address 0x0
Resetting target...
testEnv.outFiles: C:\Users\a0321811\home\work\ti_hercules_rm48\TI_HERCULES_RM48\examples\slprj\ert\ex1_fir_mdl\pil\ex1_fir_mdl.out 
Loading C:\Users\a0321811\home\work\ti_hercules_rm48\TI_HERCULES_RM48\examples\slprj\ert\ex1_fir_mdl\pil\ex1_fir_mdl.out
Target running...
END: 18:18:48 GMT-0600 (CST)
Pausing 3 Seconds


    tout: [5001x1 double]

Use 'get' to access a variable by name.

Examine the simulation results

From the spectrum scope output, it can be seen that the filter behaves
as expected.  The input (InOut - CH 1) and output (InOut - CH 2) green
are identical in magnituded for the 4KHz and 10Khz input frequencies.
At 20KHz, the output is attenuated by approximately 20dB and at 45KHz
the output is attenuated by 160dB.

Display Profiling Report

To display the profiling report, call the report() method of the executionProfile workspace variable:



If you have trouble reproducing these results, please consult the Troubleshooting section of the User's Guide

Copyright (C) 2012-2014 Texas Instruments Incorporated. Licensed as Creative Commons 3.0 Share Alike