Main Content

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.

  1. Create a Deployer object, dep, and add it to the Target object, tgt, by calling addNewDeployer 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.

  2. 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, the 0 indicates that the deployer is not used for the hardware board 'My ARM Cortex A Board'.

  3. Map the Deployer object, to the Hardware object.

    map(tgt,hw,dep);
  4. 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'.

  5. Create a Toolchain object, toolchain, and add it to the Deployer object by calling addNewToolChain with the name of the toolchain, for example, 'Linaro Toolchain v4.8'.

    toolchain = dep.addNewToolchain('Linaro Toolchain v4.8');
  6. Create a BuildConfiguration object, buildConfiguration, and add it to the Toolchain object by calling addNewBuildConfiguration with the name of the build configuration, for example, 'My build configuration'.

    buildConfiguration = toolchain.addNewBuildConfiguration('My Build Configuration');
  7. Set the properties of the BuildConfiguration object, as needed for your hardware board. Set the compiler defines to 'ARM_PROJECT' by setting the Defines property.

    buildConfiguration.Defines = 'ARM_PROJECT';
  8. Similarly, set the compiler include paths by setting the IncludePaths property to '$(ARM_CORTEX_A_ROOT_DIR)/include'.

  9. 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.

  10. Create a Loader object, loader, and add it to the Deployer object by calling addNewLoader 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.

  11. Specify the load command that downloads and executes generated code on hardware board by setting the LoadCommand property of the Loader 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 prefix matlab: 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.

  12. Save the target description information to its framework.

    saveTarget(tgt);
  13. 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:

    1. 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.

    2. 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'); 
      
    3. (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'));
  14. 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 either FAILED or is INCOMPLETE, a link to the test diagnostic logs is shown below the test summary.

Confirm the Operation of the Application Deployment Feature

  1. Create a blank Simulink model named test.

  2. 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'.

  3. In the Hardware tab, click Hardware Settings.

  4. In the Configuration Parameters dialog box, select Solver.

  5. From the Type list, select Fixed-step. From the Solver list, select auto.

  6. In the Configuration Parameters dialog box, select Code Generation and set System target file to ert.tlc.

  7. In the Build process pane, under Toolchain Settings, set Toolchain to your toolchain.

  8. Open the Simulink Library Browser, and from the Sources library, add a Constant block to your model.

  9. From the Sinks library, add an Outport block to your model. Connect the Constant and the Outport block.

  10. In the Hardware tab, click Build, Deploy & Start > Build. After the build completes, a test.elf file is added to your current folder.