TMS320F28388D: The use of CLA math lib

Part Number: TMS320F28388D
Other Parts Discussed in Thread: SYSCONFIG, C2000WARE

Dear TI experts,

I have been working on CLA math recently and followed the procedure in the C2000ware user guide ("CLA_MATH_LIB_UG"). However, I am having trouble configuring CLA with the SysConfig tool as it generates an error:

Upon examining the compile results, it seems that there might be an issue with the cmd file.

The cmd file "CLA_MATH_LIB_UG" in C2000ware contains the following code:

void CLA_init()

{
#ifdef _FLASH
#ifndef CMDTOOL // Linker command tool is not used

extern uint32_t Cla1funcsRunStart, Cla1funcsLoadStart, Cla1funcsLoadSize;
extern uint32_t Cla1ConstRunStart, Cla1ConstLoadStart, Cla1ConstLoadSize;

//
// Copy the program and constants from FLASH to RAM before configuring
// the CLA
//
memcpy((uint32_t *)&Cla1funcsRunStart, (uint32_t *)&Cla1funcsLoadStart,
(uint32_t)&Cla1funcsLoadSize);
memcpy((uint32_t *)&Cla1ConstRunStart, (uint32_t *)&Cla1ConstLoadStart,
(uint32_t)&Cla1ConstLoadSize );


#endif //CMDTOOL
#endif //_FLASH

myCLA0_init();
}

However,there is a conflicting code in the board.c that was autogenerated by the Syscfg tool. It appears that the symbol Cla1ConstLoadSize, among others, has not been defined in the cmd file. 

Would you be able to help me resolve this issue? Because I have no idea how to revise the cmd file, which looks like very complicated.

Thanks,

Eric

  • Hi Eric,

    Is the example you are using the empty CLA lab from the training/ folder ([C2000ware install]/training/device/f2838x/empty_cla_lab)? Your project name matches this, but the training folder project should use the 2838x_FLASH_CLA_lnkcpu1 or 2838x_RAM_CLA_lnkcpu1 linker cmd files. Or is this one of the CLA library examples in the libraries/ folder ([C2000ware install]/libraries/math/CLAmath/c28/examples?

    Let me know so I can try to replicate the issue and find a fix.

    Best Regards,

    Delaney

  • You're correct that I should typically use the 2838x_FLASH_CLA_lnkcpu1 or 2838x_RAM_CLA_lnkcpu1 linker command files by default (see Fig. 1). However, these files do not allocate space for CLAmath table (see Fig. 2), which is why I switched to the f2838x_cla_c_lnk.cmd file. It would be very helpful if you could show me how to modify these two types of command files to incorporate CLAmath.

    Fig. 1 (Default CMD)

    Fig. 2 (Swapped CMD)

    Thanks,

    Eric

  • Hi Eric,

    Ok I see, I will look into this and get back to you.

    Best Regards,

    Delaney

  • Hi Eric,

    Sorry for the delay. 

    The cmd file "CLA_MATH_LIB_UG" in C2000ware contains the following code:

    I'm not sure I know which file you are referring to here, however if the source code you are using already contains the CLA initializations, there should be no need to generate the initializations again in the Sysconfig tool. To make sure I'm understanding correctly, are you:

    1. Starting with an empty CLA project from the training folder in C2000ware (or if a different C2000ware project, please provide the path)
    2. Swapping the linker cmd files with the f2838x_cla_c_lnk.cmd file since it contains allocations for the CLA Math library.
    3. Opening the Sysconfig file and trying to add a CLA module instance.
    4. Trying to build and are receiving those errors?

    It may be easier to instead use one of the library examples in [C200ware install]/libraries/math/CLAmath/c28/examples as a starting point since this uses the linker cmd file with the CLA Math tables allocated and contains the proper initialization code. For the examples, you can change the predefined symbol of the project to be "F2838x" so that it compiles for the correct device. Is there a reason you are using Sysconfig? 

    Best Regards,

    Delaney

  • Hi Delaney,

    Apologies for the typo earlier. I meant to refer to the cmd file as "f2838x_cla_c_lnk.cmd," not "CLA_MATH_LIB_UG."

    The sequence of steps you outlined is mostly correct.

    (Step 1) I started by importing an empty project from C2000ware.:

    (Step 2) To utilize the trigonometrical functions in CLA, I added cla2_math_library_datarom_fpu32_eabi.lib and F2838xCPU1_CLADATAROM_Symbols_fpu32.lib, setting the include paths as per the TI user guidance "CLA_MATH_LIB_UG."

    (Step 3) The cmd file in the imported CLA project did not allocate memory for CLA's Mathtable. To address this, I replaced it with "f2838x_cla_c_lnk.cmd" from C2000ware.

    (Step 4) Compile results: Despite these changes, I still encounter a memory allocation error during compilation:

    However, the cmd file "f2838x_cla_c_lnk" in C2000ware does not define 'Cla1func' and '.Cla1Const', as shown below:

    #if !(CLA_MATH_TABLES_IN_ROM)
    //
    //Load tables to Flash and copy over to RAM
    //
    CLA1mathTables : LOAD = FLASH11,
    RUN = RAMLS4_5,
    RUN_START(CLA1mathTablesRunStart),
    LOAD_START(CLA1mathTablesLoadStart),
    LOAD_SIZE(CLA1mathTablesLoadSize),
    PAGE = 1
    #endif

    Cla1Prog : LOAD = FLASH3,
    RUN = RAMLS0_1,
    RUN_START(Cla1ProgRunStart),
    LOAD_START(Cla1ProgLoadStart),
    LOAD_SIZE(Cla1ProgLoadSize),
    PAGE = 0

    #else

    Importantly, I need to figure out the cmd configuration since I need to integrate the CLA math function into my previous existing project (I can show it over here because of NDA) that includes lots of codes, cmd and syscfg. I can't start from scratch just to reconfigure the cmd file. So I need to understand how to modify the cmd file to ensure the CLA math function operates correctly. Additionally, I'm puzzled about the memory allocation for 'Cla1funcs', 'Cla1Prog', '.Cla1Const', and 'mathtable'. Could you provide some guidance on this?" 

    Thanks,

    Eric

  • Hi Eric,

    If you are using the CLA math tables built into the ROM on the F2838x (which the libraries you've imported assume since they are include 'datarom'), there should be no need to make any modifications to the linker cmd file. The linker cmd file tells the linker where in Flash and RAM to load/run portions of memory, however the ROM tables are hardcoded into the devices ROM and therefore don't need to be allocated by the linker. The CLA_MATH_LIB_UG user guide details this in the 4.4 Using the Tables in the CLA Data ROM section. Can you switch back to the linker cmd file from the empty_cla_lab_controlcard project and try using the CLA math function needed in your code?  If you have any issues/further questions let me know.

    Best Regards,

    Delaney

  • Hi Delaney,

    Could you provide a brief introduction to how 'Cla1funcs', 'Cla1Prog', '.Cla1Const', and 'mathtable' are allocated memory? Additionally, I'm curious about why some parts are sometimes not required.

    Thanks,

    Eric

  • Hi Eric,

    Normally, if doing a RAM build, CLA program code would be automatically loaded to RAM. If doing a flash build, then everything would initially be loaded to flash and you then would need to call the below lines of code during runtime (in your main CPU code) to copy it over to the correct section of LSRAM (that the CLA has access to):


    memcpy((uint32_t *)&Cla1funcsRunStart, (uint32_t *)&Cla1funcsLoadStart,
    (uint32_t)&Cla1funcsLoadSize);
    memcpy((uint32_t *)&Cla1ConstRunStart, (uint32_t *)&Cla1ConstLoadStart,
    (uint32_t)&Cla1ConstLoadSize );

    All of the CLA program code can be separated into constants (like global variables, static arrays etc.) and funcs (the code logic/flow). The linker cmd file needs to define which sector in Flash to initially load the CLA program code constants (Cla1ConstLoadStart), which section of RAM to copy them over to during runtime (Cla1ConstRunStart), and how much to copy over (Cla1ConstLoadSize ). It needs to do the same for the funcs and uses Cla1funcsLoadStart, Cla1funcsRunStart, Cla1funcsLoadSize defined in the linker cmd for these.

    If you were using a device without the CLA math tables hardcoded into the ROM, the linker cmd would need to also similarly define where in the flash to load them (CLA1mathTablesLoadStart), where in the LSRAM to copy them over (CLA1mathTablesRunStart), and how much to copy over (CLA1mathTablesLoadSize):

    Since the CLA math tables are quite large, the newer devices (including F2838x) have the CLA math tables hardcoded into the ROM in an area that the CLA has access to, so that they don't need to take up valuable LSRAM space. Since these tables are hardcoded into the silicon itself, the linker cmd file doesn't need to tell the compiler to load the tables to flash or RAM via JTAG at all. However, your CLA program code (in the .cla file) would still need to be moved over to LSRAM during a flash build. So, the Cla1ConstLoadStart, Cla1ConstRunStart, Cla1ConstLoadSize, Cla1funcsLoadStart, Cla1funcsRunStart, and Cla1funcsLoadSize would still need to be defined by the linker cmd. 

    Let me know if this answers your question.

    Best Regards,

    Delaney

  • Thanks very much!