Main Content

Register New Hardware Devices

On the Hardware tab of the MATLAB® Coder™ app, you can specify parameters that describe target hardware and compiler properties for MATLAB software, which enables you to:

  • Generate optimized code for production or test hardware.

  • Directly test or deploy generated code on target hardware.

The Hardware tab 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

To register a new hardware device:

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

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

  2. Create a target.LanguageImplementation object for language implementation details.

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

  3. 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;

  4. Associate the language implementation with the hardware device.

    myProc.LanguageImplementations = myLanguageImplementation;
    

  5. Save the target.Processor object to MATLAB memory.

    target.add(myProc);

On the Hardware tab, you see the new device.

Specify Hardware Implementation That Persists Over MATLAB Sessions

By default, when you add a target feature object to MATLAB memory, the target data is available only for the current MATLAB session. You can specify target data persistence over MATLAB sessions.

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

    myProc = target.create('Processor', ...
                           'Name', 'MyProcessor', ...
                           'Manufacturer', 'MyManufacturer');
    
    existingImplementation = target.get('LanguageImplementation', ... 
                                        'ARM Compatible-ARM Cortex'); 
    myProc.LanguageImplementations = existingImplementation;

  2. Save the target.Processor object to MATLAB memory and specify persistence of target data over MATLAB sessions.

    target.add(myProc, 'UserInstall', true);

  3. You can remove the object from MATLAB memory.

    processorToRemove = target.get('Processor',...
                                   'MyManufacturer-MyProcessor');
    target.remove(processorToRemove );

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.

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

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

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

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

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

    myCopiedImplementation.Endianess = target.Endianess.Big;

  4. Associate the language implementation with the hardware device.

    myProc.LanguageImplementations = myCopiedImplementation;

  5. Save the target.Processor object to MATLAB memory.

    target.add(myProc);

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.

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

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

  2. Retrieve the existing implementation by using the identifier for the device vendor and type, for example, 'ARM Compatible-ARM Cortex'.

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

  3. Associate the language implementation with the hardware device.

    myProc.LanguageImplementations = existingImplementation;

  4. Save the target.Processor object to MATLAB memory.

    target.add(myProc);

Validate Hardware Device Data

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

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 validate the created object, run myProcessor.IsValid or myProcessor.validate().
myProcessor.IsValid
ans =
  logical
  0
myProcessor.validate()
Error using target.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.
myProcessor.IsValid
ans =
  logical
  1
The validity of the object is established.

Note

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

Export Hardware Device Data

You can share hardware device data across computers and users.

Specify a hardware device.

myProc = target.create('Processor', ...
                    'Name', 'MyProcessor', ...
                    'Manufacturer', 'MyManufacturer');
existingImplementation = target.get('LanguageImplementation', ...
                                 'ARM Compatible-ARM Cortex');
myProc.LanguageImplementations = existingImplementation;
Run the target.export function.
target.export(myProc, 'FileName', 'exportMyProcFunction')
The function creates exportMyProcFunction.m in the current working folder.
function processor = 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
    target.add(processor, varargin{:});
Use the generated function to share hardware device data across computers and users. When you run exportMyProcFunction, it recreates the myProc object and adds the object to MATLAB memory.

Create Alternative Identifier for Target Feature Object

To create alternative identifiers for target feature 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.

  1. Retrieve the target.Processor object.

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

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

    aliasProcessorObj = target.create('Alias');

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

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

  4. Save the target.Alias object to MATLAB memory.

    target.add(aliasProcessorObj);
  5. To retrieve the original target.Processor object, run:

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

Upgrade Data Definitions for Hardware Devices

To upgrade existing hardware device definitions that are specified through rtwTargetInfo.m files, 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, run:

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, run:

registerUpgradedTargets()

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

registerUpgradedTargets('UserInstall', true)

See Also

|