-% Copyright (C) 2013-2014 Czech Technical University in Prague
+% Copyright (C) 2013-2015 Czech Technical University in Prague
%
% Authors:
% - Carlos Jenkins <carlos@jenkins.co.cr>
%
-% This document contains proprietary information belonging to Czech
-% Technical University in Prague. Passing on and copying of this
-% document, and communication of its contents is not permitted
-% without prior written authorization.
+% Permission is hereby granted, free of charge, to any person
+% obtaining a copy of this software and associated documentation
+% files (the "Software"), to deal in the Software without
+% restriction, including without limitation the rights to use,
+% copy, modify, merge, publish, distribute, sublicense, and/or sell
+% copies of the Software, and to permit persons to whom the
+% Software is furnished to do so, subject to the following
+% conditions:
+
+% The above copyright notice and this permission notice shall be
+% included in all copies or substantial portions of the Software.
+
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+% OTHER DEALINGS IN THE SOFTWARE.
%
% File : rpp_download.m
% Abstract:
% Code download utility for Simulink RPP Target.
%
-% This function is optionally executed at the end of the build process
-% if it is successful and the user selected "Download compiled binary to
-% RPP" option on the build configuration panel. This function calls
-% loadti.sh script with the generated binary and using configuration for
-% the XDS100v2 JTAG Emulators.
+% This function is executed by rpp_make_rtw_hook.m only if the build process
+% finished successfully and RPP_DOWNLOAD is set to TRUE. The RPP_DOWNLOAD option
+% is controlled by "Download to RPP board" option in RPP code generation options.
+%
+% Avoid executing this function with Code Composer Studio running on background.
+%
+% Parameters:
+% use_openocd - When set to TRUE, an OpenOCD will be used for the code
+% download. This tool is available only for Unix based systems.
+% When set to FALSE, a Texas Instruments Loader will be used.
+% for the code download. The TI tool is available for Unix based
+% systems and Windows.
+% This parameter is controled by "Use OpenOCD to download the compiled binary"
+% option in RPP code generation options.
+% use_sdram - When set to TRUE, the code will be downloaded into SDRAM. This option
+% requires a base code for the MPU, EMIF, POM and SDRAM configuration to
+% be present in the device Flash memory. The presence of the code is not
+% verified.
+% When set to FALSE, the code will be downloaded into the Flash memory.
+% This option is usefull for debugging as the Flash memory has very limited
+% number of rewrites.
+% NOTE: The code execution may be slower from the SDRAM than from the Flash.
+% NOTE: This function is not yet implemented.
+% This parameter is controlled by "Download compiled binary to SDRAM"
+% option in RPP code generation options.
%
% References:
% loadti utility wiki at http://processors.wiki.ti.com/index.php/Loadti
% Readme file in <cssroot>/ccs_base/scripting/examples/loadti/readme.txt
-
+% OpenOCD wiki at https://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
function rpp_download(modelName, buildDirectory, use_openocd, use_sdram)
RppLibRoot = getpref('rpp', 'RppLibRoot');
-
+ CCSRoot = getpref('rpp', 'CCSRoot');
+
%TODO: parse the EXE_FILE_EXT from target_tools.mk
outfile = fullfile(buildDirectory, [modelName, '.out']);
downloadLog = fullfile(buildDirectory, 'download.log');
if use_openocd
- disp(['OpenOCD will be used.'])
if use_sdram
- disp(['Will download to SDRAM'])
- command = [...
- RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
- , outfile, ' 2> ' , downloadLog ];
- disp('### Running downloader script:');
- disp(command);
- status = system(command);
- if status ~= 0,
- throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
- end
- disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
+ disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
+ disp(['### -> Uncheck the option "Download compiled binary to SDRAM" (set use_openocd to false) to download the code to the Flash memory.'])
else
- disp(['Will download to Flash'])
- command = [...
- RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
- , outfile, ' 2> ' , downloadLog ];
- disp('### Running downloader script:');
- disp(command);
- status = system(command);
- if status ~= 0,
- throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
+ if isunix
+ command = [...
+ RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
+ , outfile, ' 2> ' , downloadLog ];
+ disp('### Running downloader script:');
+ disp(command);
+ status = system(command);
+ if status ~= 0,
+ throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
+ end
+ disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
+ else
+ disp(['### Sorry code download via OpenOCD is available for UNIX systems only. Uncheck the option']);
+ disp(['### -> Uncheck the option "Use OpenOCD to download the compiled binary" to use Ti downloader, which is functional under Windows.']);
end
- disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
end
else
- disp(['TI DSS Generic Loader will be used.'])
if use_sdram
- disp(['Will download to SDRAM'])
- disp(['Not yet implemented'])
- else
- disp(['Will download to Flash'])
-
+ disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
+ disp(['### -> Uncheck the option "Download compiled binary to SDRAM" (set use_sdram to false) to download the code to the Flash memory.'])
+ else
+ disp(['### Downloading ', modelName, ' to RPP board...']);
+ ccxml_filename = ccxml_read(RppLibRoot);
if isunix
-
- disp(['### Downloading ', modelName, ' to RPP board...']);
-
- % -a, --async-run Run the specified executable and return without halting
% -r, --reset Reset target before run
% -c, --cfg-file=CONFIG_FILE Target setup config file
command = [...
'CCS_SCRIPTING="' CCSRoot '/ccs_base/scripting/" ' ...
- '"' RppLibRoot '/../loadti/loadti.sh" -a -r ' ...
- '-c "', RppLibRoot, '/rpp/TMS570LS3137.ccxml" ', ...
+ '"' RppLibRoot '/../loadti/loadti.sh" -r ' ...
+ '-c "', ccxml_filename, '" ', ...
'"', outfile, ...
'" 2> "', downloadLog, '"'];
- disp('### Running downloader script:');
- disp(command);
- status = system(command);
- if status ~= 0,
- throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
- end
-
- disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
-
else
- disp(['### Sorry code download is available for UNIX systems only.']);
- disp(['### -> Add support for non UNIX systems in <targetroot>/rpp/rpp_download.m file.']);
- end
- end
+ % -r, --reset Reset target before run
+ % -c, --cfg-file=CONFIG_FILE Target setup config file
+ command = [...
+ 'set CCS_SCRIPTING="' CCSRoot '\ccs_base\DebugServer"&&' ...
+ '"' RppLibRoot '\..\loadti\loadti.bat" -r ' ...
+ '-c "', ccxml_filename, '" ', ...
+ '"', outfile];
+ end
+ disp('### Running downloader script:');
+ disp(command);
+ status = system(command, '-echo');
+ if status ~= 0,
+ throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
+ end
+ disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
+ end
end
end
+
+function ccxml_path = ccxml_read(RppLibRoot)
+ f = fopen(fullfile(RppLibRoot, 'Makefile.config'), 'r');
+ while ~feof(f),
+ l = fgetl(f);
+ [val, count] = sscanf(l, ' TARGET_CCXML = %s');
+ if count, ccxml=val; end
+ [val, count] = sscanf(l, ' TARGET = %s');
+ if count, target=val; end
+ end
+ ccxml_path = fullfile(RppLibRoot, 'build', target, ccxml);
+ fclose(f);
+end
\ No newline at end of file