Main Content

Build Generated Code Remotely

To build generated code on a remote computer, you can use this workflow:

  1. Using the Target Framework define:

    • A CMake toolchain for the remote computer.

    • A Secure Shell (SSH) connection with the remote computer for secure file transfers and communication.

  2. Generate code and CMakeLists.txt files locally and build the code remotely with a single command. For example, by using slbuild (Ctrl+B).

The workflow assumes that:

  • CMake and a working toolchain are installed on the remote computer, which does not require MATLAB®.

  • Using SSH, you can connect your MATLAB development computer to the remote build computer.

Build Generated Code on Raspberry Pi Computer

This example assumes that a Raspberry Pi® computer is available in a local network, for example, through the local IP address

Create a working folder for this example.

mkdir remote_build
cd remote_build

Create a target.Board object that provides MATLAB with a description of the Raspberry Pi computer.

boardName = 'Remote Raspberry Pi Board';
board = target.create('Board', 'Name', boardName);

To support code generation, associate the board with a target.Processor object that contains a language implementation. The Raspberry Pi computer uses an ARM® processor with an ARM language implementation.

processor = target.create('Processor', 'Name', 'Pi ARM Processor');
processor.LanguageImplementations = target.get('LanguageImplementation', ...
'ARM Compatible-ARM Cortex');
board.Processors = processor;

To create a CMake toolchain definition for remote building, use a target.Toolchain object. GNU® Make, CMake and GCC are installed on the Raspberry Pi computer.

tc = target.create('Toolchain', ...
                   'Name', 'Remote Raspberry Pi CMake Toolchain', ...
                   'MakeToolType', 'CMake');

Specify the use of a remote toolchain through an SSH connection.

tc.RunsOn = target.ExecutionContext.SSH();

Associate the toolchain definition with the board.

tc.SupportedHardware = target.create('HardwareComponentSupport', ...
 'Component', board);

To register the objects in MATLAB, add the objects to an internal database by using the target.add function.

target.add([board tc]);

For the MATLAB development computer, show the available connections.;

Create an SSH connection to the Raspberry Pi computer., 'SSH', IP='', Username='pi');

In the Enter password dialog box that opens, enter the required password and then click OK.

Verify that the SSH connection is available.;

Open your model and specify the board.

model = 'myExample';
set_param(model, 'HardwareBoard', boardName);

The software sets the Toolchain configuration parameter to the toolchain associated with HardwareBoard, that is, 'Remote Raspberry Pi CMake Toolchain'. You can now build the model.


On the MATLAB development computer, the build process creates production code in the code generation folder myExample_grt_rtw.

On the Raspberry Pi computer, the build process produces the executable file and build artifacts in a remote_build folder. To view the folder contents, open a command-line SSH session on the Raspberry Pi computer. Then, use these commands.

pi@my-computer-rpi:~ $ pwd

pi@my-computer-rpi:~ $ ls /home/pi/remote_build/remote_build/myExample_grt_rtw/build
CMakeCache.txt cmake_install.cmake Makefile myExample.cmake
CMakeFiles install_manifest.txt myExample

To close the SSH connection, in the MATLAB Command Window, run:


See Also

| |

Related Topics

External Websites