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.

TM4C1294NCPDT: Problem getting Systick Interrupt to work

Part Number: TM4C1294NCPDT

I am starting a new project with the 1294 Launchpad XL.  I have a program that I want to use the Systick as my system timer, with a 1 ms time slice.  I have set up the code to enable the  systick as follows:

      // Set the clocking to run directly from the crystal at 120MHz.
       //
       g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                                SYSCTL_OSC_MAIN |
                                                SYSCTL_USE_PLL |
                                                SYSCTL_CFG_VCO_480), 120000000);

    //
    // Set up and enable the SysTick timer.  It will be used as a reference
    // for delay loops in the interrupt handlers.  The SysTick timer period
    // will be set up for one second.
    //
    ROM_SysTickPeriodSet(g_ui32SysClock/1000);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

...

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

I have created a systick handler::


void SysTickHandler(void)
{
     // Increment the count
      Increment_ms();

}

And I have added the handler to the interrupt table in the startup.c

    SysTickHandler,                         // The SysTick handler
    IntDefaultHandler,                      // GPIO Port A

When I run the code I can see the part initialize, and I get to a loop where I read the Sistick value.  I can see the value is changing and that it seems to be limited by the bounds from my set, so I know the counter is actually counting.  For some reason I am not getting the interrupt to occur.  It never stops at the breakpoint in the interrupt where I increment my system count.

I have looked at all the other Systick posts I could find and could not find the answer to my problem. Can someone tell me what I am missing, or point me to an example where the SysTick interrupt is being used and not just where the timer is started and read.  I am sure I left out something stupid, but I am not having luck figuring it out.

Sincerely,

Mike Fontes

  • HI Mike,
    I don't really spot anything wrong with your code. You might want to try putting ROM_SysTickEnable() after ROM_SysTickIntEnable() and ROM_IntMasterEnable();
    You can also find a systick example under <TivaWare_Installation>\examples\peripherals\systick. This example uses interrupt.
  • Charkes,

    I tried reordering the functions with no change.
    i then tried ordering them as in the interrupts.c example with no change.

    I then tried using the library instead of the ROM code with no change.

    When I check the registers it shows the interrupt enabled for all the above cases.

    out of curiosity I added the following line in my loop:

    ROM_IntPendSet(FAULT_SYSTICK);

    After I added this line I found that the interrupt was occurring because my counter would increment by 1 each time I went through the loop. However, the program would not break at the breakpoint I put in the loop.

    TO say the least I am very confused. I have used this interrupt before on code for 3S811 parts several years back.

    I could just assign the task to a timer, but the whole point of SysTick is to handle exactly what I am trying to accomplish, so I would like to get it running correctly. I now have 2 questions:

    1. What do I try next to get the interrupt to fire correctly when the counter reaches it count?

    2. Why am I not able to stop at the beakpoint in the interrupt? Do I have a setting that needs to be changed?

    Sincerely,

    Mike Fontes
  • Charles, to be clear, the breakpoint I could nto get to was not in my program loop. It was in the interrupt routine. I am sorry for the miss-statement.

    By the way, I have eye problems and just realized I spelled interrupt wrong in my first post. Is there a way to change the title so people searching for interrupt problems don't miss the postings?
  • Hi Mike,
    Did you run the interrupt.c as is? Did the example work for you?

    When you said the interrupt did not work, did you base on the breakpt wasn't taken or the interrupt count did not increment?

    At exactly which line in the ISR did you try to place the breakpoint? Can you show a screenshot of it? I'd like to know if you might have placed a software breakpt on the flash rather than hardware breakpt. Even though this is not likely the problem I just want to make sure.

    What if you place a breakpt inside the function Increment_ms(), does it make a difference? Can you also show the content of increment_ms()?
  • Charles,

    When I said the interrupt didn't work it was due to two things:

    1. The ms counter was not incrementing although I could see the SysTick counter value changing with my Gets.

    2 The debugger was not stopping in the interrupt routine on the lie that called the increment_ms function.

    When I added the interrupt set to my loop the ms counter started being updated once per loop, indicating the code had been run.  However the debugger still did not stop in the interrupt routine.

    My loop continuously brings me to the following case, since the millisecond timer has not reached the cycle limit:

          case FINGERS_THUMB_WAIT:
                // Get the present time
                Now1 = Get_ms_count();                               // When the interrupt runs Now1 is incremented as seen using the variables window in the debugger
                Now = ROM_SysTickValueGet();                  // in normal operation Now has a value about 117000, but changing so I know it is being reset and new values read

                ROM_IntPendSet(FAULT_SYSTICK);          // This is the line I added that causes the interrupt to run.  Without it the interrupt does not run.

                // Check to see if time has elapsed
                if (Now1 >= Cycle_Limit)
                   {
                   // Set the next State to the push up the index finger
                   FingersState = FINGERS_INDEX_SET;
                   }

            break;

    I am working on trying all the options but one thing I am having a bit of trouble with is the setting of breakpoints. It seems some things have changed in the past year on the new CCS.  Where do I find a description of the difference between HW and SW breakpoints and how to set each? when I click at the beginning of a line CCS seems to decide which it is, and whether to enable or disable the breakpoint.  I also get a lot of AET resource not available when trying to set one.  Is ther a place that describes what the limitations are?  In the screenshot below the list of interrupts is seen in the window. Three are one the lines I clicked, but when I clicked the line 264 to add a breakpoint CCS adds the breakpoint at line 280 instead, as shown.  I find this very confusing.  I have tried restarting CCS ans it still does it.

    Charles,

    I have taken out the set interrupt on line 258  above, that I added yesterday to get the interrupt, and now the thing is working.  I don't know why but I am getting the timer to run.  This is very confusing.

    However I did find out that I cannot place breakpoints where I want them, as shown above, and when I single step through the code it is not following the code step by step.  It seems to be jumping around. However, I think this may be a subject for a different post.  I will restart everything and try it a few times to see if I can get some detailed descriptions,

    At this point I am getting the interrupt and the MS counter is updating, so I think this thread should end, maybe withyou telling me where to find the info on the breakpoint setting questions above.

  • Charles,

    I sent in the previous psot a screen shot showing the ccs screen and specific code, that was not added to the post you received. The rest of the post refers to line and views in that screenshot. How do I get the screenshot to you if it shows it in the post area, but doesn't transmit it to you?
  • Hi Mike,
    I do not see the screenshot. Can you please upload again?

    About the single stepping will jump around, it is due to the compiler optimization. Can you please disable the CCS compiler optimization. I hope that it will not just solve the single stepping jumping around issue but will somehow fix the breakpt issue when you place the breakpt in the ISR.
  • Hi Mike,

     At the lower right corner of the posting area there is a "Use rich formatting". Please click it to enable rich formatting. Once your screenshot is captured you can click

    on the Insert/Edit Media button to upload your screenshot. The button is about in the middle of the second row. 

  • Charles,

    Taking out the optimizations allowed me to set the breakpoints where I wanted them. As I mentioned, once I removed the set SysTick interrupt it kept working, but I don't know why. I literally only puy "//" in front of that one line in the code and rebuilt the project.

    The important thing is that the code is working, so I can continue moving forward. I am now stepping correctly through my states with the SysTick providing the ms timer.

    The only question I have now is: why the compiler would have optimized out lines of code that would be reached once a counter incremented to a known integer value? Those were the lines that I could not set a breakpoint on when I had the default optimizations. In the snippet below I could not set the breakpoint on the FingerState assignment line. You can also see the commenting out of the setting of the interrupt that I removed. The only thing I will now do is remove the ValueGer function as I was only using it to prove the counter was actually counting. For completeness the Cycle_Limit value was set in the previous state so its value is known when this state is entered.

    case FINGERS_THUMB_WAIT:
    // Get the present time
    Now1 = Get_ms_count();
    Now = ROM_SysTickValueGet();

    // ROM_IntPendSet(FAULT_SYSTICK);

    // Check to see if time has elapsed
    if (Now1 >= Cycle_Limit)
    {
    // Set the next State to the push up the index finger
    FingersState = FINGERS_INDEX_SET;
    }
    break;
  • Hi Mike,
    I tend to think that the interrupt was working before but you were unable set breakpt in the ISR and that might have misled you into thinking the interrupt was not working.

    Earlier I was asking you on which line you placed the breakpt in the ISR and I wondered if you put the breakpt inside the increment_ms() will you see the debugger stopping the CPU. There is only one line in your earlier ISR which is the function call to the increment_ms(). Perhaps due to optimization you can not place the breakpt in front of the function directly but if you were to place the breakpt inside the increment_ms() or if you add some dummy instructions before the increment_ms() in the ISR then the breakpt will happen. When you enable optimization there is no longer direct correspondence between the C code line and the assembly code. What you can also try to do is instead of placing the breakpt on the call to the increment_ms(), put the breakpt in the dissasembly window on the assembly code where the increment_ms() is allocated.
  • Charles,

    I am positive the interrupt was not running before because the increments was not happening for the ms timer. It only started working when I "forced " the interrupt with the line that I eventually commented out.

    However, I agree with you that the optimizations were not helpong me as once I removed them I could stop at breakpoints in both the SysTick handler and the increment_ms functions, neither of which happened while the optimizations were in place.

    The good news is that the timer is working nicely and I am cycling successfully through the states of the task I was showing you snippets of. I can now add the several other tasks that were being compiled, but not actively used in the project.

    I would have to say we have resolved this issue. I did ask a question about fixing my title where my blindness caused me to spell the word interrupt incorrectly. Can that be done so searches b y others can correctly find the posts?

    Thanks for your help.

    Sincerely,

    Mike Fontes
  • Hi Mike,
    Glad you problem is solved! Let me find out how to fix your title. I haven't found a way to do it yet. I will get back if it is fixable.
  • Hi Mike,
    I just fixed the title. .