Activate the Application Deployment Feature
To execute code generated from a Simulink® model, you must compile, link, and download the code to the hardware board. In this section, you specify tools for compiling and linking generated code. You also specify tools for downloading and executing generated code on your hardware board.
A toolchain compiles and links the generated code with other embedded software to produce an executable application that can run on hardware board. The reference target for ARM® Cortex®-A hardware board, provides support for the Linaro Toolchain, a variant of the GNU ARM GCC toolchain. If this toolchain is suitable for compiling and linking code for your new target and the supported hardware board, you do not need to integrate another toolchain. Instead, you can reuse the Linaro Toolchain. If you need to support different toolchains, integrate the new toolchains by following the instructions described in Custom Toolchain Registration.
Specify Application Deployment Options
You specify application deployment options for each hardware board that you want the
new target to support. Specifically, you add a Deployer
feature object to your target
and map it to the Hardware
object by calling the
map
method of the Target
object. You may map one
Deployer
object to multiple Hardware
objects.
Create a
Deployer
object,dep
, and add it to theTarget
object,tgt
, by callingaddNewDeployer
with the name of the deployer, for example,'My New Deployer'
.dep = addNewDeployer(tgt,'My New Deployer');
Do not delete the
Deployer
object from the MATLAB® workspace before you save your new target.Confirm that the deployer is added to your target.
show(tgt);
My ARM Cortex A Board Display Name My ARM Cortex A Board My New Deployer 0
The deployer
'My New Deployer'
is added to the target. However, the0
indicates that the deployer is not used for the hardware board'My ARM Cortex A Board'
.Map the
Deployer
object, to theHardware
object.map(tgt,hw,dep);
Confirm that the deployer
'My New Deployer'
is used for the hardware board'My ARM Cortex A Board'
.show(tgt);
My ARM Cortex A Board Display Name My ARM Cortex A Board My New Deployer 1
The
1
indicates that the deployer'My New Deployer'
is used for the hardware board'My ARM Cortex A Board'
.Create a
Toolchain
object,toolchain
, and add it to theDeployer
object by callingaddNewToolChain
with the name of the toolchain, for example,'Linaro Toolchain v4.8'
.toolchain = dep.addNewToolchain('Linaro Toolchain v4.8');
Create a
BuildConfiguration
object,buildConfiguration
, and add it to theToolchain
object by callingaddNewBuildConfiguration
with the name of the build configuration, for example,'My build configuration'
.buildConfiguration = toolchain.addNewBuildConfiguration('My Build Configuration');
Set the properties of the
BuildConfiguration
object, as needed for your hardware board. Set the compiler defines to'ARM_PROJECT'
by setting theDefines
property.buildConfiguration.Defines = 'ARM_PROJECT';
Similarly, set the compiler include paths by setting the
IncludePaths
property to'$(ARM_CORTEX_A_ROOT_DIR)/include'
.Register the
$(ARM_CORTEX_A_ROOT_DIR)
token.dep.Tokens{1} = struct('Name', 'ARM_CORTEX_A_ROOT_DIR', 'Value', 'codertarget.arm_cortex_a.internal.getSpPkgRootDir');
Note
$(ARM_CORTEX_A_ROOT_DIR)
is a token that stands for the root folder of the target for ARM Cortex-A hardware board and will be resolved by the code generation software.Create a
Loader
object,loader
, and add it to theDeployer
object by callingaddNewLoader
with the name of the loader, for example,'My Loader'
.loader = dep.addNewLoader('My Loader');
The loader downloads the generated code to the hardware board.
Specify the load command that downloads and executes generated code on hardware board by setting the
LoadCommand
property of theLoader
object to, for example, the MATLAB function'codertarget.arm_cortex_a.internal.loadAndRun'
.loader.LoadCommand = 'matlab:codertarget.arm_cortex_a.internal.loadAndRun';
Set the other properties of the
Loader
object as needed.Note
The prefix
matlab:
signifies a MATLAB function. If the prefixmatlab:
is omitted, the command is a system command.The reference target load command may have additional operational dependencies based on the Linux version on your hardware board. For example, some Linux versions require the user have root-level privileges (sudo) to execute generated code. In these cases, you can develop and register your own load command using the reference target load command as a starting point.
Save the target description information to its framework.
saveTarget(tgt);
Set MATLAB preferences for the hardware.
If you selected to use the loader capability for the reference target for ARM Cortex-A, you might need to set some additional MATLAB preferences. For example, you can set the load command as follows.
loader.LoadCommand = 'matlab:codertarget.arm_cortex_a.internal.loadAndRun';
The specified load command
'codertarget.arm_cortex_a.internal.loadAndRun'
works only if your hardware runs the Linux® operating system and supports the SSH protocol. In addition, the load command'codertarget.arm_cortex_a.internal.loadAndRun'
requires the following information to be specified for your hardware:IP address
User name
Password
Default build folder
To set this information as specified MATLAB preferences:
Select the name of the MATLAB preferences as follows:
Hardware_Connectivity_Installer_<hardware name-specific suffix>
Here, <hardware name-specific suffix> corresponds to the name of the hardware that is supported by your new target and that uses this loader function. Any space character in the name must be replaced by an underscore character.
Call
setpref
to set the IP address, user name, password, and default build folder in the MATLAB preferences according to the characteristics of your hardware.setpref('Hardware_Connectivity_Installer_My_ARM_Cortex_A_Board', 'DefaultIpAddress', '192.168.7.2'); setpref('Hardware_Connectivity_Installer_My_ARM_Cortex_A_Board', 'DefaultUserName', 'root'); setpref('Hardware_Connectivity_Installer_My_ARM_Cortex_A_Board', 'DefaultPasswordPref','root'); setpref('Hardware_Connectivity_Installer_My_ARM_Cortex_A_Board', 'DefaultBuildDirPref','/tmp');
(Optional) If you are using QEMU for the Embedded Coder® Support Package for ARM Cortex-A Processors, call
setpref
to set the SSH port.setpref('Hardware_Connectivity_Installer_My_ARM_Cortex_A_Board', 'DefaultsshportPref',getpref('Hardware_Connectivity_Installer_ARM_Cortex_A_QEMU', 'DefaultsshportPref'));
Test that the application deployment works correctly.
testTarget(tgt,'deployer');
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 eitherFAILED
or isINCOMPLETE
, a link to the test diagnostic logs is shown below the test summary.
Confirm the Operation of the Application Deployment 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 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 Configuration Parameters dialog box, select Code Generation and set System target file to
ert.tlc
.In the Build process pane, under Toolchain Settings, set Toolchain to your toolchain.
Open the Simulink Library Browser, and from the Sources library, add a Constant block to your model.
From the Sinks library, add an Outport block to your model. Connect the Constant and the Outport block.
In the Hardware tab, click Build, Deploy & Start > Build. After the build completes, a
test.elf
file is added to your current folder.