Main Content

Register New Hardware Devices

On the Hardware Implementation pane, you can specify parameters that describe target hardware and compiler properties for MATLAB® software, which enables you to:

  • Observe target hardware during model simulations.

  • Generate optimized code for production or test hardware.

  • Directly test or deploy generated code on target hardware.

The Hardware Implementation pane supports a range of target hardware. To extend the range, register new hardware devices by using the target.Processor and target.LanguageImplementation classes.

Specify Hardware Implementation for New Device

This example shows how to register a new hardware device.

Create a target.Processor object for the new hardware device.

myProc = target.create("Processor",Name="MyProcessor", ...
                        Manufacturer="MyManufacturer");

Create a target.LanguageImplementation object for language implementation details.

myLanguageImplementation = target.create("LanguageImplementation", ...
                                          Name="MyProcessorImplementation");

Specify language implementation details.

myLanguageImplementation.Endianess = target.Endianess.Little;

myLanguageImplementation.AtomicIntegerSize = 64;
myLanguageImplementation.AtomicFloatSize = 64;
myLanguageImplementation.WordSize = 64;

myLanguageImplementation.DataTypes.Char.Size = 8;
myLanguageImplementation.DataTypes.Short.Size = 16;
myLanguageImplementation.DataTypes.Int.Size = 32;
myLanguageImplementation.DataTypes.Long.Size = 64;
myLanguageImplementation.DataTypes.LongLong.IsSupported = true;
myLanguageImplementation.DataTypes.LongLong.Size = 64;
myLanguageImplementation.DataTypes.Float.Size = 32;
myLanguageImplementation.DataTypes.Double.Size = 64;

myLanguageImplementation.DataTypes.Pointer.Size = 32;

myLanguageImplementation.DataTypes.SizeT.Size = 64;
myLanguageImplementation.DataTypes.PtrDiffT.Size = 64;

Associate the language implementation with the hardware device.

myProc.LanguageImplementations = myLanguageImplementation;

Add the target.Processor object to an internal database.

objectsAdded = target.add(myProc);
"target.add" summary:

    Objects added to internal database for current MATLAB session:
        target.LanguageImplementation    "MyProcessorImplementation"
        target.Processor                 "MyManufacturer-MyProcessor"
  • If you are using the MATLAB® Coder™: On the Hardware tab, you see the new device. Alternatively, you can now create a coder.Hardware object for this device by using the coder.hardware function.

  • If you are using the Simulink® Coder™: On the Hardware Implementation pane, you can now set Device vendor and Device type to MyManufacturer and MyProcessor respectively.

To remove the objects from the internal database, enter:

target.remove(objectsAdded)
"target.remove" summary:

    Objects removed from internal database:
        target.LanguageImplementation    "MyProcessorImplementation"
        target.Processor                 "MyManufacturer-MyProcessor"

Specify Hardware Implementation That Persists Over MATLAB® Sessions

By default, when you add the target object to the internal database, the target data is available only for the current MATLAB session. This examples shows how to specify target data persistence over MATLAB sessions.

Create a target.Processor object for a new hardware device and specify the language implementation for the process as the existing implementation for ARM Compatible-ARM Cortex.

myProc = target.create("Processor",Name="MyProcessor", ...
                        Manufacturer="MyManufacturer");

existingImplementation = target.get("LanguageImplementation", ...
                                "ARM Compatible-ARM Cortex"); 

myProc.LanguageImplementations = existingImplementation;

Add the created target.Processor object to an internal database, and specify UserInstall as true to allow persistence of target data over MATLAB sessions.

objectsAdded = target.add(myProc,UserInstall=true);
"target.add" summary:

    Objects added to internal database, which will persist across MATLAB sessions:
        target.Processor                 "MyManufacturer-MyProcessor"
    Objects not added because they already exist:
        target.LanguageImplementation    "ARM Compatible-ARM Cortex"

If you subsequently modify the object in the MATLAB workspace and then want to update the object in the internal database, you can use the target.update function.

To remove the objects from the internal database, enter:

target.remove(objectsAdded)
"target.remove" summary:

    Objects removed from internal database:
        target.Processor    "MyManufacturer-MyProcessor"

To remove multiple persistent objects from the internal database, use the target.clear function.

Create Hardware Implementation by Modifying Existing Implementation

If an existing hardware implementation contains most of the values that you want in a new hardware implementation, you can quickly create the new implementation by creating and modifying a copy of the existing implementation.

Create a target.Processor object for the new hardware device.

myProc = target.create("Processor",Name="MyProcessor", ...
                        Manufacturer="MyManufacturer");

Create a target.LanguageImplementation object that copies an existing language implementation.

myCopiedImplementation = target.create("LanguageImplementation", ...
                                      Name="MyCopiedImplementation", ...
                                      Copy="Atmel-AVR");

Specify the required language implementation details. For example, byte ordering.

myCopiedImplementation.Endianess = target.Endianess.Big;

Associate the language implementation with the hardware device.

myProc.LanguageImplementations = myCopiedImplementation;

Add the target.Processor object to an internal database.

objectsAdded = target.add(myProc);
"target.add" summary:

    Objects added to internal database for current MATLAB session:
        target.LanguageImplementation    "MyCopiedImplementation"
        target.Processor                 "MyManufacturer-MyProcessor"

To remove the objects from the internal database, enter:

target.remove(objectsAdded)
"target.remove" summary:

    Objects removed from internal database:
        target.LanguageImplementation    "MyCopiedImplementation"
        target.Processor                 "MyManufacturer-MyProcessor"

Create Hardware Implementation by Reusing Existing Implementation

If your hardware device requires the same hardware implementation as an existing implementation, you can reuse the existing implementation.

Create a target.Processor object for the new hardware device.

myProc = target.create( "Processor",Name="MyProcessor", ...
                        Manufacturer="MyManufacturer");

Retrieve the existing implementation by using the identifier for the device vendor and type.

existingImplementation = target.get("LanguageImplementation", ...
                                  "ARM Compatible-ARM Cortex");

Associate the language implementation with the hardware device.

myProc.LanguageImplementations = existingImplementation;

Add the target.Processor object to an internal database.

objectsAdded = target.add(myProc);
"target.add" summary:

    Objects added to internal database for current MATLAB session:
        target.Processor                 "MyManufacturer-MyProcessor"
    Objects not added because they already exist:
        target.LanguageImplementation    "ARM Compatible-ARM Cortex"

To remove the objects from the internal database, enter:

target.remove(objectsAdded);
"target.remove" summary:

    Objects removed from internal database:
        target.Processor    "MyManufacturer-MyProcessor"

Validate Hardware Device Data

To validate the data integrity of target objects, use the IsValid property or the validate method of the target.Object base class.

Consider an example where you create a target.Processor object and associate an existing language implementation with the object.

myProcessor = target.create("Processor");
myProcessor.LanguageImplementations = target.get("LanguageImplementation", ...
                                              "ARM Compatible-ARM Cortex");

To see that the newly created object is not valid, enter myProcessor.IsValid.

myProcessor.IsValid
ans = logical
   0

If you try to validate the object with the method myProcessor.validate(), you get an error.

myProcessor.validate()
Error using target.internal.Processor/validate
Target data validation failed.
 * Undefined property "Name" in "Processor" object.
 * Undefined identifier in "Processor" object.

The validation fails because these target.Processor properties are not specified:

  • Name — Processor name

  • Id — Object identifier

You can specify a processor name, which also specifies the object identifier.

myProcessor.Name = "MyProcessor";

Check the validity of myProcessor again to see that the validity of the object is established.

myProcessor.IsValid
ans = logical
   1

myProcessor.validate()

Note: When you use the target.add function to register a target object, the software also checks the validity of the object.

Export Hardware Device Data

You can share previously created hardware device data across computers and users.

For this example, specify a hardware device and add it to an internal database.

myProc = target.create("Processor",Name="MyProcessor", ...
                        Manufacturer="MyManufacturer");

existingImplementation = target.get("LanguageImplementation", ...
                        "ARM Compatible-ARM Cortex");

myProc.LanguageImplementations = existingImplementation;
objectsAdded = target.add(myProc);
"target.add" summary:

    Objects added to internal database for current MATLAB session:
        target.Processor                 "MyManufacturer-MyProcessor"
    Objects not added because they already exist:
        target.LanguageImplementation    "ARM Compatible-ARM Cortex"

To create a function for sharing the hardware device data, enter:

target.export(myProc,"FileName", ...
  "exportMyProcFunction",Overwrite=true)

The target.export function creates exportMyProcFunction.m in the current working folder. Use the type command to see the function.

type("exportMyProcFunction.m")
function registeredObjects = exportMyProcFunction(varargin)
% This function was generated using target data export.

    % Create target.Processor "MyManufacturer-MyProcessor"
    processor = target.create("Processor");
    processor.LanguageImplementations(1) = target.get("LanguageImplementation", "ARM Compatible-ARM Cortex");
    processor.Manufacturer = "MyManufacturer";
    processor.Name = "MyProcessor";

    % Add the target objects to MATLAB memory
    registeredObjects = target.add(processor, varargin{:});
end

Now, you can use the generated function to share the hardware device data in your database across computers and users. For example, on another computer, enter this command:

objectsAdded = exportMyProcFunction;

The generated function recreates the target.Processor object, MyManufacturer-MyProcessor, and adds it to an internal database.

To remove the objects from the internal database, enter:

target.remove(objectsAdded)
"target.remove" summary:

    Objects removed from internal database:
        target.Processor    "MyManufacturer-MyProcessor"

Create Alternative Identifier for Target Object

To create alternative identifiers for target objects, use the target.Alias class.

For example, if a target.Processor object has a long class identifier, you can create a target.Alias object that provides a short identifier for the target.Processor object.

Retrieve the target.Processor object.

proccesorObj = target.get("Processor", ...
  "Analog Devices-ADSP-CM40x (ARM Cortex-M)");

Use the target.create function to create a target.Alias object.

aliasProcessorObj = target.create("Alias");

Use target.Alias object properties to specify the alternative identifier and original target object.

aliasProcessorObj.Name = "myShortName";
aliasProcessorObj.For = proccesorObj;

Add the target.Alias object to an internal database.

objectsAdded = target.add(aliasProcessorObj);
"target.add" summary:

    Objects added to internal database for current MATLAB session:
        target.Alias        "myShortName"
    Objects not added because they already exist:
        target.Processor    "Analog Devices-ADSP-CM40x (ARM Cortex-M)"

To retrieve the original target.Processor object, enter:

target.get("Processor","myShortName");

To remove the objects from the internal database, enter:

target.remove(objectsAdded)
"target.remove" summary:

    Objects removed from internal database:
        target.Alias    "myShortName"

Upgrade Data Definitions for Hardware Devices

To upgrade existing hardware device definitions that are specified through rtwTargetInfo.m file or sl_customization.m file (only applies to Simulink Coder and Embedded Coder), use the target.upgrade function.

rtwTargetInfo.m File

Suppose you have the hardware device definition in an rtwTargetInfo.m file:

function rtwTargetInfo(tr)
    % Add registration function handle to the Target Registry
    tr.registerTargetInfo(@loc_register_hardware);
end
  
function hw = loc_register_hardware
    hw = RTW.HWDeviceRegistry;
    hw.Vendor = 'MyManufacturer';
    hw.Type = 'MyDevice';
    hw.Alias = {};
    hw.Platform = {'Prod', 'Target'};
    hw.setWordSizes([8 16 32 64 64 64 64 64 64 64 64]);
    hw.Endianess = 'Little';
    hw.IntDivRoundTo = 'Zero';
    hw.ShiftRightIntArith = true;
    hw.LargestAtomicInteger = 'Long';
    hw.LargestAtomicFloat = 'Double';
end

To upgrade the data definitions contained in the file, enter:

target.upgrade("rtwTargetInfo","myPathTo/rtwTargetInfo.m");

In the current folder, the function creates this registerUpgradedTargets.m file:

function processor = registerUpgradedTargets(varargin)
% This function was generated using target data export.
  
    % Create target.LanguageImplementation 'MyManufacturer-MyDevice'
    languageimplementation = target.create('LanguageImplementation');
    languageimplementation.AtomicFloatSize = 64;
    languageimplementation.AtomicIntegerSize = 64;
    languageimplementation.DataTypes.Char.Size = 8;
    languageimplementation.DataTypes.Double.Size = 64;
    languageimplementation.DataTypes.Float.Size = 64;
    languageimplementation.DataTypes.Half.IsSupported = false;
    languageimplementation.DataTypes.Half.Size = 16;
    languageimplementation.DataTypes.Int.Size = 32;
    languageimplementation.DataTypes.Long.Size = 64;
    languageimplementation.DataTypes.LongLong.IsSupported = false;
    languageimplementation.DataTypes.LongLong.Size = 64;
    languageimplementation.DataTypes.Pointer.Size = 64;
    languageimplementation.DataTypes.PtrDiffT.Size = 64;
    languageimplementation.DataTypes.Short.Size = 16;
    languageimplementation.DataTypes.SizeT.Size = 64;
    languageimplementation.Name = 'MyManufacturer-MyDevice';
    languageimplementation.WordSize = 64;
  
    % Create target.Processor 'MyManufacturer-MyDevice'
    processor = target.create('Processor');
    processor.LanguageImplementations(1) = languageimplementation;
    processor.Manufacturer = 'MyManufacturer';
    processor.Name = 'MyDevice';
  
    % Add the target objects to MATLAB memory
    target.add(processor, varargin{:});
end

To register the hardware device with MATLAB, enter:

registerUpgradedTargets()

If you want the registration to persist across MATLAB sessions, enter:

registerUpgradedTargets(UserInstall=true)

sl_customization.m File (only applies to Simulink Coder and Embedded Coder)

Suppose you have multiple hardware device definitions in an sl_customization.m file:

function sl_customization(cm)
  % sl_customization function to register a device
  % vendor and type with Simulink.
  % Copy or rename this file to sl_customization.m.
  cm.registerTargetInfo(@loc_register_device);
  cm.registerTargetInfo(@loc_register_device2);
  cm.registerTargetInfo(@loc_createConfig);
     
  cm.registerTargetInfo(@locRegisterTfl);
  cm.CodeCoverageTools.add('DummyCoverageToolForTesting',...
                           'HDummyCovTool',...
                           'A Coverage Tool Vendor');
end
 
function thisDev = loc_register_device
  thisDev = RTW.HWDeviceRegistry;
  thisDev.Vendor = 'MyDevVendor';
  thisDev.Type = 'MyDevType';
  thisDev.Alias = {};
  thisDev.Platform = {'Prod', 'Target'};
  thisDev.setWordSizes([8 16 32 32 32]);
  thisDev.LargestAtomicInteger = 'Char';
  thisDev.LargestAtomicFloat = 'None';
  thisDev.Endianess = 'Unspecified';
  thisDev.IntDivRoundTo = 'Undefined';
  thisDev.ShiftRightIntArith = true;
  thisDev.setEnabled({'IntDivRoundTo'});
end
 
function thisDev = loc_register_device2
  thisDev = RTW.HWDeviceRegistry;
  thisDev.Vendor = 'MyDevVendor';
  thisDev.Type = 'MyDevType2';
  thisDev.Alias = {};
  thisDev.Platform = {'Prod', 'Target'};
  thisDev.setWordSizes([8 16 32 32 32]);
  thisDev.LargestAtomicInteger = 'Char';
  thisDev.LargestAtomicFloat = 'None';
  thisDev.Endianess = 'Unspecified';
  thisDev.IntDivRoundTo = 'Undefined';
  thisDev.ShiftRightIntArith = true;
  thisDev.setEnabled({'IntDivRoundTo'});
end
 
% local function
function config = loc_createConfig
  config = rtw.connectivity.ConfigRegistry;
  config.ConfigName = 'Infineon->C16x, XC16x';
  config.ConfigClass = 'pil_slcust.HostDemoConfig1';
  config.SystemTargetFile = {'custom_target.tlc'};
  config.TemplateMakefile = {'custom_target.tmf'};
  config.TargetHWDeviceType = {'Infineon->C16x, XC16x'};
end
 
function thisTfl = locRegisterTfl
  thisTfl(1) = RTW.TflRegistry;
  thisTfl(1).Name = 'myTFL1';
  thisTfl(1).Description = 'Test';
  thisTfl(1).TableList = {'tfl_table_Sum',...
                          'tfl_table_Product',...
                         }; % Sum includes Add and Subtract
  thisTfl(1).BaseTfl = 'ANSI_C';
  thisTfl(1).TargetHWDeviceType = {'*'};
end

To upgrade the RTW.HWDeviceRegistry data definitions in the file, enter:

target.upgrade("sl_customization","myPathTo/sl_customization.m")

In the current folder, the function creates this registerUpgradedTargets.m file:

function targetObjects = registerUpgradedTargets(varargin)
% This function was generated using target data export.
 
    % Create target.LanguageImplementation 'MyDevVendor-MyDevType'
    languageimplementation = target.create('LanguageImplementation');
    languageimplementation.AtomicIntegerSize = 8;
    languageimplementation.DataTypes.Char.Size = 8;
    languageimplementation.DataTypes.Double.Size = 64;
    languageimplementation.DataTypes.Float.Size = 32;
    languageimplementation.DataTypes.Half.IsSupported = false;
    languageimplementation.DataTypes.Half.Size = 16;
    languageimplementation.DataTypes.Int.Size = 32;
    languageimplementation.DataTypes.Long.Size = 32;
    languageimplementation.DataTypes.LongLong.IsSupported = false;
    languageimplementation.DataTypes.LongLong.Size = 64;
    languageimplementation.DataTypes.Pointer.Size = 32;
    languageimplementation.DataTypes.PtrDiffT.Size = 32;
    languageimplementation.DataTypes.Short.Size = 16;
    languageimplementation.DataTypes.SizeT.Size = 32;
    languageimplementation.Endianess = target.Endianess.Unspecified;
    languageimplementation.Name = 'MyDevVendor-MyDevType';
    languageimplementation.WordSize = 32;
 
    % Create target.Processor 'MyDevVendor-MyDevType'
    processor = target.create('Processor');
    processor.LanguageImplementations(1) = languageimplementation;
    processor.Manufacturer = 'MyDevVendor';
    processor.Name = 'MyDevType';
 
    % Create target.LanguageImplementation 'MyDevVendor-MyDevType2'
    languageimplementation2 = target.create('LanguageImplementation');
    languageimplementation2.AtomicIntegerSize = 8;
    languageimplementation2.DataTypes.Char.Size = 8;
    languageimplementation2.DataTypes.Double.Size = 64;
    languageimplementation2.DataTypes.Float.Size = 32;
    languageimplementation2.DataTypes.Half.IsSupported = false;
    languageimplementation2.DataTypes.Half.Size = 16;
    languageimplementation2.DataTypes.Int.Size = 32;
    languageimplementation2.DataTypes.Long.Size = 32;
    languageimplementation2.DataTypes.LongLong.IsSupported = false;
    languageimplementation2.DataTypes.LongLong.Size = 64;
    languageimplementation2.DataTypes.Pointer.Size = 32;
    languageimplementation2.DataTypes.PtrDiffT.Size = 32;
    languageimplementation2.DataTypes.Short.Size = 16;
    languageimplementation2.DataTypes.SizeT.Size = 32;
    languageimplementation2.Endianess = target.Endianess.Unspecified;
    languageimplementation2.Name = 'MyDevVendor-MyDevType2';
    languageimplementation2.WordSize = 32;
 
    % Create target.Processor 'MyDevVendor-MyDevType2'
    processor2 = target.create('Processor');
    processor2.LanguageImplementations(1) = languageimplementation2;
    processor2.Manufacturer = 'MyDevVendor';
    processor2.Name = 'MyDevType2';
 
    targetObjects = [processor, processor2];
 
    % Add the target objects to MATLAB memory
    target.add(targetObjects, varargin{:});
end

To register the hardware device definitions with MATLAB, enter:

registerUpgradedTargets()

If you want the registration to persist across MATLAB sessions, enter:

registerUpgradedTargets(UserInstall=true)

See Also

| | | |

Related Topics