1 % Copyright (C) 2013-2015 Czech Technical University in Prague
4 % - Carlos Jenkins <carlos@jenkins.co.cr>
6 % Permission is hereby granted, free of charge, to any person
7 % obtaining a copy of this software and associated documentation
8 % files (the "Software"), to deal in the Software without
9 % restriction, including without limitation the rights to use,
10 % copy, modify, merge, publish, distribute, sublicense, and/or sell
11 % copies of the Software, and to permit persons to whom the
12 % Software is furnished to do so, subject to the following
15 % The above copyright notice and this permission notice shall be
16 % included in all copies or substantial portions of the Software.
18 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 % OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 % NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 % HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 % WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 % OTHER DEALINGS IN THE SOFTWARE.
27 % File : rpp_download.m
29 % Code download utility for Simulink RPP Target.
31 % This function is executed by rpp_make_rtw_hook.m only if the build process
32 % finished successfully and RPP_DOWNLOAD is set to TRUE. The RPP_DOWNLOAD option
33 % is controlled by "Download to RPP board" option in RPP code generation options.
35 % Avoid executing this function with Code Composer Studio running on background.
38 % use_openocd - When set to TRUE, an OpenOCD will be used for the code
39 % download. This tool is available only for Unix based systems.
40 % When set to FALSE, a Texas Instruments Loader will be used.
41 % for the code download. The TI tool is available for Unix based
42 % systems and Windows.
43 % This parameter is controled by "Use OpenOCD to download the compiled binary"
44 % option in RPP code generation options.
45 % use_sdram - When set to TRUE, the code will be downloaded into SDRAM. This option
46 % requires a base code for the MPU, EMIF, POM and SDRAM configuration to
47 % be present in the device Flash memory. The presence of the code is not
49 % When set to FALSE, the code will be downloaded into the Flash memory.
50 % This option is usefull for debugging as the Flash memory has very limited
52 % NOTE: The code execution may be slower from the SDRAM than from the Flash.
53 % NOTE: This function is not yet implemented.
54 % This parameter is controlled by "Download compiled binary to SDRAM"
55 % option in RPP code generation options.
58 % loadti utility wiki at http://processors.wiki.ti.com/index.php/Loadti
59 % Readme file in <cssroot>/ccs_base/scripting/examples/loadti/readme.txt
60 % OpenOCD wiki at https://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
62 function rpp_download(modelName, buildDirectory, use_openocd, use_sdram)
63 RppLibRoot = getpref('rpp', 'RppLibRoot');
64 CCSRoot = getpref('rpp', 'CCSRoot');
66 %TODO: parse the EXE_FILE_EXT from target_tools.mk
67 outfile = fullfile(buildDirectory, [modelName, '.out']);
68 downloadLog = fullfile(buildDirectory, 'download.log');
72 disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
73 disp(['### -> Uncheck the option "Download compiled binary to SDRAM" (set use_openocd to false) to download the code to the Flash memory.'])
77 RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
78 , outfile, ' 2> ' , downloadLog ];
79 disp('### Running downloader script:');
81 status = system(command);
83 throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
85 disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
87 disp(['### Sorry code download via OpenOCD is available for UNIX systems only. Uncheck the option']);
88 disp(['### -> Uncheck the option "Use OpenOCD to download the compiled binary" to use Ti downloader, which is functional under Windows.']);
93 disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
94 disp(['### -> Uncheck the option "Download compiled binary to SDRAM" (set use_sdram to false) to download the code to the Flash memory.'])
96 disp(['### Downloading ', modelName, ' to RPP board...']);
97 ccxml_filename = ccxml_read(RppLibRoot);
99 % -r, --reset Reset target before run
100 % -c, --cfg-file=CONFIG_FILE Target setup config file
102 'CCS_SCRIPTING="' CCSRoot '/ccs_base/scripting/" ' ...
103 '"' RppLibRoot '/../loadti/loadti.sh" -r ' ...
104 '-c "', ccxml_filename, '" ', ...
106 '" 2> "', downloadLog, '"'];
108 % -r, --reset Reset target before run
109 % -c, --cfg-file=CONFIG_FILE Target setup config file
111 'set CCS_SCRIPTING="' CCSRoot '\ccs_base\DebugServer"&&' ...
112 '"' RppLibRoot '\..\loadti\loadti.bat" -r ' ...
113 '-c "', ccxml_filename, '" ', ...
116 disp('### Running downloader script:');
118 status = system(command, '-echo');
120 throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
122 disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);
128 function ccxml_path = ccxml_read(RppLibRoot)
129 f = fopen(fullfile(RppLibRoot, 'Makefile.config'), 'r');
132 [val, count] = sscanf(l, ' TARGET_CCXML = %s');
133 if count, ccxml=val; end
134 [val, count] = sscanf(l, ' TARGET = %s');
135 if count, target=val; end
137 ccxml_path = fullfile(RppLibRoot, 'build', target, ccxml);