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
Deployerobject,dep, and add it to theTargetobject,tgt, by callingaddNewDeployerwith the name of the deployer, for example,'My New Deployer'.dep = addNewDeployer(tgt,'My New Deployer');Do not delete the
Deployerobject 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, the0indicates that the deployer is not used for the hardware board'My ARM Cortex A Board'.Map the
Deployerobject, to theHardwareobject.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
1indicates that the deployer'My New Deployer'is used for the hardware board'My ARM Cortex A Board'.Create a
Toolchainobject,toolchain, and add it to theDeployerobject by callingaddNewToolChainwith the name of the toolchain, for example,'Linaro Toolchain v4.8'.toolchain = dep.addNewToolchain('Linaro Toolchain v4.8');Create a
BuildConfigurationobject,buildConfiguration, and add it to theToolchainobject by callingaddNewBuildConfigurationwith the name of the build configuration, for example,'My build configuration'.buildConfiguration = toolchain.addNewBuildConfiguration('My Build Configuration');Set the properties of the
BuildConfigurationobject, as needed for your hardware board. Set the compiler defines to'ARM_PROJECT'by setting theDefinesproperty.buildConfiguration.Defines = 'ARM_PROJECT';Similarly, set the compiler include paths by setting the
IncludePathsproperty 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
Loaderobject,loader, and add it to theDeployerobject by callingaddNewLoaderwith 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
LoadCommandproperty of theLoaderobject 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
Loaderobject 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 settings 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 settings. 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 settings:
Select the name of the MATLAB settings 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
setprefto set the IP address, user name, password, and default build folder in the MATLAB settings 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
setprefto 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 eitherFAILEDor 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.elffile is added to your current folder.