What is the role of Build tool object in toolchain?
6 views (last 30 days)
Show older comments
Toshifumi Sone
on 20 Feb 2021
Commented: Toshifumi Sone
on 7 Mar 2021
Dear All,
Could you tell me the purpose of the code below??
I'm trying to make toolchain for RX64 micro-controller form Renesas Electronics. I have to make .hex file and ASAP2 file from Simulink bolck with Embedded Corder.
But I couldn't understand clear what the role of code below from link below .
% ------------------------------
% C Compiler
% ------------------------------
tool = tc.getBuildTool('C Compiler');
tool.setName('Intel C Compiler');
tool.setCommand('icl');
tool.setPath('');
tool.setDirective('IncludeSearchPath','-I'); <- What does this code mean? What is the purpose of this code?
tool.setDirective('PreprocessorDefine','-D');<- What does this code mean? What is the purpose of this code?
tool.setDirective('OutputFlag','-Fo');<- What does this code mean? What is the purpose of this code?
tool.setDirective('Debug','-Zi');<- What does this code mean? What is the purpose of this code?
tool.setFileExtension('Source','.c');<- What does this code mean? What is the purpose of this code?
tool.setFileExtension('Header','.h');<- What does this code mean? What is the purpose of this code?
tool.setFileExtension('Object','.obj');<- What does this code mean? What is the purpose of this code?
tool.setCommandPattern('|>TOOL<| |>TOOL_OPTIONS<| |>OUTPUT_FLAG<||>OUTPUT<|');<- What does this code mean? What is the purpose of this code?
Regards,
0 Comments
Accepted Answer
Yuxuan Hao
on 24 Feb 2021
Hi Toshifumi,
Simulink will use these options to generate the MSVC compiler option/makefile/cmakes.
Take MSVC compiler options as an example, you can refer to this web: https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=msvc-160
For example, IncludeSearchPath means which directory you want to add to the search path. PreprocessorDefine means to defines a preprocessing symbol for a source file.
You should be able to find what do all these configurations mean in that web page.
Best Regards,
Yuxuan
0 Comments
More Answers (2)
Toshifumi Sone
on 25 Feb 2021
2 Comments
Ondrej Mikulas
on 25 Feb 2021
Hello Toshifumi,
To use the cc-rx compiler, you need to modify the ToolchainInfo definition file. The code in the original question comes from the demo example file intel_tc from https://uk.mathworks.com/help/rtw/ug/register-custom-toolchain-and-build-executable.html#d122e99958.
Based on my experience, the documentation of this topic in Matlab Coder / Simulink Coder / Embedded Coder is quite too brief and fails to explain the complete workflow.
You need to modify the ToolchainInfo definition file in order to pass correct compiler and linker commands.
The PreprocessorDefine directive specifies the flag used to define macros for your compiler. The '-D' is specific to the Intel compiler from the demo example. You need to find an equivalent compiler flag that is valid for the Renesas compiler. Quickly skimming throught the documentation, I think the flag should be '-define='.
Similarly, the IncludeSearchPath specifies the compiler flag to select include directories. Intel compiler uses '-I' to select the include directories. Renesas CC-RX should use '-include='.
The other commands need to be customized in a similar way depending on the commands that Renesas compiler expects. You will need to set the name of the compiler commands:
% From Renesas ccrx documentation:
% ccrx -isa=rxv1 -output=obj=tp.obj tp1.c tp2.c
tool = tc.getBuildTool('C Compiler');
tool.setName( 'Renesas C Compiler'); % Descriptive name for you own identification
tool.setCommand( 'ccrx'); % Compiler command name
tool.setPath( ''); % Assumes the ccrx is defined on system path. Otherwise provide aboslute path to compiler installed folder
tool.setDirective( 'IncludeSearchPath', '-include');
tool.setDirective( 'PreprocessorDefine', '-define');
tool.setDirective( 'OutputFlag', '-output=obj=');
After registering the customized toolchain, you can experiment with it. It takes some trial and error to make things work, so prepare for that. Note that you can use tc.validate method of the ToolchainInfo object to check that it is formally correct (from Matlab point of view).
You can check that by setting GenerateCodeOnly parameter to on in Simulink model. Then you can inspect the generated makefile in the <model>_ert_rtw directory.
When you set the GenerateCodeOnly to off, Simulink will try to call the compiler and returns the commandline output to the Diagnostic Viewer window. You can check the messages there.
See Also
Categories
Find more on Custom Toolchain Registration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!