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:
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
c2000libblock 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)
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
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
If set to
Multiple, you get
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).
Go to Configuration Parameters > Math and Data Types and set the Default for underspecified data type parameter to
Go to Configuration Parameters > Code Generation > Interface and set the Code replacement libraries parameter to
TI C28xfor the C28x core of TI C2000 processors.
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
F2802x, F2803x, F2805x, F2834x, F2804x, F28M35x, F28M36x
F2806x, F2837x, F28004x, F28003x, F2838x, F28002x
Go to Configuration Parameters > Hardware Implementation > Device details and set the Support long long parameter to
Models using CLA requires long long mode to be set to
Go to Configuration Parameters > Code Generation > Optimization and set the Remove root level I/O zero initialization parameter to
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
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.
Toolchain for C28x core of all TI C2000 processors expect TI F2838x processor is Texas Instruments Code Composer Studio (C2000). This generates an executable in Common Object File Application Binary Interface (COFF ABI) format.
Toolchain for TI F2838x (C28x) processor is Texas Instruments Code Composer Studio - EABI (C2000). This generates an executable in ELF Application Binary Interface (EABI) format.
Toolchain for ARM core is Texas Instruments Code Composer Studio (ARM).
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) processor. For more information related to COFF ABI and ELF ABI, refer to the TI documentation.
ELF ABI (EABI) format will only work with TI F2838x processor and rest of the TI C2000 processors with COFF ABI format.
By default, the code generation tools shipped with the blockset has EABI support. If you want to use a different version of CGT ensure it has EABI support.
All the files referred (libraries - .lib, source - .c/.h/.asm and linker command files - .cmd) should be in the same format as supported by the toolchain. Else linker errors is seen during build process.
If your are adding any custom files, ensure that the custom files matches the toolchain format.
Generate code only option under Build process enables you to specify code generation versus an executable build. For more information, refer Generate code only (Simulink Coder)
You can choose the build configuration options to get the required compiler flags for the code compilation.
Use Specify option to edit column Tool Options to add any additional flags. For more information, refer to Build configuration (Simulink Coder)
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, report and time line.
Profiling data - gathers profiling data from the target hardware and stores it in a variable.
Profiling report - provides HTML report based on the profiling data.
Profiling timeline - provides the timeline report of the tasks or profiled functions.
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.
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.
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.
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.
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
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
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.
Rapid Accelerator simulation is not supported by C2000 Microcontroller Blockset.