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.

CCS/TMS320C5535: Strange GPT function behavior

Part Number: TMS320C5535

Tool/software: Code Composer Studio

I'm developing on a TMS320C5535 using the XDS110 debugger, the C5000 chip support library, and Code Composer version: 8.2.0.00007. I'm trying to initialize the general purpose timer (GPT0) peripheral to blink an LED and I'm coming across a strange behavior in my code. I originally had: 

CASE 1

/////////////* Main Function */////////////
int main(void)
{
CSL_Status SYS_status;
/////////////* System Level Initializations *///////////// SYS_status = SYS_PLL_LDO_init(); SYS_status = SYS_EBSR_init(); SYS_status = SYS_GPIO_init(); SYS_status = SYS_I2C_init(); SYS_status = SYS_SPI_init(); SYS_status = SYS_UART_init(); SYS_status = SYS_RTC_init(); SYS_status = SYS_GPT_init(); /* Initialize Interrupt Vector table */ IRQ_setVecs((Uint32) (&VECSTART)); /////////////* Initialize ISRs *///////////// IRQ_globalDisable(); // Disable CPU interrupts IRQ_clearAll(); // Clear any pending interrupt IRQ_disableAll(); // Disable all interrupts IRQ_plug(GPIO_EVENT, &GPIO_isr); IRQ_plug(INT1_EVENT, &ADS_DRDY_isr); IRQ_plug(RTC_EVENT, &RTC_isr); IRQ_plug(TINT_EVENT, &GPT_isr); // IRQ_enable(GPIO_EVENT); // Enable interrupt // IRQ_enable(INT1_EVENT); // Enable interrupt // IRQ_enable(RTC_EVENT); // Enable interrupt IRQ_enable(TINT_EVENT); IRQ_globalEnable(); // Enable CPU interrupts SYS_status = GPT_start(hGpt0); /////////////* Infinite Loop *///////////// while (1) { } }

where SYS_GPT_init() is:

CSL_Status SYS_GPT_init(void){

    CSL_Status status;
    CSL_Config hwConfig;
    CSL_GptObj gptObj;

    hGpt0 = GPT_open(GPT_0, &gptObj, &status);
//    hGpt1 = GPT_open(GPT_1, &gptObj, &status);
//    hGpt2 = GPT_open(GPT_2, &gptObj, &status);

    status |= GPT_reset(hGpt0);
//    status |= GPT_reset(hGpt1);
//    status |= GPT_reset(hGpt2);

    // Setup GPT0 to 1 second to blink LEDs
    hwConfig.autoLoad = GPT_AUTO_ENABLE;
    hwConfig.ctrlTim = GPT_TIMER_ENABLE;
    hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1;// 100Mhz/4 = 25Mhz
    hwConfig.prdLow =  0x7840;              // Period 25,000,000 ticks
    hwConfig.prdHigh = 0x017D;              // So 1 second interval

    /* Configure the GPT module */
    status |= GPT_config(hGpt0, &hwConfig);

    return status;
}

I expect the GPT to trigger an LED through an ISR (not shown) but nothing happens. 

CASE 2:

However, when I remove the SYS_GPT_init() function and put the contents of the function directly into main():

See line 13: SYS_GPT_init() was commented out

See lines 15-35: the code from SYS_GPT_init() is inserted there

int main(void)
{
    CSL_Status SYS_status;

    /////////////* System Level Initializations */////////////
    SYS_status = SYS_PLL_LDO_init();
    SYS_status = SYS_EBSR_init();
    SYS_status = SYS_GPIO_init();
    SYS_status = SYS_I2C_init();
    SYS_status = SYS_SPI_init();
    SYS_status = SYS_UART_init();
    SYS_status = SYS_RTC_init();
//    SYS_status = SYS_GPT_init();

    CSL_Status status;
    CSL_Config hwConfig;
    CSL_GptObj gptObj;

    hGpt0 = GPT_open(GPT_0, &gptObj, &status);
//    hGpt1 = GPT_open(GPT_1, &gptObj, &status);
//    hGpt2 = GPT_open(GPT_2, &gptObj, &status);

    status |= GPT_reset(hGpt0);
//    status |= GPT_reset(hGpt1);
//    status |= GPT_reset(hGpt2);

    // Setup GPT0 to 1 second to blink LEDs
    hwConfig.autoLoad = GPT_AUTO_ENABLE;
    hwConfig.ctrlTim = GPT_TIMER_ENABLE;
    hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1;// 100Mhz/4 = 25Mhz
    hwConfig.prdLow =  0x7840;              // Period 25,000,000 ticks
    hwConfig.prdHigh = 0x017D;              // So 1 second interval

    /* Configure the GPT module */
    status |= GPT_config(hGpt0, &hwConfig);

    /* Initialize Interrupt Vector table */
    IRQ_setVecs((Uint32) (&VECSTART));

    /////////////* Initialize ISRs */////////////
    IRQ_globalDisable();    // Disable CPU interrupts
    IRQ_clearAll();         // Clear any pending interrupt
    IRQ_disableAll();       // Disable all interrupts
    IRQ_plug(GPIO_EVENT, &GPIO_isr);
    IRQ_plug(INT1_EVENT, &ADS_DRDY_isr);
    IRQ_plug(RTC_EVENT, &RTC_isr);
    IRQ_plug(TINT_EVENT, &GPT_isr);
//    IRQ_enable(GPIO_EVENT); // Enable interrupt
//    IRQ_enable(INT1_EVENT); // Enable interrupt
//    IRQ_enable(RTC_EVENT);  // Enable interrupt
    IRQ_enable(TINT_EVENT);
    IRQ_globalEnable();     // Enable CPU interrupts

    SYS_status = GPT_start(hGpt0);

    /////////////* Infinite Loop */////////////
    while (1)
    {

    }
}

The LED DOES begin to work and blinks as expected in CASE 2. 

I have done a forward declaration for all functions already, so that should not be a problem. 

Why is it that the LED/GPT does not work in case 1, but DOES work in case 2? Both cases SHOULD produce the same results because the code is exactly the same. The only difference between the two cases is that case 1 calls SYS_GPT_init() but case 2 does not call SYS_GPT_init().

  • Hi Eddie,

    Could you post the CCS console output?

    Regards,
    Tsvetolin Shulev
  • Tsvetolin , 

    Thank you for getting back to me. 

    This is the console output for Case 1:

    **** Build of configuration Debug for project Puck_main ****
    
    "C:\\ti\\ccsv8\\utils\\bin\\gmake" -k -j 8 all -O 
     
    Building file: "../main.c"
    Invoking: C5500 Compiler
    "C:/ti/ccsv8/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --include_path="C:/ti/c55_lp/c55_csl_3.08/inc" --include_path="C:/Users/Inno/Desktop/puck_workspace/Puck_main" --include_path="C:/ti/ccsv8/tools/compiler/c5500_4.4.1/include" --define=c5535 --display_error_number --diag_warning=225 --ptrdiff_size=16 --preproc_with_compile --preproc_dependency="main.d_raw"  "../main.c"
    "../main.c", line 94: warning #552-D: variable "SYS_status" was set but never used
    Finished building: "../main.c"
     
    Building target: "Puck_main.out"
    Invoking: C5500 Linker
    "C:/ti/ccsv8/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --define=c5535 --display_error_number --diag_warning=225 --ptrdiff_size=16 -z -m"Puck_main.map" --stack_size=0x6000 --heap_size=0x1E80 -i"C:/ti/ccsv8/tools/compiler/c5500_4.4.1/lib" -i"C:/ti/ccsv8/tools/compiler/c5500_4.4.1/include" -i"C:/ti/c55_lp/c55_csl_3.08/ccs_v6.x_examples/C55XXCSL_LP" --reread_libs --display_error_number --warn_sections --xml_link_info="Puck_main_linkInfo.xml" --rom_model --sys_stacksize=0x200 -o "Puck_main.out" "./ADS1310A2.obj" "./GPS.obj" "./LSM303C_driver.obj" "./XBee.obj" "./main.obj" "../C5535.cmd"  -l"C:/ti/c55_lp/c55_csl_3.08/ccs_v6.x_examples/C55XXCSL_LP/Debug/C55XXCSL_LP.lib" -llibc.a 
    <Linking>
    Finished building target: "Puck_main.out"
     
    
    **** Build Finished ****

    This is the console output for Case 2:

    **** Build of configuration Debug for project Puck_main ****
    
    "C:\\ti\\ccsv8\\utils\\bin\\gmake" -k -j 8 all -O 
     
    Building file: "../main.c"
    Invoking: C5500 Compiler
    "C:/ti/ccsv8/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --include_path="C:/ti/c55_lp/c55_csl_3.08/inc" --include_path="C:/Users/Inno/Desktop/puck_workspace/Puck_main" --include_path="C:/ti/ccsv8/tools/compiler/c5500_4.4.1/include" --define=c5535 --display_error_number --diag_warning=225 --ptrdiff_size=16 --preproc_with_compile --preproc_dependency="main.d_raw"  "../main.c"
    "../main.c", line 94: warning #552-D: variable "SYS_status" was set but never used
    Finished building: "../main.c"
     
    Building target: "Puck_main.out"
    Invoking: C5500 Linker
    "C:/ti/ccsv8/tools/compiler/c5500_4.4.1/bin/cl55" -v5515 --memory_model=large -g --define=c5535 --display_error_number --diag_warning=225 --ptrdiff_size=16 -z -m"Puck_main.map" --stack_size=0x6000 --heap_size=0x1E80 -i"C:/ti/ccsv8/tools/compiler/c5500_4.4.1/lib" -i"C:/ti/ccsv8/tools/compiler/c5500_4.4.1/include" -i"C:/ti/c55_lp/c55_csl_3.08/ccs_v6.x_examples/C55XXCSL_LP" --reread_libs --display_error_number --warn_sections --xml_link_info="Puck_main_linkInfo.xml" --rom_model --sys_stacksize=0x200 -o "Puck_main.out" "./ADS1310A2.obj" "./GPS.obj" "./LSM303C_driver.obj" "./XBee.obj" "./main.obj" "../C5535.cmd"  -l"C:/ti/c55_lp/c55_csl_3.08/ccs_v6.x_examples/C55XXCSL_LP/Debug/C55XXCSL_LP.lib" -llibc.a 
    <Linking>
    Finished building target: "Puck_main.out"
     
    
    **** Build Finished ****

    They are both identical.

    I also checked the .map file for case 1 and case 2 and they are also both identical. I included the .map file and the .cmd file I'm using in the following zip folder:  map and command file.zip

    Another issue I'm noticing is in Case 2 I have:

        hGpt0 = GPT_open(GPT_0, &gptObj, &status);
    //    hGpt1 = GPT_open(GPT_1, &gptObj, &status);
    //    hGpt2 = GPT_open(GPT_2, &gptObj, &status);
    
        status |= GPT_reset(hGpt0);
    //    status |= GPT_reset(hGpt1);
    //    status |= GPT_reset(hGpt2);

    When I keep case 2 like this, the LED (which is connected to the gpt0 ISR) blinks as expected. However, when I uncomment the initialization code for gpt1 and gpt2:

        hGpt0 = GPT_open(GPT_0, &gptObj, &status);
        hGpt1 = GPT_open(GPT_1, &gptObj, &status);
        hGpt2 = GPT_open(GPT_2, &gptObj, &status);
    
        status |= GPT_reset(hGpt0);
        status |= GPT_reset(hGpt1);
        status |= GPT_reset(hGpt2);

    The LED does NOT blink anymore. I'm unsure if this is related to the original problem, but decided to let you know in case it helps narrow the source of this strange behavior. Please let me know if there is anything else I can do to help. 

    Best, 

    Eddie

  • Eddie,

    Could you add result verification for hGpt0 = GPT_open(...) and status |= GPT_reset(hGpt0); as:

    	/* Open the CSL GPT modules */
    	hGpt0 = GPT_open (GPT_0, &gptObj, &status);
    	if((NULL == hGpt0) || (CSL_SOK != status))
    	{
    		printf("GPT0 Open Failed\n");
    		return (CSL_TEST_FAILED);
    	}
    	else
    	{
    		printf("GPT0 Open Successful\n");
    	}
    	/* Reset the GPT modules */
    	status = GPT_reset(hGpt0);
    	if(CSL_SOK != status)
    	{
    		printf("GPT0 Reset Failed\n");
    		return (CSL_TEST_FAILED);
    	}
    	else
    	{
    		printf("GPT0 Reset Successful\n");
    	}

    It is important to see whether GPT module has been opened and reset successfully. Share the results for both cases please.

    Regards,

    Tsvetolin Shulev

  • Tsvetolin, 

    I have already verified the return status of GPT_open(), GPT_reset(), GPT_config(), and GPT_start() using the watch window in debug mode. They are all 0 for both cases, which means no errors have occurred anywhere.

    After spending more time trying to debug this issue, I found a pattern. This strange bug only gets stranger:

    CASE 1: Has GPT_open(), GPT_reset(), and the GPT_config() inside a function called SYS_GPT_init(void). However, GPT_start(hGpt0) is inside main() and NOT SYS_GPT_init(). GPT_start() is in the scope of main() but the other functions are not. The LED does NOT blink in this case, which means the GPT is not working.

    CASE 2: Has GPT_open(), GPT_reset(), and the GPT_config() inside main() with GPT_start(hGpt0) also in main(). They are all within the same scope of main. The LED DOES blink in this case, which means the GPT is working.

    I made a new case called CASE 3:

    CSL_Status SYS_GPT_init(void){
    
        CSL_Status status;
        CSL_Config hwConfig;
        CSL_GptObj gptObj;
    
        hGpt0 = GPT_open(GPT_0, &gptObj, &status);
    //    hGpt1 = GPT_open(GPT_1, &gptObj, &status);
    //    hGpt2 = GPT_open(GPT_2, &gptObj, &status);
    
        status |= GPT_reset(hGpt0);
    //    status |= GPT_reset(hGpt1);
    //    status |= GPT_reset(hGpt2);
    
        // Setup GPT0 to 1 second to blink LEDs
        hwConfig.autoLoad = GPT_AUTO_ENABLE;
        hwConfig.ctrlTim = GPT_TIMER_ENABLE;
        hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1;// 100Mhz/4 = 25Mhz
        hwConfig.prdLow =  0x7840;              // Period 25,000,000 ticks
        hwConfig.prdHigh = 0x017D;              // So 1 second interval
    
        /* Configure the GPT module */
        status |= GPT_config(hGpt0, &hwConfig);
        status |= GPT_start(hGpt0);
    
        return status;
    }

    CASE 3 is exactly the same as CASE 1 but the only difference is where GPT_start(hGpt0) is called (see line 24 above). In CASE 1 GPT_start(hGpt0) is in main(). In CASE 3 GPT_start(hGpt0) is in SYS_GPT_init(). 

    CASE 3 DOES have the LED blinking, which means the GPT is working. 

    So what does this tell me? I think it means that GPT_start(hGpt0) MUST be in the same function as GPT_open(), GPT_reset(), and the GPT_config(). If GPT_start(hGpt0) is not in the same function, then the GPT will not work. Can you verify if this assumption is correct or why it's happening? Maybe it has to do with how the C5535 or the compiler is managing the stack memory?

    EDIT:

    In debug mode, console sometimes reports:

    C55xx: Trouble Reading Memory Block at 0x80010 on Page 1 of Length 0x1: (Error -1143 @ 0x80010) Device core was hung. The debugger has forced the device to a ready state and recovered debug control, but your application's state is now corrupt. You should have limited access to memory and registers, but you may need to reset the device to debug further. (Emulation package 8.0.903.6) 
    C55xx: Trouble Reading Memory Block at 0x80810 on Page 1 of Length 0x1: (Error -1143 @ 0x80810) Device core was hung. The debugger has forced the device to a ready state and recovered debug control, but your application's state is now corrupt. You should have limited access to memory and registers, but you may need to reset the device to debug further. (Emulation package 8.0.903.6) 
    

    At the start of main(), even before I click on the "Resume" button (F8). Hopefully this is helpful information. 

    Best,

    Eddie

  • Eddie,

    Your assumption is correct - the sequence of GPT commands should be in a same function as you make this in Case 3. Seems this solving the first issue with GPT timer.
    The second issue - error displayed in debug mode:
    C55xx: Trouble Reading Memory Block at 0x80010 on Page 1 of Length 0x1: (Error -1143 @ 0x80010) ...
    is strange because the error -1143 indicates the CPU is hanging on a memory access or a pipeline stall. Probably it is related with JTAG debugger and you can set a break point in the beginning of main() and debug step by step to localize which command causes the error.
    A similar problem is discussed at:
    e2e.ti.com/.../767328
    Also some clarifications about "Error -1143" can be found at:
    dev.ti.com/.../

    Regards,
    Tsvetolin Shulev