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.

debugging Trivaware project0 on tiva-c launchpad, using CCS

Hi, 

Is there any good tutorials on how to debug code in CCS?

I am trying to understand how to use CCS's debugging features. so I modified TivaWare project0 to enable the SysTick timer, and record the time between red LED and blue LED flashing, to try to understand how much time it takes between LED changing colors:

int main(void) {

// Setup the system clock to run at 50 Mhz from PLL with crystal reference
//
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); 

// Enable SysTick timer, 24-bit
// declare variables to store time
//
SysTickEnable();
volatile unsigned long time0, time1, time2, time3;

while(1) {

time0 = SysTickValueGet();              //get initial timer count

//
// Turn on red LED
//
GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED, RED_LED);

//
// Delay for a bit
// 5,000,000 * 3 cycles / 50 MHz = 0.3 Second, I think??
//
SysCtlDelay(5000000);

time1 = SysTickValueGet();              //get timer count after turning on red LED and waiting 5M*3 cycles

//
// Turn on blue LED
//
GPIOPinWrite(GPIO_PORTF_BASE, RED_LED|BLUE_LED, BLUE_LED);

//
// Delay for a bit
//
SysCtlDelay(5000000);

time2 = SysTickValueGet();

When I run the debugger and look at the variable values, I get:

time0 value = 0

time1 value = 12

time2 value = 240

These values don't make any sense to me, I was expecting the value to time1 to be 15M+a few cycles because of SysCtlDelay(5M)... What is stored in the value field in the variables window?

Thanks for your help,

  • doginwater said:
    These values don't make any sense to me, I was expecting the value to time1 to be 15M+a few cycles because of SysCtlDelay(5M)... What is stored in the value field in the variables window?

    The reason for the observed behavior is because the code doesn't explicitly write to the SysTick Reload Value Register (STRELOAD) via a call to the TivaWare SysTickPeriodSet(). If the SysTick Reload Value Register was already set to a small value, say 256, then the SysTick Current Value Register read by a call to SysTickValueGet() would wrap multiple times leading to small values being displayed.

    If you change the program to set the SysTick Reload Value Register to the maximum value the variable values should then make sense:

        // Set the number of clock ticks in each period of the SyStick counter to the maximum
        SysTickPeriodSet (16777216);
    
        // Enable SysTick timer, 24-bit
        // declare variables to store time
        //
        SysTickEnable();
        volatile unsigned long time0, time1, time2, time3;
    

    Bear in mind that:

    a) SysTick counts down.

    b) The SysTick counter is only 24-bits wide.

    c) The SysCtlDelay() function does NOT provide an accurate timing mechanism - see the description in the TivaWareTM Peripheral Driver Library User's Guide.