Highlights from
Simulink Support Package for LEGO MINDSTORMS NXT hardware (R2012a)

image thumbnail

Simulink Support Package for LEGO MINDSTORMS NXT hardware (R2012a)

by

 

23 Feb 2012 (Updated )

Simulink block library for creating models that run directly on yourLEGO MINDSTORMS NXT robot

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

lego()
% NOTE: DO NOT REMOVE THIS LINE XMAKEFILE_TOOL_CHAIN_CONFIGURATION
function toolChainConfiguration = lego()
%LEGO Defines a tool chain configuration

% Copyright 2011-2013 The MathWorks, Inc.

hSetup     = realtime.setup.PackageInfo;
spPkg      = hSetup.getSpPkgInfo('LEGO MINDSTORMS NXT');
nxtOsekDir = hSetup.getTpPkgRootDir('NXT OSEK', spPkg);
gnuGccDir  = hSetup.getTpPkgRootDir('GNU Tools for ARM Embedded Processors', spPkg);

% General
toolChainConfiguration.Configuration = 'Lego';
toolChainConfiguration.Version = '2.0';
toolChainConfiguration.Description = 'Lego nxtOSEK tool chain';
toolChainConfiguration.Operational = true;
toolChainConfiguration.Decorator = 'realtime.headerFilesOverrideDecorator';

% Make
toolChainConfiguration.MakePath = @(src) fullfile(matlabroot, 'bin', computer('arch'), 'gmake.exe'); 
toolChainConfiguration.MakeFlags = '-f "[|||MW_XMK_GENERATED_FILE_NAME[R]|||]"';
toolChainConfiguration.MakeInclude = '';

% Compiler
toolChainConfiguration.CompilerPath = @(src) fullfile(gnuGccDir, 'bin', 'arm-none-eabi-gcc'); 
toolChainConfiguration.CompilerFlags = @(src) ['-c -ffreestanding -fsigned-char -mcpu=arm7tdmi -Os -Winline -Wall -Werror-implicit-function-declaration --param max-inline-insns-single=1000 -mthumb -mthumb-interwork -ffunction-sections -fdata-sections' ...
    ' -nostdinc' ...
    ' -iquote'  adjustPath(fullfile(nxtOsekDir, 'lejos_nxj', 'src', 'nxtvm', 'javavm')) ...
    ' -iquote'  adjustPath(fullfile(nxtOsekDir, 'lejos_nxj', 'src', 'nxtvm', 'platform', 'nxt')) ...
    ' -iquote'  adjustPath(fullfile(nxtOsekDir, 'ecrobot', 'bios')) ...
    ' -iquote'  adjustPath(fullfile(nxtOsekDir, 'ecrobot', 'c')) ...
    ' -iquote'  adjustPath(fullfile(nxtOsekDir, 'c++')) ...
    ' -I. -I'   adjustPath(fullfile(nxtOsekDir, 'toppers_osek', 'kernel')) ...
    ' -I'       adjustPath(fullfile(nxtOsekDir, 'toppers_osek', 'include')) ...
    ' -I'       adjustPath(fullfile(nxtOsekDir, 'toppers_osek', 'config', 'at91sam7s-gnu')) ...
    ' -I'       adjustPath(fullfile(nxtOsekDir, 'toppers_osek', 'config', 'at91sam7s-gnu', 'lego_nxt')) ...
    ' -I'       adjustPath(fullfile(nxtOsekDir, 'toppers_osek', 'syslib', 'at91sam7s-gnu', 'lego_nxt')) ...
    ' -I'       adjustPath(fullfile(gnuGccDir, 'lib', 'gcc', 'arm-none-eabi', '4.6.2', 'include')) ...
    ' -I'       adjustPath(fullfile(gnuGccDir, 'lib', 'gcc', 'arm-none-eabi', '4.6.2', 'include-fixed')) ...
    ' -I'       adjustPath(fullfile(gnuGccDir, 'arm-none-eabi', 'include')) ...
    ' -DLEGO' ...
    ' -std=gnu99'];

toolChainConfiguration.SourceExtensions = '.c,.s,.S';
toolChainConfiguration.HeaderExtensions = '.h';
toolChainConfiguration.ObjectExtension = '.o';

% Linker
toolChainConfiguration.LinkerPath = @(src) fullfile(gnuGccDir, 'bin', 'arm-none-eabi-g++'); 
toolChainConfiguration.LinkerFlags = @(src) ['-nostartfiles -o $(TARGET) -T ./mine.ld -mthumb -mthumb-interwork -Wl,--allow-multiple-definition  -Wl,--gc-sections' ...
    ' -L' adjustPath(fullfile(nxtOsekDir, 'ecrobot')) ...
    ' -L' adjustPath(fullfile(nxtOsekDir, 'c++')) ...
    ' -Wl,--start-group -lgcc -lc -lc -lm -lnosys -Wl,--end-group' ...
    ' -llejososek -lecrobot'];

toolChainConfiguration.LibraryExtensions = '.lib,.a';
toolChainConfiguration.TargetExtension = '.elf';
toolChainConfiguration.TargetNamePrefix = '';
toolChainConfiguration.TargetNamePostfix = '';

% Archiver
toolChainConfiguration.ArchiverPath = @(src) fullfile(gnuGccDir, 'bin', 'arm-none-eabi-ar');
toolChainConfiguration.ArchiverFlags = 'crs';
toolChainConfiguration.ArchiveExtension = '.a';
toolChainConfiguration.ArchiveNamePrefix = 'lib';
toolChainConfiguration.ArchiveNamePostfix = '';

% Pre-build
toolChainConfiguration.PrebuildEnable = false;

% Post-build
toolChainConfiguration.PostbuildEnable = true;
toolChainConfiguration.PostbuildToolPath = @(src) fullfile(gnuGccDir, 'bin', 'arm-none-eabi-objcopy');
toolChainConfiguration.PostbuildFlags = '-O binary $(OUTPUT_PATH)$(TARGET_FILE) $(OUTPUT_PATH)$(TARGET_NAME_PREFIX)$(MODEL_NAME)$(TARGET_NAME_POSTFIX).rxe';

% Directories
toolChainConfiguration.DerivedPath = '[|||MW_XMK_SOURCE_PATH_REF|||]';
toolChainConfiguration.OutputPath = '';

% Custom
toolChainConfiguration.Custom1 = '';
toolChainConfiguration.Custom2 = '';
toolChainConfiguration.Custom3 = '';
toolChainConfiguration.Custom4 = '';
toolChainConfiguration.Custom5 = '';
end

% Helper functions
function value = adjustPath(winPath)
    value = doubleQuotes(strrep(winPath, '\', '/'));
end

function pathStr = doubleQuotes(pathStr)
    pathStr = ['"', pathStr, '"'];
end

%[EOF]

Contact us