Activate the External Mode Feature
External mode is used to validate algorithm code by enabling parameter tuning and signal monitoring. In this section, you add the external mode feature to your target.
Follow these steps if your hardware:
Runs the Linux® or VxWorks® operating system
Includes a TCP/IP software stack
Is connected to the host computer via an Ethernet interface
For more details about creating custom external mode, see Create a Transport Layer for TCP/IP or Serial External Mode Communication.
Create and add an
ExternalModeobject,ext, to yourTargetobject,tgt, by callingaddNewExternalModewith the name to be used for this external mode configuration, for example,'My New External Mode'.ext = addNewExternalMode(tgt,'My New External mode');Do not delete the
ExternalModeobject from the MATLAB® workspace before you save the target.Confirm that the external mode configuration named
'My New External Mode'is added to you target.show(tgt);
My ARM Cortex A Board Display Name My ARM Cortex A Board My New Deployer 1 My New PIL My Ethernet Interface Linux 1 My New External Mode 0
The external mode configuration
'My New External Mode'is added to the target. However, the 0 indicates that the external mode configuration is not used for the hardware'My ARM Cortex A Board'.Map the
ExternalModeobject to the to theHardwareobject,hw, and to its I/O interface named'My Ethernet Interface'.map(tgt,hw,ext,'My Ethernet Interface');Confirm that the external mode configuration is used for the hardware and its I/O interface.
show(tgt);
My ARM Cortex A Board Display Name My ARM Cortex A Board My New Deployer 1 My New PIL My Ethernet Interface Linux 1 My New External Mode My Ethernet Interface
The external mode configuration
'My New External Mode'is used for the hardware'My ARM Cortex A Board'as shown by its I/O interface,'My Ethernet Interface', appearing in the corresponding position for the hardware.View properties of the
ExternalModeobject.ext
ext = ExternalMode with properties: Name: 'My New External Mode' SourceFiles: {} PreConnectFcn: '' SetupFcn: '' CloseFcn: ''Set the property values as needed for your hardware. For more information, see
matlabshared.targetsdk.ExternalModeSpecify the source files to use when building a model that uses external mode feature by setting the
SourceFilesproperty of theExternalModeobject. For example, to set the source files for external mode using Ethernet I/O interface enter, enter:ext.SourceFiles = {'$(MATLAB_ROOT)/rtw/c/src/ext_mode/common/rtiostream_interface.c', '$(MATLAB_ROOT)/toolbox/coder/rtiostream/src/rtiostreamtcpip/rtiostream_tcpip.c'}Note
$(MATLAB_ROOT)is a token that stands for the root folder of MATLAB. The code generation software resolves this token.Specify that MATLAB executes a function before an external mode connection is established between Simulink® and generated code. Set the
PreConnectFcnproperty of theExternalModeobject to, for example,'pause(5);'.ext.PreConnectFcn = 'pause(5);'Save the information that describes a target to its framework.
saveTarget(tgt);
Test that the external mode works correctly.
testTarget(tgt,'externalmode');Upon completion of the test, a summary result is displayed. If the test
PASSED, then you can proceed with adding the next feature. Otherwise, if the test eitherFAILEDor isINCOMPLETE, a link to the test diagnostic logs is shown below the test summary.
Confirm That External Mode is Registered for Your Hardware
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 A Board'.In the Hardware tab, click Hardware Settings.
In the Configuration Parameters dialog box, select
Solver.From the Type list, select
Fixed-step. From the Solver list, selectauto.In the Target Hardware Resources section, select the External mode group. Confirm that the external mode properties are displayed correctly for your hardware.

Confirm the Operation of the External Mode
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 A Board'.In the Hardware tab, click Hardware Settings.
In the Configuration Parameters dialog box, select
Solver.From the Type list, select
Fixed-step. From the Solver list, selectauto.From the Sources library, add the Constant block to your model.
From the Math Operations library, add the Gain block to your model. Connect the Constant and the Gain block.
From the Sinks library, add the Scope block to your model. Connect the Scope and the Gain block.
Open the Scope block.
In the Hardware tab, click Monitor & Tune to run the simulation in external mode. Confirm that the Scope block output is 1.