Build Generated Code Remotely - MATLAB & Simulink (original) (raw)

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 usingslbuild (Ctrl+B).

The workflow assumes that:

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

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 atarget.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 atarget.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 thetarget.add function.

For the MATLAB development computer, show the available connections.

target.connection.show();

Create an SSH connection to the Raspberry Pi computer.

target.connection.open(boardName, 'SSH', IP='192.168.0.10', 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.

target.connection.show();

Open your model and specify the board.

model = 'myExample'; open_system(model); 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 /home/pi

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:

target.connection.close(boardName);

See Also

target.connection.close | target.connection.open | target.connection.show

Topics

External Websites