TM4C1290NCZAD: (Again)Unexpected program halt caused by timer counter update

Part Number: TM4C1290NCZAD

Since there was no response, I created a new thread.

Hi experts,

My customer is developing a control program for a 2-phase stepping motor using the TI TM4C1290NCZAD and TI DriverLib. This is not PWM-based motor control. Instead, the motor is accelerated and decelerated by updating the next timer value at each interrupt.

During operation, they observed an issue where the program randomly stops running. The system can be recovered by power-cycling the board.
When this issue occurs, it also becomes impossible to connect via the JTAG debugger, and the following error message is displayed in the debug environment:

“CORTEX_M4_0: Error connecting to the target: (Error -2062 @ 0x0) Unable to halt device. Reset the device, and retry the operation. If error persists, confirm configuration, power-cycle the board, and/or try more reliable JTAG settings (e.g. lower TCLK). (Emulation package 8.0.27.9)”

As a result of our investigation, they found that the issue is resolved by stopping the timer once before updating the timer counter value, and then enabling it again afterward.

Specifically, they implemented the following / sequence:
TimerDisable(TIMER0_BASE, TIMER_A);
TimerLoadSet(TIMER0_BASE, TIMER_A, (wTimer - 1));
TimerEnable(TIMER0_BASE, TIMER_A);Disable()Enable()

Our questions are as follows:

  • Q1: If the timer counter value is updated without stopping the timer, what kinds of malfunction or unexpected behavior could occur?
  • Q2: From a design and specification point of view, is the above workaround of stopping and restarting the timer an appropriate solution?

The initialization code is shown below.

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0));
TimerDisable(TIMER0_BASE, TIMER_A);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerPrescaleSet(TIMER0_BASE, TIMER_A, 0);
TimerLoadSet(TIMER0_BASE, TIMER_A, (g_timerPeriod -1) );
TimerUpdateMode(TIMER0_BASE, TIMER_A, TIMER_UP_LOAD_TIMEOUT);
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntPrioritySet(INT_TIMER0A, 4);
IntEnable(INT_TIMER0A);
TimerEnable(TIMER0_BASE, TIMER_A);

Best regards,
O.H

  • Hi O.H

    I will check the following 2 questions later and reply to you later

    • Q1: If the timer counter value is updated without stopping the timer, what kinds of malfunction or unexpected behavior could occur?
    • Q2: From a design and specification point of view, is the above workaround of stopping and restarting the timer an appropriate solution?
  • Hi Xiaodong LI,

    Thank you for your reply, and sorry for rush you. Is there any update?

    Best regards,
    O.H

  • Hi O.H

    Q1: If the timer counter value is updated without stopping the timer, what kinds of malfunction or unexpected behavior could occur?

    Updating the timer load value on the fly without suspending the peripheral can trigger several critical faults due to how the General-Purpose Timer Module (GPTM) hardware registers synchronize:
    1Severe CPU and JTAG Starvation (Root Cause of Lockup)

    • The Mechanism: If TimerLoadSet() updates the target register near the exact moment the hardware counter transitions, it can create an invalid internal state or immediate underflow.
    • The Consequence: The timer hardware may flag a continuous, un-clearable timeout interrupt or enter an ultra-high frequency interrupt cycle.
    • System Lockup: Because the timer interrupt has a higher priority or keeps pending instantly, the Cortex-M4 core spends 100% of its cycles servicing the ISR. It starves background tasks and entirely drops the JTAG debug access port (DAP) communication line, throwing Error -2062. refer to: https://software-dl.ti.com/ccs/esd/documents/ccs_debugging_jtag_connectivity_issues.html

    2. Missed Timeouts or Extreme Step Delays
    • The Mechanism: By default, the TM4C129x operates with immediate reload updates. If the current counter value is 0x00000005, and the program writes a new value like 0x0000FFFF to the register, the counter resets mid-cycle.
    • The Consequence: Conversely, if the current counter value has already passed a point relative to the new configuration, the hardware can miss its comparison or timeout match entirely. In a down-counter, it might force the module to count all the way through a full 32-bit integer rollover cycle (0xFFFFFFFF), stalling your stepper motor's next pulse for millions of clock cycles. Refer to: TM4C129x Timer operation 

    3. Stepper Motor Acceleration Jitter
    • The Mechanism: Modifying a running counter destroys the precision of the current step profile.
    • The Consequence: Steps will either be abruptly truncated (producing a harsh, violent snap in the motor) or stretched excessively, distorting the acceleration and deceleration curve. Refer to: TM4C129x Timer operation

    Q2: From a design and specification point of view, is the above workaround of stopping and restarting the timer an appropriate solution?

    Yes, the implemented workaround is perfectly appropriate, robust, and highly recommended from a design and specification standpoint.

    Refer to: https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/414478/tm4c129-timer-capture-with-ti_rtos

    Why This Solution Is Correct
    • Guaranteed Determinism: Calling TimerDisable() completely freezes the peripheral's internal digital logic state machine. This eliminates hardware race conditions between the CPU writing to the configuration registers and the timer counting down.
    • Glitch-Free Motor Profiles: By disabling the timer, updating the exact reload interval, and enabling it again, you ensure every single step pulse matches the intended math calculation. Refer to: TM4C129x Timer operation 

    Thanks!

  • Hi Xiaodong LI,

    Thank you for your kind support. I understood. We will contact you if we receive any further questions from customer.

    Best regards,
    O.H

  • Hi O.H

    can I close this thread? if have more question, please contact with me again

    Thanks