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.
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;
Save the target.Processor
object to MATLAB
memory.
target.add(myProc);
On the Hardware tab, you see the new device.
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.
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;
Save the target.Processor
object to MATLAB memory and specify persistence of target data over MATLAB sessions.
target.add(myProc, 'UserInstall', true);
You can remove the object from MATLAB memory.
processorToRemove = target.get('Processor',... 'MyManufacturer-MyProcessor'); target.remove(processorToRemove );
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;
Save the target.Processor
object to MATLAB
memory.
target.add(myProc);
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, for example, 'ARM Compatible-ARM Cortex'
.
existingImplementation = target.get('LanguageImplementation', ... 'ARM Compatible-ARM Cortex');
Associate the language implementation with the hardware device.
myProc.LanguageImplementations = existingImplementation;
Save the target.Processor
object to MATLAB memory.
target.add(myProc);
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');
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.
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';
myProcessor
.myProcessor.IsValid
ans = logical 1
Note
When you use the target.add
function to register a target feature object, the software also
checks the validity of the object.
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;
target.export
function.target.export(myProc, 'FileName', 'exportMyProcFunction')
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{:});
exportMyProcFunction
, it recreates the myProc
object
and adds the object to MATLAB memory.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.
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 feature
object.
aliasProcessorObj.Name = 'myShortName';
aliasProcessorObj.For = proccesorObj;
Save the target.Alias
object to MATLAB memory.
target.add(aliasProcessorObj);
To retrieve the original target.Processor
object, run:
target.get('Processor', 'myShortName');
To upgrade existing hardware device definitions that are specified through
rtwTargetInfo.m
files, use the target.upgrade
function.
rtwTargetInfo.m
FileSuppose 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');
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)