image thumbnail
from Simulink Support Package for LEGO MINDSTORMS NXT hardware (R2012b) by MathWorks Simulink Team
Simulink block library for creating models that run directly on your LEGO MINDSTORMS NXT robot

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

% Copyright 2011 The MathWorks, Inc.
% Copyright 1984-2007 The MathWorks, Inc.


hSetup     = hwconnectinstaller.PackageInfo;
spPkg      = hSetup.getSpPkgInfo('LEGO MINDSTORMS NXT');
nxtOsekDir = hSetup.getTpPkgRootDir('NXT OSEK', spPkg);
cygwinDir  = hSetup.getTpPkgRootDir('Cygwin', spPkg);
gnuGccDir  = hSetup.getTpPkgRootDir('GNU ARM Compiler', spPkg);

% General
toolChainConfiguration.Configuration = 'Lego';
toolChainConfiguration.Version = '2.0';
toolChainConfiguration.Description = 'Lego nxtOSEK tool chain';
toolChainConfiguration.Operational = true;
%toolChainConfiguration.InstallPath = 'C:\Program Files (x86)\Microsoft Visual Studio 8\';
toolChainConfiguration.Decorator = 'realtime.headerFilesOverrideDecorator';
% Make
%toolChainConfiguration.MakePath = '"C:/MW_LegoNXT/Cygwin/bin/make"';
toolChainConfiguration.MakePath = @(src) fullfile(cygwinDir, 'bin', 'make.exe'); 
%toolChainConfiguration.MakeFlags = '-f "[|||MW_XMK_GENERATED_FILE_NAME[R]|||]" [|||MW_XMK_ACTIVE_BUILD_ACTION_REF|||]';
toolChainConfiguration.MakeFlags = '-f "[|||MW_XMK_GENERATED_FILE_NAME[R]|||]"';
toolChainConfiguration.MakeInclude = '';
% Compiler
%toolChainConfiguration.CompilerPath = '"/cygdrive/C/MW_LegoNXT/GNU_ARM_Compiler/bin/arm-elf-gcc"';
toolChainConfiguration.CompilerPath = @(src) doubleQuotes(cygwinPathTranslate(fullfile(gnuGccDir, 'bin', 'arm-elf-gcc'))); 
%toolChainConfiguration.CompilerFlags = '-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 -iquote /cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../lejos_nxj/src//nxtvm/platform/nxt -iquote /cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../lejos_nxj/src//nxtvm/javavm -iquote /cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../ecrobot/bios -iquote /cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../ecrobot -iquote /cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../ecrobot/c -iquote /cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../c++ -I. -I/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../toppers_osek/kernel -I/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../toppers_osek/include -I/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../toppers_osek/config/at91sam7s-gnu -I/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../toppers_osek/config/at91sam7s-gnu/lego_nxt -I/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../toppers_osek/sg -I/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../toppers_osek/syslib/at91sam7s-gnu/lego_nxt -std=gnu99';

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 -iquote ' ...
                cygwinPathTranslate(fullfile(nxtOsekDir, 'lejos_nxj', 'src', 'nxtvm', 'platform', 'nxt')) ...
    ' -iquote ' cygwinPathTranslate(fullfile(nxtOsekDir, 'lejos_nxj', 'src', 'nxtvm', 'javavm')) ...
    ' -iquote ' cygwinPathTranslate(fullfile(nxtOsekDir, 'ecrobot', 'bios')) ...
    ' -iquote ' cygwinPathTranslate(fullfile(nxtOsekDir, 'ecrobot')) ...
    ' -iquote ' cygwinPathTranslate(fullfile(nxtOsekDir, 'ecrobot', 'c')) ...
    ' -iquote ' cygwinPathTranslate(fullfile(nxtOsekDir, 'c++')) ...
    ' -I. -I'   cygwinPathTranslate(fullfile(nxtOsekDir, 'toppers_osek', 'kernel')) ...
    ' -I'       cygwinPathTranslate(fullfile(nxtOsekDir, 'toppers_osek', 'include')) ...
    ' -I'       cygwinPathTranslate(fullfile(nxtOsekDir, 'toppers_osek', 'config', 'at91sam7s-gnu')) ...
    ' -I'       cygwinPathTranslate(fullfile(nxtOsekDir, 'toppers_osek', 'config', 'at91sam7s-gnu', 'lego_nxt')) ...
    ' -I'       cygwinPathTranslate(fullfile(nxtOsekDir, 'toppers_osek', 'sg')) ...
    ' -I'       cygwinPathTranslate(fullfile(nxtOsekDir, 'toppers_osek', 'syslib', 'at91sam7s-gnu', 'lego_nxt')) ...
    ' -DLEGO' ...
    ' -std=gnu99'];

toolChainConfiguration.SourceExtensions = '.c,.s,.S';
toolChainConfiguration.HeaderExtensions = '.h';
toolChainConfiguration.ObjectExtension = '.o';
% Linker
%toolChainConfiguration.LinkerPath = '"/cygdrive/C/MW_LegoNXT/GNU_ARM_Compiler/bin/arm-elf-g++"';
toolChainConfiguration.LinkerPath = @(src) doubleQuotes(cygwinPathTranslate(fullfile(gnuGccDir, 'bin', 'arm-elf-g++'))); 
%toolChainConfiguration.LinkerFlags = '-nostartfiles -o $(TARGET) -T ./mine.ld -mthumb -mthumb-interwork -Wl,--allow-multiple-definition  -Wl,--gc-sections -L/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../lejos_nxj/src//nxtvm/platform/nxt -L/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../lejos_nxj/src//nxtvm/javavm -L/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../ecrobot/bios -L/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../ecrobot -L/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../ecrobot/c -L/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../c++ -L/cygdrive/c/MW_LegoNXT/nxtOSEK/ecrobot/../c++ -lm -llejososek -lecrobot';

toolChainConfiguration.LinkerFlags = @(src) ['-nostartfiles -o $(TARGET) -T ./mine.ld -mthumb -mthumb-interwork -Wl,--allow-multiple-definition  -Wl,--gc-sections -L' ...
    cygwinPathTranslate(fullfile(nxtOsekDir, 'lejos_nxj', 'src', 'nxtvm', 'platform', 'nxt')) ...
    ' -L' cygwinPathTranslate(fullfile(nxtOsekDir, 'lejos_nxj', 'src', 'nxtvm', 'javavm')) ...
    ' -L' cygwinPathTranslate(fullfile(nxtOsekDir, 'ecrobot', 'bios')) ...
    ' -L' cygwinPathTranslate(fullfile(nxtOsekDir, 'ecrobot')) ...
    ' -L' cygwinPathTranslate(fullfile(nxtOsekDir, 'ecrobot', 'c')) ...
    ' -L' cygwinPathTranslate(fullfile(nxtOsekDir, 'c++')) ...
    ' -lm -llejososek -lecrobot'];

toolChainConfiguration.LibraryExtensions = '.lib,.a';
toolChainConfiguration.TargetExtension = '.elf';
toolChainConfiguration.TargetNamePrefix = '';
toolChainConfiguration.TargetNamePostfix = '';
% Archiver
toolChainConfiguration.ArchiverPath = @(src) doubleQuotes(cygwinPathTranslate(fullfile(gnuGccDir, 'bin', 'arm-elf-ar'))); 
toolChainConfiguration.ArchiverFlags = 'crs';
toolChainConfiguration.ArchiveExtension = '.a';
toolChainConfiguration.ArchiveNamePrefix = 'lib';
toolChainConfiguration.ArchiveNamePostfix = '';
% Pre-build
toolChainConfiguration.PrebuildEnable = true;
%toolChainConfiguration.PrebuildToolPath = 'C:\MW_LegoNXT\nxtOSEK\toppers_osek\sg\sg';
toolChainConfiguration.PrebuildToolPath = @(src) fullfile(nxtOsekDir, 'toppers_osek', 'sg', 'sg');
%toolChainConfiguration.PrebuildFlags = './mine.oil -os=ECC2 -IC:/MW_LegoNXT/nxtOSEK/toppers_osek/sg/impl_oil -template=C:/MW_LegoNXT/nxtOSEK/toppers_osek/sg/lego_nxt.sgt';

toolChainConfiguration.PrebuildFlags = @(src) ['./mine.oil -os=ECC2 -I' ...
    strrep(fullfile(nxtOsekDir, 'toppers_osek', 'sg', 'impl_oil'), '\', '/') ...
    ' -template=' strrep(fullfile(nxtOsekDir, 'toppers_osek', 'sg', 'lego_nxt.sgt'), '\', '/')];

% Post-build
toolChainConfiguration.PostbuildEnable = true;
%toolChainConfiguration.PostbuildToolPath = '"\cygdrive\C\MW_LegoNXT\GNU_ARM_Compiler\bin\arm-elf-objcopy"';
toolChainConfiguration.PostbuildToolPath = @(src) doubleQuotes(cygwinPathTranslate(fullfile(gnuGccDir,'bin', 'arm-elf-objcopy')));
toolChainConfiguration.PostbuildFlags = '-O binary $(OUTPUT_PATH)$(TARGET_FILE) $(OUTPUT_PATH)$(TARGET_NAME_PREFIX)$(MODEL_NAME)$(TARGET_NAME_POSTFIX).rxe';
% Execute
%toolChainConfiguration.ExecuteDefault = false;
%toolChainConfiguration.ExecuteToolPath = '"/cygdrive/C/MW_LegoNXT/NXT_Tools/NeXTTool.exe"';
%toolChainConfiguration.ExecuteToolPath = @(src) ['"' cygwinPathTranslate(fullfile(legoInstallDir('Lego'), 'NXT_Tools', 'NeXTTool.exe')) '"'];
%toolChainConfiguration.ExecuteFlags = '/COM=usb -download=$(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 = cygwinPathTranslate(winPath)
        value = strrep(winPath, '\', '/');
        value = strrep(value, ':', ' ');
        [driveStr, pathStr] = strtok(value);
        driveStr = strcat('/cygdrive/', driveStr);
        pathStr = strtok(pathStr);
        value = strcat(driveStr, pathStr);
        %value =['"', value, '"'];
    end

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

%[EOF]

Contact us