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.
To perform this action at the MATLAB command line, use the coder.hardware
function.
The Hardware tab and the coder.hardware
function support 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:
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);
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.
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. 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;
Add the
target.Processor
object to an internal database and specify persistence of target data over MATLAB sessions.If you subsequently modify the object in the MATLAB workspace and then want to update the object in the internal database, you can use theobjectsAdded = target.add(myProc, 'UserInstall', true);
target.update
function.You can remove the object from the internal database.
To remove multiple persistent objects from the internal database, use thetarget.remove(objectsAdded);
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);
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, 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;
Add the
target.Processor
object to an internal database.objectsAdded = target.add(myProc);
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');
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 nameId
— 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 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.export(myProc, 'FileName', 'exportMyProcFunction')
target.export
function creates exportMyProcFunction.m
in the current working
folder.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{:});
objectsAdded = exportMyProcFunction;
target.Processor
object,
MyManufacturer-MyProcessor
, and adds it to an internal database. 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 atarget.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.target.add(aliasProcessorObj);
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');
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)