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.

TMS320F280049C: Code is not debugging as expected for CLA

Part Number: TMS320F280049C
Other Parts Discussed in Thread: CCSTUDIO, C2000WARE

Tool/software:

Hi Team,

I wrote a cla code which calls a test case function and do some conversions. The code is building and while debugging is not happening as expected in CLA. After 2 to 3 function calls, the debug is going to asm file (watch dog).

Here, i am attaching the cla file and main file.

Please let me know if any file/information is required.

Thanks and regards,

Rajesh

/*
Filename: main.c
*/

#include "device.h"
void breakfunc();

int main(void)
{
    Device_setup();


       //
        // Enable ADC interrupt
        //
        ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);
    #ifndef CLA_CPU
        Interrupt_enable(INT_ADCA1);
    #endif

        //
        // Enable the clock to synchronously enable all the ePWMs
        //
       SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

       breakfunc();
//while(1);
    return 0;
}

void breakfunc()
{
    volatile int bp=0;
}

/*
Filename: test.cla
*/

#include <stdio.h>

#include <device.h>

#define MSG_SIZE 32

int testbed_out;
int history_in_target;
int fileid;
int Configured;
char message[MSG_SIZE];
int exit_reached;
int iter_message;
char *qqqqone;
int test_return;

void upload (void)
{
	  int iter;
      iter_message=0;
      for ( iter=0; iter<MSG_SIZE; iter++ ) {
           message[iter] = 0;
      }
}

void port_init (void)
{
	  int i;
	  Configured=0;
      qqqqone="%6d%6d\n";
      for( i=0;i<MSG_SIZE;i++)
      {
      message[i]=0;
      }
	  upload();
	  iter_message=0;
	  message[0]=0;
	  Configured=1;
}

void c_exit()
{
	Configured = 1;
}

void port_close()
{
	exit_reached=1;
	upload();
	c_exit();
}

int port_configured (void) {
  return Configured;
}

int port_open (void) {
  fileid = 1;
  /* 
   * Protect against the case with just a single main and in white box
   * where the port can get initialised twice 
   */
  if ( port_configured() == 0 ) {
    port_init();
  }
  /* Need to stop ldra_port_close from being optimised out */
  if ( port_configured() == 0 ) {
    port_close();
  }
  return fileid;
}

void port_write(const char *pMsg)
{
	if ( pMsg != 0 ) {
    /* Output characters in string until 0 terminator */
    while (*pMsg != 0 ) {
      /* Write characters to the buffer */
      message[iter_message] = *pMsg;
      iter_message++;
        
      if ( iter_message >= MSG_SIZE ) {
        /* Upload the entire buffer in one go when full */
        upload();
      }
      /* Point to next character */
      pMsg++;
    }
    message[iter_message]=0;
  }
}

int port_initialisation(void)
{
/* ****4 New test case initialisation */

  testbed_out = port_open();
  return 1;

} /* end of port_initialisation */

void output (char *fmt,int start,int new_line)
{
  port_write (fmt);

  if (new_line)
  {
    port_write ("\n");
  }
}

char abs (const int n) 
{
  int v;
  if ( n < 0 ) {
    v = -n;
  } else {
    v = n;
  }
  return v;
}

void char_push_front(char* buf, int i, const char add)
{
  /* Move any previous values */
  int k = i-1;

  while (k >= 0) {
    buf[i] = buf[k];
    i--;
    k--;
  }

  /* Add the next value */
  buf[0]=add;
}

int int_sprintf(char* buf, const char *fmt, const int ap)
{
  int i = 0;
  int ret = 0;
  int value = ap;

  /* null terminate the array */
  buf[i]=0;
  i++;

  if (value == 0) {
    char_push_front(buf,i,'0');
    i++;
  }

  while (value != 0) {
    /* Compute the next character  */
    char next = abs(value % 10) + '0';

    /* Add to the existing array */
    char_push_front(buf,i,next);

    /* Calculate the next step */
    value = value / 10;
    i++;
  }

  /* If the original value was negative, add the sign */
  if (ap < 0) {
    char_push_front(buf,i,'-');
    i++;
  }

  /* return number of printed characters minus the null terminator */
  ret = i-1;
  return ret;
}

int signed_int_convert(const signed int value, char* res)
{
	int_sprintf (res,"%d", value);
	return 1;
}

int int_strcmp (const char* a, const char* b)
{
  int ret = 0;

  if (a == (const char*)(0) && b == (const char*)(0)) {
    ret = 0;
  } else if (a == (const char*)(0)) {
    ret = 1;
  } else if (b == (const char*)(0)) {
    ret = -1;
  } else {
    while (!(ret = *(unsigned char*)a - *(unsigned char*)b) && *b) {
      ++a;
      ++b;
    }

    if (ret < 0 ) {
      ret = -1;
    } else if (ret > 0) {
      ret = 1;
    }
  }
  return ret;
}

int string_compare (char* a, char* b)
{
  int equal = 0;

  if (a == (char*)(0) && b == (char*)(0)) {
    equal = 1;
  } else if (a != (char*)(0) && b != (char*)(0)) {
    equal = int_strcmp(a,b) == 0;
  }
  return equal;
}

int int_convert(int expected_value,int actual_value,char * name,
                             char * svalue,char df,int convert,int compare,
                             int convert_ok,char * expstr)
{
  char testbed_buff[64];
  int variable_converted = 1;
  int variable_passed = 1;
  int var_exception_raised = 0;
  char str[3];
  int saved_history_in_target = history_in_target;
  testbed_buff[0] = '\0';
  str[0] = df;
  str[1] = ' ';
  str[2] = '\0';
    if (convert == 1)
    {
      variable_converted = signed_int_convert (actual_value,testbed_buff);
    }
  if (var_exception_raised == 1)
  {
      output (name,0,1);
      variable_passed = 0;
  }
  else
  {
    if (convert > 0)
    {
       output ("pass",0,1);
    }
    else
    {
       output ("fail",0,1);
    }
    if (variable_converted == 1)
    {
        variable_passed = 0;
        if (compare == 1)
        {
          if (expected_value != actual_value)
          {
            variable_passed = 0;
          }
          else
          {
            variable_passed = 1;
          }
        }
    }
    else
    {
      if (convert_ok == 0)
      {
        variable_passed = string_compare (expstr,testbed_buff);
      }
      else
      {
        variable_passed = 0;
      }
    }
    if (variable_passed == 1)
    {
      output ("P ",1,0);
    }
    else
    {
      output ("F ",1,0);
    }
    history_in_target = 0;
    if (variable_converted == 1)
    {
      output ("V",0,0);
    }
    else
    {
      output ("F",0,0);
    }
    if (convert > 0)
    {
      output (" ",0,0);
      output (testbed_buff,0,0);
    }
    output ("",0,1);
    history_in_target = saved_history_in_target;
  }
  return variable_passed;
} 

int unit_test()
{
	return 0;
}

int test_case_1()
{
	int passed=1;
	int exception_raised=1;
	output("need to print",1,1);
	test_return=unit_test();
	if (exception_raised == 1)
    {
       output ("pass",1,1);
    }
    else
    {
       output ("fail",1,1);
    }
	if (int_convert(test_return,test_return,"%",
                        "",'O',1,1,
                        1,"") == 0)
    {
       passed = 0;
    }
	return passed;
}

void initialise()
{
    testbed_out=0;
    fileid=0;
	history_in_target = 1;
	Configured=0;
}

void test_cla()
{
    //
    // Uncomment to halt and debug
  __mdebugstop();
 initialise();
  if (port_initialisation())
  {
/*
 * Execute new test case
 */
    test_case_1 ();
  }
  port_close();
  return ;
}

  • Hi Kandala,

    Can you explain a little more about the set up? 

    You have a CLA task being defined in a .cla file - what trigger is being used for the CLA task?

    Did you base your code on one of the CLA examples?

    Best Regards,

    Delaney

  • Hi Delaney,

    Thanks for your reply.

    Here, i am attaching the whole project folder which has target configuration file and all other information regarding project settings.

    Yes, based on CLA example available for TMS320F280049C, the attached project is created.

    I created 2 more projects with 1 or 2 functions in CLA and those projects are working fine.

    If you need any other information, please let me know.

    Thanks and Regards,

    Rajesh.

    CLA code working and not working

  • Hi Kandala,

    Thank you for your response. Are you able to describe/summarize your setup here? Generally, direct code debugging is out of the scope of what we can provide on E2E. But if you describe your setup and/or the issue in more detail I can see if anything sounds incorrectly configured and try to provide some guidance.

    Best Regards,

    Delaney

  • Hi Delaney,

    The settings and setup details are available in the attached link (Prev. reply) where .ccsproject, settings, .cproject etc., for both working and not working projects.

    Can you please let me know what else settings/setup details you want so that i can provide?

    My actual issue is CLA debugging is not happening properly with one project while the other one is working fine with same project and debug settings.

    If required, i can do webex or teams meeting with you to show the issue.

    My setup details:

       Using ccstudio version 12.7.1.00001 with C2000 compiler and C2000Ware_5_02_00_00 for hardware support.

       Using TMS320F280049C hardware and calling CLA using ADC interrupt.

    Attaching the link where the settings files are present for both projects (working and non-working):

    CLA_settings_files_with_project

    Regards,

    Rajesh

  • Hi Rajesh,

    Thank you for providing the demo video recording. After viewing the video, I believe I see the issue. Generally, in CLA programs you want to avoid too many nested function calls, as this will slow down the CLA program and the scratchpad (which can be thought of as the CLA's stack) could overflow. In older versions of the CLA peripheral, a maximum of two function calls were allowed, although this requirement has been removed on the CLA for F28004x.

    It looks like when the port_init() function is called, a scratchpad frame is never placed in the scratchpad memory (meaning it is likely full) and the CLA doesn't know how to return from the function call since there is no return address in the scratchpad. I would recommend removing the nested function calls and limiting your program to one level of function nesting maximum (the CLA can branch to a task and that task can call one other function, then return). For example, you can call port_initialisation() inside your task, but contain all of the code in that function and avoid branching to any more functions from port_initialisation(). Please try this out and upvote this response if it fixes the issue.

    Best Regards,

    Delaney

  • Hi Delaney,

    But in my map file, i can see all the functions in scratchpad memory. You can find the map file in prev. attached link. I also observed that nested function calls happened for one of the project.

    Attaching the screenshot of scratchpad memory for your reference.

    Regards,

    Rajesh

  • Hi Delaney,

    Thanks for your help with nested function input which worked in my case.

    I followed your inputs for nested function and tried to reduce the nested functions. With that i am able to debug till certain level where i had a math calculation checking in if condition like

         if ((value % 10) > 0)

    In this particular place, the debug is going to somewhere and not returning to function.

    Attaching the code and video of debugging for your reference.

    #include <stdio.h>
    
    #include <device.h>
    
    void test_cla()
    {
        //
        // Uncomment to halt and debug
      __mdebugstop();
    
      int value = 35, next;
    	  	 if ( (value % 10) < 0 ) {
    	  	       next = -(value % 10) + '0';
    	  	     } else {
    	  	       next = (value % 10) + '0';
    	  	     }
    }
    

    Remaining all settings w.r.t project and debug are same.

    Regards,

    Rajesh

  • Hi Rajesh,

    Glad to hear that my previous suggestions about the nesting functions were helpful. 

    For this issue, this means that CCS is looking for a source file and can't find it. Just to verify, what is the warning on line 11?

    The modulus (%) functionality can be used from a .cla files but let me consult the other CLA expert to see if any additional includes are needed to get it working.

    Best Regards,

    Delaney

  • Hi Delaney,

    Did you get any solution for the above query for modulus operation?

    Regards,

    Rajesh

  • Hi Kandala,

    The team is currently without power because of hurricane Beryl that hit Texas on Monday, so I haven't had a chance to consult the other expert. I will get back to you with a response as soon as we are back up and running and in office. I apologize for the inconvenience.

    Best Regards,

    Delaney

  • Hi Kandala,

    I apologize for the delay. Can you try clicking "Locate File" and navigating to the CCS compiler install folder: C:/ti/ccs1270/ccs/tools/compiler/ti-cgt-c2000_22.6.1.LTS? This will allow CCS to locate the modulus operation source code on your local PC and should allow you to step over that line in the debugger. This CCS error does not mean that there is any issue with the code but rather that CCS itself does not know how to locate the proper files to show you the code execution when debugging.

    Best Regards,

    Delaney