Overview of Creating a Model and Generating Executable for C2000 Processors
Accessing the Embedded Coder Block Library
Describes how to access the block library and open the required target hardware.
After you have Hardware Setup for C2000 Microcontroller Blockset, you can open the block library for C2000™ Microcontroller Blockset.
To open the C2000 Microcontroller Blockset Library, at the MATLAB® command prompt, enter the command:
c2000lib
Alternately from the Simulink Library Browser, locate, and select C2000 Microcontroller Blockset.
Open the required target block to access the device driver blocks.
Create your real-time model for your application the same way you create other Simulink® models. Select blocks to build your model from the following sources or products:
The libraries in the
c2000lib
block library (for handling input and output functions for on your target hardware)Simulink Coder™ software
Discrete time blocks from Simulink
Another blockset that meets your needs and operates in the discrete time domain
Configuring Target Hardware Resources
Describes how to configure target hardware resources using configuration parameters.
After adding the required blocks for the model, Open Modeling tab and Click Model Settings.
In the Configuration Parameters window, click Hardware Implementation and select the Hardware Board.
Configure the Target Hardware Resources as required. For more details refer Model Configuration Parameters for Texas Instruments C2000 Processors and Model Configuration Parameters for Texas Instruments F2838x (ARM Cortex-M4).
Note
The peripherals supported in C2000 Microcontroller Blockset can be of any of the following configuration:
Blocks only - features that can be configured only through the block. (Hardware Interrupt, etc.)
Blocks + Configuration Parameters - features that can configured in both block and configuration parameters. (ADC, ePWM, SCI, SPI, etc)
Configuration Parameters only - features that can be configured only through configuration parameters. (EMIF, DMA, Clock Configuration, etc.)
Configuring Additional Options for Hardware Selection
Following configuration settings are done automatically as part of a TI C2000 hardware selection. On selecting different hardware other than TI C2000 target, the below configurations are re-configured to default.
When changing ModelReferenceNumInstancesAllowed from
Multiple
to One
, the name for the signal logged in
child model (output signal) when running external mode using XCP over
CAN will change.
If set to
One
, you get<ChildModelName>_B.<outputsignalname>
If set to
Multiple
, you get<TopModelName>_DW.Model_InstanceData.rtb.<outputsignalname>
hCS
is the config set object for the model. You can use the following
command to get the config set object.
hCS = getActiveConfigSet(mdlname);
Go to Configuration Parameters > Math and Data Types and set the Simulation behavior for denormal numbers parameter to
Flush to Zero (FTZ)
.set_param(hCS,'DenormalBehavior', 'FlushToZero');
Go to Configuration Parameters > Math and Data Types and set the Default for underspecified data type parameter to
Single
.set_param(hCS,'DefaultUnderspecifiedDataType','single');
Go to Configuration Parameters > Code Generation > Interface and set the Code replacement libraries parameter to
TI C28x
for the C28x core of TI C2000 processors.set_param(hCS,'CodeReplacementLibrary','TI C28x');
Go to Configuration Parameters > Code Generation > Optimization > Advanced parameters and select the Maximum stack size (bytes) parameter depending on the processor.
SL No Device Family Maximum Stack Size(bytes) 1 F281x
512
2 F2802x, F2803x, F2805x, F2834x, F2804x, F28M35x, F28M36x
768
3 F2806x, F2837x, F28004x, F28003x, F2838x, F28002x
1024
4 ARM-Core 2560
set_param(hCS,'MaxStackSize','1024');
Go to Configuration Parameters > Hardware Implementation > Device details and set the Support long long parameter to
On
.set_param(hCS,'ProdLongLongMode','on');
Note
Models using CLA requires long long mode to be set to
off
.Go to Configuration Parameters > Code Generation > Optimization and set the Remove root level I/O zero initialization parameter to
On
.set_param(hCS,'ZeroExternalMemoryAtStartup', 'on');
Ensure the above mentioned configurations are done when the model has to run in SIL mode for a custom board. In SIL mode, ensure following additional setting is done:
Go to Configuration Parameters > Code Generation > Verification and set the Enable portable word sizes parameter to
On
. This will ensure identical code generation for a model in PIL and
SIL mode.
Configuring Additional Options for Code Generation
You can follow the steps below to configure additional options like Compiler flag, CRL and Custom Code, etc required for code generation in Code Generation pane.
In the Configuration Parameters window, click Code Generation pane.
COFF ABI format will interpret double datatype in Simulink as 32-bit floating point for C28x processors and ELF ABI format will interpret double datatype in Simulink as 64-bit floating point for TI F2838x (C28x), TI F2807x, F2837x, F28004x, F28003x, F28002x, F28001x, F28P5x processors. For more information related to COFF ABI and ELF ABI. For more information, see Exploring TI C2000 Toolchain Options
Generate code only option under Build process enables you to specify code generation versus an executable build. For more information, refer to Generate code only (Simulink Coder).
You can choose the build configuration options to get the required compiler flags for the code compilation.
Faster builds
Faster run
Debug
Specify
Use Specify option to edit column Tool Options to add any additional flags. For more information, refer to Build configuration (Simulink Coder), Enhance Code Execution Speed in TI C2000 Simulink Applications, and Exploring TI C2000 Toolchain Options.
The Code Generation > Optimization category includes parameters for improving the simulation speed of your models and improving the performance of the generated code. For more information, refer Model Configuration Parameters: Code Generation Optimization (Simulink Coder).
The Code Generation > Report category includes parameters for generating and customizing the code generation report. For more information, refer Model Configuration Parameters: Code Generation Report (Simulink Coder).
The Code Generation > Custom Code category includes parameters for inserting custom C code into the generated code. For more information, refer Model Configuration Parameters: Code Generation Custom Code (Simulink Coder).
The Code Generation > Interface category includes parameters for configuring the interface of the generated code and code replacement library(CRL). For more information, refer Model Configuration Parameters: Code Generation Interface (Simulink Coder).
The Code Generation > Verification category includes code verification and performance analysis parameters for SIL and PIL simulations and also configuring profiling options. Additionally you can configure the following options and perform profiling which is independent of SIL and PIL simulations:
Measure task execution time - by enabling this parameter in Configuration Parameters, you can perform real time execution of profiling.
Measure function execution times - configure to get different levels of profiling (tasks, subsystems or functions) in Configuration Parameters. The profiling logic is added accordingly. There will be additional overhead due to profiling logic on the measure time. Currently only hardware interrupts are supported for asynchronous system profiling.
off - measure time with respective task
course - tasks, reference models and subsystem only
detailed - tasks,reference models, subsystem, block/function internalization and step logic
Save options - select to save only as summary data only or all data to get detailed time line in Configuration Parameters. Metrics option is not supported for C2000.
Profiling with Build, Load and Run
Profiling data - Run the following code in MATLAB Command Window to obtain the profiling data and report and task scheduling.
Profiling data - gathers profiling data from the target hardware and stores it in a variable.
codertarget.profile.getData('ModelName')
Profiling report - provides HTML report based on the profiling data.
executionProfile.report
Task scheduling - visualize the scheduling of the different tasks and functions.
executionProfile.schedule
For more information, refer Model Configuration Parameters: Code Generation Verification (Embedded Coder) and Real-Time Code Execution Profiling.
Profiling with Monitor & Tune
You can use the C2000 Microcontroller Blockset to profile the real-time execution of the generated code running as an executable on a Texas Instruments® C2000 board with XCP on Serial and XCP on TCP/IP Interface. For more information, see Code Execution Profiling on Texas Instruments C2000 and Troubleshooting External Mode Issues.
Profiling with PIL
You can configure the profiling options and use it with PIL mode.
Generate Code, Build and Download the Executable
After configuring hardware resource and code generation for a model, you can generate the code, build the real-time executable and download it to your Texas Instruments development board. Simulink Coder software automatically generates C code and inserts the I/O device drivers as specified by the hardware blocks along with configuration parameters in your Simulink model.
Note
When naming the model, make sure not to name the model name which matches the keyword or that defines the makefile that gets generated. For example, CPU1, CPU2.
When you are creating a custom device driver block using S-function, use the
MATLAB_MEX_FILE macro to differentiate between simulation and code generation behaviors. For
example, when you include the Texas Instruments header file in the generated code for creating the MEX file, use the
#else
section to avoid compilation errors, as shown:
#ifdef MATLAB_MEX_FILE /* /* Simulation behavior */ #else /* Code generation behavior*/ #endif
During the build operation, the Texas Instruments cross-compiler builds an executable file from the generated code. The build operation will generate dependency files (.dep) for each of the source files (.c) which it will use to create the object files (.obj). The object files are then linked using linker command file to create the map file (.map) and the executable file (.exe) files.
The default linker command file can be modified, or different linker command file can be
provided if required using the option Hardware Implementation > Target
Hardware Resources > Build options > Use custom linker
.
Dependency Build
Subsequent builds will use dependency files to recompile the object files only if any source or header files are changed or make file is updated. The dependency build makes use of Windows® PowerShell to update the dependency files. Hence the dependency build will not be used and object files is recompiled, if Windows PowerShell is not present in the computer.
Parallel Build
The build will make use of multiple cores in host computer by enabling parallel build to compile the object files faster. This may cause issues in the order of the messages displayed in build log if there are any build failures. You can disable this option using Hardware Implementation > Target Hardware Resources > Build options > Disable parallel build.
If you select the Build, load and run
option in
Hardware Implementation > Target Hardware Resources > Build options > Build
action parameter then the generated executable is automatically downloaded to
the target.
Select option Boot from Flash
if the application has to load
to the flash. If you do not select this option, the application loads to the RAM.
Hardware Implementation > Target Hardware Resources > Build options > Boot from
Flash.
By default, the target configuration file will be provided to support download to Control card or launchpad of the selected hardware board. If you have any custom board, you can provide your own target configuration file in the option in Hardware Implementation > Target Hardware Resources > Build options > Select target configuration.
For CCS v5 and the later versions, a CCS project file is also generated during the build process. You can use this project file for debugging in the CCS IDE.
Note
Rapid Accelerator simulation is not supported by C2000 Microcontroller Blockset.
See Also
Creating CCS Project from a Model | Enhance Code Execution Speed in TI C2000 Simulink Applications | Measuring Code Execution Time on TI C2000 using Custom Code Blocks | Troubleshooting External Mode Issues