This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28388D: reading and writing issue about shared variables between CPU and CLA

Part Number: TMS320F28388D

Hi Team,

Here's an issue from the customer need your help:

I'm having an issue debugging shared variables for CPU1 and CPU1.CLA.

/*CPU1 .c file */
#pragma SET_DATA_SECTION("cla_shared")
int32_t a = 10;
#pragma SET_DATA_SECTION()

//
// Configure LSRAMs
//
MemCfg_setLSRAMControllerSel(MEMCFG_SECT_LS0, MEMCFG_LSRAMCONTROLLER_CPU_CLA1);
MemCfg_setCLAMemType(MEMCFG_SECT_LS0, MEMCFG_CLA_MEM_DATA);
MemCfg_setLSRAMControllerSel(MEMCFG_SECT_LS1, MEMCFG_LSRAMCONTROLLER_CPU_CLA1);
MemCfg_setCLAMemType(MEMCFG_SECT_LS1, MEMCFG_CLA_MEM_DATA);

/*CPU1 .cmd file */
CLA_SCRATCHPAD_SIZE = 0x100;
--undef_sym=__cla_scratchpad_end
--undef_sym=__cla_scratchpad_start

CLAscratch       :
                 { *.obj(CLAscratch)
                 . += CLA_SCRATCHPAD_SIZE;
                 *.obj(CLAscratch_end) } >  RAMLS1

   .scratchpad      : > RAMLS1
   .bss_cla         : > RAMLS1
   cla_shared       : >> RAMLS1
   
/*CPU1 CLA shared.h */
extern int32_t a;

/*CPU1_CLA .cla file */
void Func1(void);

The above is the approximate configuration of my project code. When variable a is defined in cla and cpu sharing LSRAM, variable a is assigned in the c code, and then triggers CLA to execute the task. Execute the Func1 function in the CLA task to read the value of variable a, and find that the value of a has become 0 at this time. 

When I comment out the Func1 function and directly read the value of a, it is correct again, and the Func1 function only performs some if statement judgments.

Func1 is defined in the .cla file, and is directly called by the CLAtask1() function in the .cla file. The optimization level is 3. If it is turned off, the memory will overflow. 

Why this happened?

--

Thanks & Regards

Yale

  • Hi Yale,

    Can you try adding volatile keyword to variable a. Lets ensure it is not due to any compiler optimizations around that variable

    Regards,

    Veena

  • Hi Veena,

    The customer have already added it, and turned-off compiler optimization. The result is the same as the above description.

    --

    Thanks & Regards

    Yale

  • Is it possible to share the Func1 code?

    Regards,

    Veena

  • if((claPara->RunMode != 3) && (RunState ==2) && !FaultState)
    	{
    		if(claPara->spd.Err > claPara->Speed)
    		{
    			claPara->protect.Cnt++;
    			if(claPara->protect.Cnt >= 1600) 
    			{
    				GPIO_writePin(mGPIO_PIN_LED12, 0);
    				FaultState = claPara->protect.mark;
    			}
    		}
    		else
    		{
    			if(claPara->protect.Cnt > 0)
    			{
    				ptAxis_claPara->protect.Cnt--;
    			}
    		}
    	}

    claPara is a structure variable defined in cla_shard, and claPara->protect.mark is an enumeration variable. A non-0 value has been set when the CPU1 parameter is initialized, and no writing operations are performed. But when the FaultState = claPara->protect.mark; code is executed, the FaultState variable value is 0, and the same is true for the claPara->Speed variable. However, some variables in the claPara structure can be read normally.