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.

Aplication crashes when using two timers and I2C (EK-TM4C123GXL)

Other Parts Discussed in Thread: EK-TM4C123GXL, SYSBIOS

Hardware: Tiva-C evaluation kit EK-TM4C123GXL

I am testing two modules in my application. One of them uses a timer and the I2C, the other uses another timer. The two modules run well when tested separately, but if I run them together, the application crashes and I can not find the reason for this. CCS does not give me any useful information, I do not know how to configure it.

The first module is a real time clock using DS1307. A task reads the IC through I2C every 10 ms. The timing is determined by the timer module, which posts an event to unblock the task.

The second module is a wrapper to a 16x2 LCD display. It uses a timer to set the appropriate timing for the commands sent to the display.

For testing purposes, I create an instance of the RTC module in a task context, wait for 5 seconds, and create the LCD module. In the RTC reading just after LCD instance creation, when the function "I2C_Transfer" is called, the application crashes, giving this:

e: 0x20000fd8.
Task stack size: 0x568.
R0 = 0x00000001  R8  = 0x0000fa94
R1 = 0x00000068  R9  = 0x0000fa84
R2 = 0x000000d0  R10 = 0x0000fa8c
R3 = 0x00004a88  R11 = 0x0000fa90
R4 = 0x20003f60  R12 = 0x00007ec9
R5 = 0x0000f454  SP(R13) = 0x20001488
R6 = 0x00000001  LR(R14) = 0x000049f5
R7 = 0x0000fa88  PC(R15) = 0x000049f6
PSR = 0x21000000
ICSR = 0x00456803
MMFSR = 0x00
BFSR = 0x04
UFSR = 0x0000
HFSR = 0x40000000
DFSR = 0x0000000b
MMAR = 0xe000ed34
BFAR = 0xe000ed38
AFSR = 0x00000000
Terminating execution...

I tried to trace the execution of the task until the crash moment is reached, the call sequence is the following:

I2C_transfer -> I2CTiva_transfer -> I2CTiva_primeTransfer -> I2CMasterSlaveAddrSet

The crash occurs in the following line of code of the file i2c.c:

1140:    HWREG(ui32Base + I2C_O_MSA) = (ui8SlaveAddr << 1) | bReceive;

Stepping through assembly, the function "ti_sysbios_family_arm_m3_Hwi_excHandlerAsm__I" is called. I do not know where is the source code for this function, so I could not go any further.

I noticed that if I do not create the timer module in the LCD code, no error occurs.

I spent days trying to fix this, I am going crazy. Is there anything I can do to find out more about this error?

Thanks

  • * UPDATE *


    Replaced the timer instance in the RTC module by calls to Task_sleep(). Still crashing.

    In the timer instantiation code "Timer_create()", replaced "Timer_ANY" by 4. Not crashing anymore.

    Tested all possible values for ID parameter. Application crashes if ID < 4, it works if ID is 4 or 5. After this point I remembered that for the RTC timer I was using 4 as ID, this is why it was working all the time.


    Is there a reason for the I2C module not work when timer 0, 1, 2 or 3 are enabled?

  • Hi Lucas,

    Can you please clarify, what version of TI-RTOS and CCS are you currently using?

    Does the LCD create the timer using SYS/BIOS APIs?  What Timer IDs are you using to create the Timers?  Would it be possible for you to post some code snips?

    Regards,

    -- Emmanuel

  • Hi, I stopped working in this application for a while, but now I am back to work. I have made some inprovements in the code and fixed some bugs, but the fault related to I2C and Timers still occurs.

    I am using TivaWare lib v 2.1.0.12573c and SYSBIOS v 6.41.00.26.

    Scenario: I use a Timer module in some part of the code, and it is instantiated in the main function before Bios_Start():

    		Timer_Params l_timer_prms;
    		Error_Block l_eb;
    		Error_init(&l_eb);
    		Timer_Params_init(&l_timer_prms);
    		l_timer_prms.periodType = Timer_PeriodType_MICROSECS;
    		l_timer_prms.runMode = Timer_RunMode_CONTINUOUS;
    		l_timer_prms.startMode = Timer_StartMode_USER;
    		l_timer_prms.arg = (UArg) l_instance;
    		l_timer_prms.period = period;
    		l_instance->timer = Timer_create(MY_TIMER_ID, tick_timer_fxn, &l_timer_prms, &l_eb);
    		if (l_instance->timer == NULL)
    			l_alloc_error = TRUE;
    		else
    			l_resources |= RES_TIMER;
    

    And in other part of the code I create an I2C module, as follows. The I2C module is created in a Task context.

    		I2C_Params l_i2c_params;
    		I2C_Params_init(&l_i2c_params);
    		l_i2c_params.bitRate = I2C_400kHz;
    		m_i2c = I2C_open(I2C_PERIPHERAL_NUM, &l_i2c_params); // I2C_PERIPHERAL_NUM = 0
    

    If MY_TIMER_ID is >= 4, the application works perfect. If MY_TIMER_ID < 4, a crash occurs when the function I2C_open() is called.

    I followed the execution with the debugger, the sequence of calls is as follows:

    I2C_Handle I2C_open(unsigned int index, I2C_Params *params)
    I2C_Handle I2CTiva_open(I2C_Handle handle, I2C_Params *params)
    void I2CMasterInitExpClk(uint32_t ui32Base, uint32_t ui32I2CClk, bool bFast);
    I2CMasterInitExpClk()
    I2CMasterEnable()
    (instruction) 6A03     LDR             R3, [R0, #32]
    ti_sysbios_family_arm_m3_Hwi_excHandlerAsm__I()

    The exception information given by ROV:

    Decoded exception,
    Decoded,Hard Fault: FORCED: BUSFAULT: PRECISERR.Data Access Error. Address = 0x40021020
    Exception context,
    $addr,0x200033e8
    $type,ti.sysbios.family.arm.m3.Hwi.ExcContext
    threadType,ti.sysbios.BIOS.ThreadType_Task
    threadHandle,0x20002fe8
    threadStack,0x20003038
    threadStackSize,1504
    r0,0x40021000
    r1,0x4c4b400
    r2,0x1
    r3,0x13c80
    r4,0x40021000
    r5,0x4c4b400
    r6,0x1
    r7,0x0
    r8,0x0
    r9,0x200035d8
    r10,0x1
    r11,0xffffffff
    r12,0x1398c
    sp,0x200034c0
    lr,0xc131
    pc,0xc118
    psr,0x1000000
    ICSR,0x400803
    MMFSR,0x0
    BFSR,0x82
    UFSR,0x0
    HFSR,0x40000000
    DFSR,0xb
    MMAR,0x40021020
    BFAR,0x40021020
    AFSR,0x0
    Exception call stack,
    0    I2CMasterEnable() at Hwi.c:0,PC = 0x0000C118 FP = 0x200034C0
    1    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x200034C0
    2    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x00011334 FP = 0x200034C8
    3    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x200034C8
    4    I2CTiva_open(struct I2C_Config *, struct I2C_Params *) at I2CTiva.c:512,PC = 0x00005ED8 FP = 0x200034D0
    5    I2C_open(unsigned int, struct I2C_Params *) at I2C.c:103,PC = 0x00005DF8 FP = 0x20003530
    6    sys_init_modules() at system.c:78,PC = 0x00003A32 FP = 0x00000008
    7    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x4B25468C FP = 0x000000B8
    8    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000B8
    9    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x4B25468C FP = 0x000000C0
    10    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000C0
    11    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x1001F240 FP = 0x000000C8
    12    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000C8
    13    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x7080F04E FP = 0x000000D0
    14    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000D0
    15    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x47706188 FP = 0x000000D8
    16    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000D8
    17    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x8114F3EE FP = 0x000000E0
    18    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000E0
    19    _c_int00() at EK_TM4C123GXL.c:0,PC = 0xF3822200 FP = 0x000000E8
    20    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000E8
    21    _c_int00() at EK_TM4C123GXL.c:0,PC = 0xF8DFB402 FP = 0x000000F0
    22    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000F0
    23    _c_int00() at EK_TM4C123GXL.c:0,PC = 0xBC01BC00 FP = 0x000000F8
    24    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x000000F8
    25    _c_int00() at EK_TM4C123GXL.c:0,PC = 0xF3812102 FP = 0x00000100
    26    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000100
    27    _c_int00() at EK_TM4C123GXL.c:0,PC = 0xE048F8DE FP = 0x00000108
    28    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000108
    29    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x5180F04E FP = 0x00000110
    30    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000110
    31    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x8811F380 FP = 0x00000118
    32    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000118
    33    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x0F04F01E FP = 0x00000120
    34    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000120
    35    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x46698108 FP = 0x00000128
    36    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000128
    37    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x0B08F850 FP = 0x00000130
    38    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000130
    39    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x0B10ECB0 FP = 0x00000138
    40    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000138
    41    _c_int00() at EK_TM4C123GXL.c:0,PC = 0x468D8808 FP = 0x00000140
    42    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000140
    43    _c_int00() at EK_TM4C123GXL.c:0,PC = 0xE000ED04 FP = 0x00000148
    44    exit(int) at exit.c:65,PC = 0x0000C20F FP = 0x00000148
    45    ti_sysbios_family_arm_m3_Hwi_doSwiRestore__I(unsigned int) at Hwi.c:1414,PC = 0x00009288 FP = 0x00000150
    46    ti_sysbios_family_arm_m3_Hwi_doSwiRestore__I(unsigned int) at Hwi.c:1414,PC = 0x00009288 FP = 0x200034C0

    I still do not understand the reason of this crash and it is driving me crazy. Any help is welcome.

  • Not sure if it's the same issue, but I had a similar problem when using timers - debugger throws ti_sysbios_family_arm_m3_Hwi_excHandlerAsm__I. Turns out I wasn't setting the RCGCTIMER register. I added SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER3); to my code and it's working now. I was using Timer3.
  • Hey,
    I am facing this error right now!!! :( Same launchpad, 1 i2c task and 1 timer. both are made dynamically.

    I have I2C and Timer. tasks. When I start the timer a bit later I2C task is gone. The ROV says the I2C task is preemted.

    And here is the output:

    e: 0x20001800.
    Task stack size: 0x800.
    R0 = 0x40021000  R8  = 0x00000000
    R1 = 0x04c4b400  R9  = 0x00000001
    R2 = 0x00000000  R10 = 0xffffffff
    R3 = 0x04c4b400  R11 = 0xffffffff
    R4 = 0x20004910  R12 = 0x20001e90
    R5 = 0x0000c120  SP(R13) = 0x20001ef8
    R6 = 0x0000be0c  LR(R14) = 0x00008cf1
    R7 = 0x20001fb4  PC(R15) = 0x0000b61e
    PSR = 0x61000000
    ICSR = 0x00425803
    MMFSR = 0x00
    BFSR = 0x82
    UFSR = 0x0000
    HFSR = 0x40000000
    DFSR = 0x0000000b
    MMAR = 0x40021020
    BFAR = 0x40021020
    AFSR = 0x00000000
    Terminating execution...

    Anyway, is there any method to convert this error code for readable message? It is very hard to find out what is the reason based on only numbers...

  • Changing the timer to fixed 4 the outcome is the following:

    {module#45}: line 288: error {id:0x1e0000, args:[0x4, 0x0]}
    xdc.runtime.Error.raise: terminating execution

    Unfortunately the ROV -> BIOS -> Scan for error shows nothing.