How to use C2000 CLA and solutions to common CLA memory problems
[Copy link]
Author: Chen Yang, Benjamin Zhou, Strong Zhang
CLA (Control Law Accelerator) is an independent programmable 32-bit floating-point digital processing unit designed for fast trigger response and mathematical operations. CLA works independently of the C28x CPU, has the same clock frequency as the CPU, and can execute algorithms and periodic calculations. By adding parallel processing units CLA, the performance of the C28x CPU is expanded. There are currently three types of CLA in the C2000 series products. Different C2000 models correspond to different CLA types. The differences between each type and the corresponding C2000 device model details are shown in Figure 1. Type 2 CLA can directly read the ADC result register, greatly reducing the delay from ADC sampling to output, improving the system response and allowing the system to run at a higher frequency; and can directly operate all Epwm, HRPWM, eCAP, eQEP, CMPSS, DACSDFM, PGA, SPI, LIN, FSI, PMBUS, CLB and GPIO data registers; CLA can independently respond to peripheral interrupts. Using CLA to perform some periodic tasks can free up the CPU to work on other system tasks.
查看详情
Figure 1 CLA types and corresponding C2000 devices
The use of CLA includes initialization settings and task definition. Initialization is completed by the CPU, including program memory and data memory allocation, and task trigger configuration; Type 2 CLA provides 8 independent tasks (can also be configured as 7 independent tasks and 1 underlying continuous running task). These tasks are similar to interrupt service functions, triggered by interrupts and run until the task ends, and can be configured to generate an interrupt when the task is completed. The CLA block diagram is shown in Figure 2.
查看详情
Figure 2 CLA block diagram
CLA can access the memory of RAMLS0-LS7 blocks, and each block can be configured as CPU-only or shared data between CPU and CLA. These memory blocks are assigned to the CPU by default when reset, and need to be initialized by the CPU before they can be used to share data with CLA. If these memory blocks are configured for data sharing, they can be further configured as program memory or data memory. Program memory is used to store CLA program code, and data memory is used to store variables and coefficients used by CLA programs. There are dedicated message memories MSG RAMs for transferring data between CPU and CLA. The description of CLA's memory and register operation mode is shown in Figure 3.
查看详情
Figure 3 CLA Memory and register operations
CLA initialization is performed by the CPU during software initialization and consists of six steps:
- Copy the CLA task code from Flash to the CLA program memory
- Allocate CLA data memory
- Configure CLA registers: including enabling CLA clock; assigning CLA task function addresses; selecting task trigger sources; enabling software-triggered tasks as needed; mapping CLA program memory and data memory to CLA space
- Configure the service function of the CLA task completion interrupt in PIE
- Enable CLA task trigger in MIER register
- Initialize the trigger source peripheral so that it can trigger the CLA task
During CLA development, engineers often focus on CLA initialization, CLA_task configuration, and algorithm design at the code level, but ignore the underlying problem - CLA memory allocation in CMD files. Improper memory allocation may cause compilation errors and memory overflow.
This blog post will give an example of the specific error caused by memory allocation error when using TI's TMS320F280049 for CLA development.
In this example, after completing CLA initialization and configuring the interrupt function of CLA_task, click Compile and CCS reports 43 "#17003-D" warnings, as shown in Figure 4:
查看详情
Figure 4 #17003-D Warning
Description Resource Path Location Type:
#17003-D</a> relocation to symbol "CLAscratch_end" overflowed; the 6-bit relocated address 0xee is too large to encode in the 16-bit unsigned field (type = 'R_ABS16_OC' (107), file = "../xxxxxxx", offset = 0x00000312, section = "Cla1Prog")
The warning shows that CLAscratch_end memory overflows. The problem is located in the CMD file. Check the memory allocation related to scratch in CMD, as shown in Figure 5.
查看详情
Figure 5 CMD file scratchpad description
It was found that only .scrathpad was allocated to RAMLS1, and CLAscratch_end and the definition of CLA_SCRATCHPAD_SIZE were not found .
Therefore, open the .map file to determine whether __cla_scratchpad_end/start is allocated , and search for scratchpad in the .map file , as shown in Figure 6.
查看详情
Figure 6. Description of cla_scratchpad_end in the .map file
As shown in Figure 6, only __cla_scratchpad_end is found in .map , which indicates that the project uses scratchpad , but there is no memory allocation for __cla_scratchpad_start .
The cause of the problem has been found. The solution is to configure the scratchpad in the CMD file , as shown in Figure 7.
The reference configuration is as follows:
①Add the following code to the head of the CMD file, as shown in the figure
- CLA_SCRATCHPAD_SIZE=0x100;
- --undef_sym=__cla_scratchpad_end
- --undef_sym=__cla_scratchpad_start
查看详情
Figure 7 Scratchpad configuration
②Add the following code at the end of the SECTIONS{} code section of the CMD file
- CLAscratch:
- {*.lib(CLAscratch)
- .+=CLA_SCRATCHPAD_SIZE;
- *.lib(CLAscratch_end)}>RAMLS1,
- PAGE=1
Compile again, the #17003-D warning has disappeared, and the compilation is successful. The result is shown in Figure 8.
查看详情
Figure 8 Compilation result after modifying CMD
At this point, check the .map file again and find that __cla_scratchpad_end/start and CLA_SCRATCHPAD_SIZE have been successfully allocated, as shown in Figure 9.
查看详情
查看详情
查看详情
Figure 9 Modify the CMD file to compile and generate the .map file
The above is the solution to the " #17003-D warning" . We hope that through this example, engineers can pay attention to the importance of CMD for the correct configuration of CLA memory when developing CLA, so as to avoid problems encountered in actual development and difficult to troubleshoot.
|