Activate the Application Deployment Feature

To execute code generated from a Simulink® model, you must compile, link, and download the code to the supported 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®-R hardware board, provides support for the GNU Tools for ARM Embedded Processors toolchain. If this toolchain is suitable for compiling and linking code for your new target and the hardware board that it supports, you do not need to integrate another toolchain. Instead, you can reuse the GNU Tools for ARM Embedded Processors toolchain. If you need to support different toolchains, integrate new toolchains by following instructions described in Custom Toolchain Registration (MATLAB Coder).

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 can 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, 'RM46 TI Deployer'.

    deployerName = 'RM46 TI Deployer';
    deployerObj = addNewDeployer(tgt, deployerName);

    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);
                          TIRM46Lx2 Launchpad      
    Display Name          TIRM46Lx2 Launchpad      
    RM46 TI Deployer               0         

    The deployer 'RM46 TI Deployer' is added to the target. However, the 0 indicates that the deployer is not used for the hardware board 'TIRM46Lx2 Launchpad'.

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

    map(tgt,hw,deployerObj);
  4. Confirm that the deployer is used for the hardware board 'TIRM46Lx2 Launchpad'.

    show(tgt);
                          TIRM46Lx2 Launchpad      
    Display Name          TIRM46Lx2 Launchpad      
    RM46 TI Deployer               1         

    The 1 indicates that the deployer 'RM46 TI Deployer' is used for the hardware board 'TIRM46Lx2 Launchpad'.

  5. Create a Toolchain object, toolchain, and add it to the Deployer object by calling addNewToolChain with the name of the toolchain, for example, 'TI ARM Code Generation Tools v5.2.x | gmake'.

    toolchainName = 'TI ARM Code Generation Tools v5.2.x | gmake';
    toolchainObj = addNewToolchain(deployerObj,toolchainName);
  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, 'Build Configuration RM46'.

    buildConfigurationObj = addNewBuildConfiguration(toolchainObj,'Build Configuration RM46');
  7. Set the LinkerFlags, AssemblerFlags, and CompilerFlags properties of the BuildConfiguration object as needed for your hardware board.

    compflags = [...
        '-mv7R4 ', ... processor architecture
        '--code_state=32 ', ...arm compilation mode (32bit)
        '--float_support=VFPv3D16 ', ... vector floating-point (VFP) coprocessor instructions
        '--abi=eabi ', ... use ELF object format and the DWARF debug format (EABI)
        '-me ', ... little endian
        '--enum_type=packed ', ... optional optimization
        '--diag_wrap=off ', ... optional diagnostic
        '--display_error_number ',... optional diagnostic
        '--diag_warning=225 ',... make 225 diagnostics into warnings
        ];
    buildConfigurationObj.CompilerFlags = compflags;
    buildConfigurationObj.AssemblerFlags = compflags;
    buildConfigurationObj.LinkerFlags = [...
        '-mv7R4 ', ... processor architecture
        '-me ', ... little endian
        '-m"$(PRODUCT_NAME).map" ', ... linker map file name (this is generated by HALCOGEN. $(PRODUCT_NAME) is a macro that is used in all Mathworks generated makefiles. 
        '--warn_sections ', ... optional diagnostic
        '--reread_libs ', ... resolve back references
        '--diag_wrap=off ', ... optional diagnostic 
        '--display_error_number ', ... optional diagnostic
        '--diag_warning=225 ', ... optional diagnostic
        '--xml_link_info="$(PRODUCT_NAME)_linkInfo.xml" ', ... optional diagnostic: link info xml for debugging
        '--rom_model ', ... optional auto initialize variables at run time
        '--heap_size=0x5000 ', ... heap size: make sure that this matches what is set in HALCOGEN
        '--stack_size=0x5000', ... size size: make sure that this matches what is set in HALCOGEN
        ];

    Note

    • The compiler, linker, and assembler flags shown above are toolchain specific. You need to modify these flags for your specific toolchain configuration.

    • $(PRODUCT_NAME) is a token automatically provided and used in all MATLAB and Simulink generated makefiles.

  8. Create a Loader object, loader, and add it to the Deployer object, by calling addNewLoader with the name of the loader, for example, 'TIRM46 loader'.

    loader = addNewLoader(deployerObj, 'TIRM46 loader');
  9. Specify the load command that downloads and executes generated code on hardware board by setting the LoadCommand property of the Loader object. For example, the target for TI’s RM46 based on the ARM Cortex-R processor uses the MATLAB function 'matlabshared.target.tirm46.loadAndRun'.

    loader.LoadCommand = 'matlab:matlabshared.target.tirm46.loadAndRun';

    Set the other properties of the Loader object as needed using the LoadCommandArguments property.

    The 'matlabshared.target.tirm46.loadAndRun' function can be used as a reference to develop and register your own load command.

    Note

    • A target load command needs to be designed to operate with the selected hardware board or family.

    • The prefix matlab: signifies a MATLAB function. If you omit the prefix matlab:, the command is a system command.

  10. Define a MATLAB function to invoke after the code for the Simulink model is generated.

    deployerObj.AfterCodeGenFcn = 'matlabshared.target.tirm46.onAfterCodeGenHook_freeRunning';

    The 'matlabshared.target.tirm46.onAfterCodeGenHook_freeRunning' function uses the predefined HALCoGen project files and generates specific source files for the TIRM46L852 device configuration. You can use this function as a reference to develop and register your own command.

  11. Save the target description information to its framework.

    saveTarget(tgt);
  12. Copy the functions required by this feature from the examples folder to the target root folder.

    copyfile(fullfile(codertarget.arm_cortex_r.internal.getSpPkgRootDir(),...
         'arm_cortex_r_examples', 'deployer'),...
         fullfile(tgt.Folder),'f');

    Note

    You can use these functions as examples for creating your own feature specific files.

  13. 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. In your model, select Simulation > Model Configuration Parameters.

  3. In the Configuration Parameters dialog box, select Hardware Implementation.

  4. From the Hardware board list, select your hardware board, TIRM46Lx2 Launchpad, and click OK.

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

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

  7. Click Build Model. After the build completes, a test.elf file is added to your current folder.