]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/rpp/rpp_download.m
Merge branch 'maint-rm48' into rm48/master
[pes-rpp/rpp-simulink.git] / rpp / rpp / rpp_download.m
1 % Copyright (C) 2013-2014 Czech Technical University in Prague
2 %
3 % Authors:
4 %     - Carlos Jenkins <carlos@jenkins.co.cr>
5 %
6 % This document contains proprietary information belonging to Czech
7 % Technical University in Prague. Passing on and copying of this
8 % document, and communication of its contents is not permitted
9 % without prior written authorization.
10 %
11 % File : rpp_download.m
12 % Abstract:
13 %     Code download utility for Simulink RPP Target.
14 %
15 %     This function is executed by rpp_make_rtw_hook.m only if the build process
16 %     finished successfully and RPP_DOWNLOAD is set to TRUE. The RPP_DOWNLOAD option
17 %     is controlled by "Download to RPP board" option in RPP code generation options.
18 %
19 %     Avoid executing this function with Code Composer Studio running on background.
20 %
21 % Parameters:
22 %     use_openocd - When set to TRUE, an OpenOCD will be used for the code
23 %                 download. This tool is available only for Unix based systems.
24 %                 When set to FALSE, a Texas Instruments Loader will be used.
25 %                 for the code download. The TI tool is available for Unix based
26 %                 systems and Windows.
27 %                 This parameter is controled by "Use OpenOCD to download the compiled binary"
28 %                 option in RPP code generation options.
29 %     use_sdram - When set to TRUE, the code will be downloaded into SDRAM. This option
30 %                 requires a base code for the MPU, EMIF, POM and SDRAM configuration to
31 %                 be present in the device Flash memory. The presence of the code is not
32 %                 verified.
33 %                 When set to FALSE, the code will be downloaded into the Flash memory.
34 %                 This option is usefull for debugging as the Flash memory has very limited
35 %                 number of rewrites.
36 %                 NOTE: The code execution may be slower from the SDRAM than from the Flash.
37 %                 NOTE: This function is not yet implemented.
38 %                 This parameter is controlled by "Download compiled binary to SDRAM"
39 %                 option in RPP code generation options.
40 %
41 % References:
42 %     loadti utility wiki at http://processors.wiki.ti.com/index.php/Loadti
43 %     Readme file in <cssroot>/ccs_base/scripting/examples/loadti/readme.txt
44 %     OpenOCD wiki at https://rtime.felk.cvut.cz/hw/index.php/TMS570LS3137#OpenOCD_setup_and_Flashing
45
46 function rpp_download(modelName, buildDirectory, use_openocd, use_sdram)
47         RppLibRoot = getpref('rpp', 'RppLibRoot');
48         CCSRoot    = getpref('rpp', 'CCSRoot');
49         
50         %TODO: parse the EXE_FILE_EXT from target_tools.mk
51         outfile     = fullfile(buildDirectory, [modelName, '.out']);
52         downloadLog = fullfile(buildDirectory, 'download.log');
53
54         if use_openocd
55                 if use_sdram
56                         disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
57                         disp(['###     -> Uncheck the option "Download compiled binary to SDRAM" (set use_openocd to false) to download the code to the Flash memory.'])
58                 else
59                         if isunix
60                                 command = [...
61                                         RppLibRoot '/../loadopenocd/loadopenocd.sh -d flash -b -s ' ...
62                                         , outfile, ' 2> ' , downloadLog ];
63                                 disp('### Running downloader script:');
64                                 disp(command);
65                                 status = system(command);
66                                 if status ~= 0,
67                                         throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
68                                 end
69                                 disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);                    
70                         else
71                                 disp(['### Sorry code download via OpenOCD is available for UNIX systems only. Uncheck the option']);
72                                 disp(['###     -> Uncheck the option "Use OpenOCD to download the compiled binary" to use Ti downloader, which is functional under Windows.']);
73                         end
74                 end
75         else
76                 if use_sdram
77                         disp(['### Sorry, Downloading to the SDRAM is not yet implemented.'])
78                         disp(['###     -> Uncheck the option "Download compiled binary to SDRAM" (set use_sdram to false) to download the code to the Flash memory.'])
79         else
80             disp(['### Downloading ', modelName, ' to RPP board...']);
81                         if isunix
82                                 % -r,   --reset                 Reset target before run
83                                 % -c,   --cfg-file=CONFIG_FILE  Target setup config file
84                                 command = [...
85                                         'CCS_SCRIPTING="' CCSRoot '/ccs_base/scripting/" ' ...
86                                         '"' RppLibRoot '/../loadti/loadti.sh" -r ' ...
87                                         '-c "', RppLibRoot, '/../loadti/RM48L952.ccxml" ', ...
88                                         '"', outfile, ...
89                                         '" 2> "', downloadLog, '"'];
90                         else
91                                 % -r,   --reset                 Reset target before run
92                                 % -c,   --cfg-file=CONFIG_FILE  Target setup config file
93                                 command = [...
94                                         'set CCS_SCRIPTING="' CCSRoot '\ccs_base\DebugServer"&&' ...
95                                         '"' RppLibRoot '\..\loadti\loadti.bat" -r ' ...
96                                         '-c "', RppLibRoot, '\..\loadti\RM48L952.ccxml" ', ...
97                                         '"', outfile];
98             end
99             disp('### Running downloader script:');
100             disp(command);
101             status = system(command, '-echo');
102             if status ~= 0,
103                 throw(MException('rpp:targetDlErr', ['Failed to download ' modelName ' to the target']))
104             end
105             disp(['Done. <a href="matlab:open(''', downloadLog, ''')">Open download log.</a>']);    
106         end
107         end
108
109 end