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.

TM4C123GH6PM: problem with SysTick Interrupt

Part Number: TM4C123GH6PM

Hi all, I am having problem with systick interrupt. Just to make sure everything is correct I have downloaded working code from internet and it also doesnt work. Program goes to HardFault_Handler instead of SysTick_Handler. Can you please help me, code is so simple, and it took my 3 days trying to figure out what is problem.

whole project files: Systickint.rar

  • Hello Furkan,

    Although I have not opened your .rar archive, it sounds as though you have neglected to populate the interrupt vector for the systick handler within your startup file. I suspect this will get you going straight away.

    Regards,
    Dave
  • The sturtup file is below. I think everything is correct. Can you see any problem here.

    #pragma language=extended
    #pragma segment="CSTACK"
    
    extern void __iar_program_start( void );
    
    extern void NMI_Handler( void );
    extern void HardFault_Handler( void );
    extern void MemManage_Handler( void );
    extern void BusFault_Handler( void );
    extern void UsageFault_Handler( void );
    extern void SVC_Handler( void );
    extern void DebugMon_Handler( void );
    extern void PendSV_Handler( void );
    extern void SysTick_Handler( void );
    
    typedef void( *intfunc )( void );
    typedef union { intfunc __fun; void * __ptr; } intvec_elem;
    
    // The vector table is normally located at address 0.
    // When debugging in RAM, it can be located in RAM, aligned to at least 2^6.
    // If you need to define interrupt service routines,
    // make a copy of this file and include it in your project.
    // The name "__vector_table" has special meaning for C-SPY, which
    // is where to find the SP start value.
    // If vector table is not located at address 0, the user has to initialize
    // the  NVIC vector table register (VTOR) before using interrupts.
    
    
    #pragma location = ".intvec"
    const intvec_elem __vector_table[] =
    {
      { .__ptr = __sfe( "CSTACK" ) },
      __iar_program_start,
    
      NMI_Handler,
      HardFault_Handler,
      MemManage_Handler,
      BusFault_Handler,
      UsageFault_Handler,
      0,
      0,
      0,
      0,
      SVC_Handler,
      DebugMon_Handler,
      0,
      PendSV_Handler,
      SysTick_Handler
    
    };
    
    #pragma call_graph_root = "interrupt"
    __weak void NMI_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void HardFault_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void MemManage_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void BusFault_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void UsageFault_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void SVC_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void DebugMon_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void PendSV_Handler( void ) { while (1) {} }
    #pragma call_graph_root = "interrupt"
    __weak void SysTick_Handler( void ) { while (1) {} }
    
    
    void __cmain( void );
    __weak void __iar_init_core( void );
    __weak void __iar_init_vfp( void );
    
    #pragma required=__vector_table
    void __iar_program_start( void )
    {
      __iar_init_core();
      __iar_init_vfp();
      __cmain();
    }

  • You're still haven't shown either the interrupt routine or the initialization. However, two critical points

    1. Never set unused vectors to zero
    2. Always fill the entire interrupt table

    Those are both critical.

    This doesn't look like the TIVAWare startup. I'd suggest using that.

    Robert

  • Thanks a lot Robert. After 3 days it worked thanks to you. But I have noticed something weird. When I place a printf("%d\n",NVIC_ST_CURRENT_R); in while loop in main to see current value of systick, the interrupt works properly(blinking led). But when I erase that line interrupt stops working and stays in while loop in main. important point is I didn't enable global interrupt. Even I didn't enable global interrupt it worked when I put  printf("%d\n",NVIC_ST_CURRENT_R); in while loop. I couldn't undertstand how it works that way. Also while systick interrupt working I place a printf("entered"); in systick handler function to make sure program enters the function, it goes FaultISR. What kind of effect does printf() has on interrups. I share the code below both startup and main.

    main.c

    #include <stdint.h>
    #include <stdio.h>
    #include "inc/tm4c123gh6pm.h"
    
    
    volatile unsigned long Counts=0; 
    
    
    void SysTick_Init(unsigned long period){ // priority 2
      NVIC_ST_CTRL_R = 0;         // disable SysTick during setup
      NVIC_ST_RELOAD_R = period-1;// reload value
      NVIC_ST_CURRENT_R = 0;      // any write to current clears it
      NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF)|0x40000000;           
      NVIC_ST_CTRL_R = 0x07; // enable SysTick with core clock and interrupts
      // finish all initializations and then enable interrupts
    }
    
    
    
    void SysTick_Handler(void){
      GPIO_PORTF_DATA_R ^= 0x04;       // toggle PF2
      Counts = Counts + 1;
    //  printf("enter");
    }
    
    
    int main(void)
    {
        volatile uint32_t ui32Loop;
    
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
    
        //
        // Do a dummy read to insert a few cycles after enabling the peripheral.
        //
        ui32Loop = SYSCTL_RCGC2_R;
        Counts = 0;
        //
        // Enable the GPIO pin for the LED (PF2).  Set the direction as output, and
        // enable the GPIO pin for digital function.
        //
        GPIO_PORTF_DIR_R = 0x04;
        GPIO_PORTF_AFSEL_R &= ~0x04;// disable alt funct on PF2
        GPIO_PORTF_DEN_R = 0x04;
        GPIO_PORTF_PCTL_R = (GPIO_PORTF_PCTL_R&0xFFFFF0FF)+0x00000000;
        GPIO_PORTF_AMSEL_R = 0;     // disable analog functionality on PF
    
        SysTick_Init(16000);        // initialize SysTick timer, every 1ms
        //
        // Loop forever.
        //
        while(1)
        {
          
          printf("%d\n",NVIC_ST_CURRENT_R);
          
        }
    }
    

    startup.c

    #include <stdint.h>
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    
    //*****************************************************************************
    //
    // Enable the IAR extensions for this source file.
    //
    //*****************************************************************************
    #pragma language=extended
    
    //*****************************************************************************
    //
    // Forward declaration of the default fault handlers.
    //
    //*****************************************************************************
    void ResetISR(void);
    static void NmiSR(void);
    static void FaultISR(void);
    extern void SysTick_Handler(void);
    static void IntDefaultHandler(void);
    
    //*****************************************************************************
    //
    // The entry point for the application startup code.
    //
    //*****************************************************************************
    extern void __iar_program_start(void);
    
    //*****************************************************************************
    //
    // Reserve space for the system stack.
    //
    //*****************************************************************************
    static uint32_t pui32Stack[64] @ ".noinit";
    
    //*****************************************************************************
    //
    // A union that describes the entries of the vector table.  The union is needed
    // since the first entry is the stack pointer and the remainder are function
    // pointers.
    //
    //*****************************************************************************
    typedef union
    {
        void (*pfnHandler)(void);
        uint32_t ui32Ptr;
    }
    uVectorEntry;
    
    //*****************************************************************************
    //
    // The vector table.  Note that the proper constructs must be placed on this to
    // ensure that it ends up at physical address 0x0000.0000.
    //
    //*****************************************************************************
    __root const uVectorEntry __vector_table[] @ ".intvec" =
    {
        { .ui32Ptr = (uint32_t)pui32Stack + sizeof(pui32Stack) },
                                                // The initial stack pointer
        ResetISR,                               // The reset handler
        NmiSR,                                  // The NMI handler
        FaultISR,                               // The hard fault handler
        IntDefaultHandler,                      // The MPU fault handler
        IntDefaultHandler,                      // The bus fault handler
        IntDefaultHandler,                      // The usage fault handler
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        IntDefaultHandler,                      // SVCall handler
        IntDefaultHandler,                      // Debug monitor handler
        0,                                      // Reserved
        IntDefaultHandler,                      // The PendSV handler
        SysTick_Handler,                        // The SysTick handler
        IntDefaultHandler,                      // GPIO Port A
        IntDefaultHandler,                      // GPIO Port B
        IntDefaultHandler,                      // GPIO Port C
        IntDefaultHandler,                      // GPIO Port D
        IntDefaultHandler,                      // GPIO Port E
        IntDefaultHandler,                      // UART0 Rx and Tx
        IntDefaultHandler,                      // UART1 Rx and Tx
        IntDefaultHandler,                      // SSI0 Rx and Tx
        IntDefaultHandler,                      // I2C0 Master and Slave
        IntDefaultHandler,                      // PWM Fault
        IntDefaultHandler,                      // PWM Generator 0
        IntDefaultHandler,                      // PWM Generator 1
        IntDefaultHandler,                      // PWM Generator 2
        IntDefaultHandler,                      // Quadrature Encoder 0
        IntDefaultHandler,                      // ADC Sequence 0
        IntDefaultHandler,                      // ADC Sequence 1
        IntDefaultHandler,                      // ADC Sequence 2
        IntDefaultHandler,                      // ADC Sequence 3
        IntDefaultHandler,                      // Watchdog timer
        IntDefaultHandler,                      // Timer 0 subtimer A
        IntDefaultHandler,                      // Timer 0 subtimer B
        IntDefaultHandler,                      // Timer 1 subtimer A
        IntDefaultHandler,                      // Timer 1 subtimer B
        IntDefaultHandler,                      // Timer 2 subtimer A
        IntDefaultHandler,                      // Timer 2 subtimer B
        IntDefaultHandler,                      // Analog Comparator 0
        IntDefaultHandler,                      // Analog Comparator 1
        IntDefaultHandler,                      // Analog Comparator 2
        IntDefaultHandler,                      // System Control (PLL, OSC, BO)
        IntDefaultHandler,                      // FLASH Control
        IntDefaultHandler,                      // GPIO Port F
        IntDefaultHandler,                      // GPIO Port G
        IntDefaultHandler,                      // GPIO Port H
        IntDefaultHandler,                      // UART2 Rx and Tx
        IntDefaultHandler,                      // SSI1 Rx and Tx
        IntDefaultHandler,                      // Timer 3 subtimer A
        IntDefaultHandler,                      // Timer 3 subtimer B
        IntDefaultHandler,                      // I2C1 Master and Slave
        IntDefaultHandler,                      // Quadrature Encoder 1
        IntDefaultHandler,                      // CAN0
        IntDefaultHandler,                      // CAN1
        IntDefaultHandler,                      // CAN2
        0,                                      // Reserved
        IntDefaultHandler,                      // Hibernate
        IntDefaultHandler,                      // USB0
        IntDefaultHandler,                      // PWM Generator 3
        IntDefaultHandler,                      // uDMA Software Transfer
        IntDefaultHandler,                      // uDMA Error
        IntDefaultHandler,                      // ADC1 Sequence 0
        IntDefaultHandler,                      // ADC1 Sequence 1
        IntDefaultHandler,                      // ADC1 Sequence 2
        IntDefaultHandler,                      // ADC1 Sequence 3
        0,                                      // Reserved
        0,                                      // Reserved
        IntDefaultHandler,                      // GPIO Port J
        IntDefaultHandler,                      // GPIO Port K
        IntDefaultHandler,                      // GPIO Port L
        IntDefaultHandler,                      // SSI2 Rx and Tx
        IntDefaultHandler,                      // SSI3 Rx and Tx
        IntDefaultHandler,                      // UART3 Rx and Tx
        IntDefaultHandler,                      // UART4 Rx and Tx
        IntDefaultHandler,                      // UART5 Rx and Tx
        IntDefaultHandler,                      // UART6 Rx and Tx
        IntDefaultHandler,                      // UART7 Rx and Tx
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        IntDefaultHandler,                      // I2C2 Master and Slave
        IntDefaultHandler,                      // I2C3 Master and Slave
        IntDefaultHandler,                      // Timer 4 subtimer A
        IntDefaultHandler,                      // Timer 4 subtimer B
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        0,                                      // Reserved
        IntDefaultHandler,                      // Timer 5 subtimer A
        IntDefaultHandler,                      // Timer 5 subtimer B
        IntDefaultHandler,                      // Wide Timer 0 subtimer A
        IntDefaultHandler,                      // Wide Timer 0 subtimer B
        IntDefaultHandler,                      // Wide Timer 1 subtimer A
        IntDefaultHandler,                      // Wide Timer 1 subtimer B
        IntDefaultHandler,                      // Wide Timer 2 subtimer A
        IntDefaultHandler,                      // Wide Timer 2 subtimer B
        IntDefaultHandler,                      // Wide Timer 3 subtimer A
        IntDefaultHandler,                      // Wide Timer 3 subtimer B
        IntDefaultHandler,                      // Wide Timer 4 subtimer A
        IntDefaultHandler,                      // Wide Timer 4 subtimer B
        IntDefaultHandler,                      // Wide Timer 5 subtimer A
        IntDefaultHandler,                      // Wide Timer 5 subtimer B
        IntDefaultHandler,                      // FPU
        0,                                      // Reserved
        0,                                      // Reserved
        IntDefaultHandler,                      // I2C4 Master and Slave
        IntDefaultHandler,                      // I2C5 Master and Slave
        IntDefaultHandler,                      // GPIO Port M
        IntDefaultHandler,                      // GPIO Port N
        IntDefaultHandler,                      // Quadrature Encoder 2
        0,                                      // Reserved
        0,                                      // Reserved
        IntDefaultHandler,                      // GPIO Port P (Summary or P0)
        IntDefaultHandler,                      // GPIO Port P1
        IntDefaultHandler,                      // GPIO Port P2
        IntDefaultHandler,                      // GPIO Port P3
        IntDefaultHandler,                      // GPIO Port P4
        IntDefaultHandler,                      // GPIO Port P5
        IntDefaultHandler,                      // GPIO Port P6
        IntDefaultHandler,                      // GPIO Port P7
        IntDefaultHandler,                      // GPIO Port Q (Summary or Q0)
        IntDefaultHandler,                      // GPIO Port Q1
        IntDefaultHandler,                      // GPIO Port Q2
        IntDefaultHandler,                      // GPIO Port Q3
        IntDefaultHandler,                      // GPIO Port Q4
        IntDefaultHandler,                      // GPIO Port Q5
        IntDefaultHandler,                      // GPIO Port Q6
        IntDefaultHandler,                      // GPIO Port Q7
        IntDefaultHandler,                      // GPIO Port R
        IntDefaultHandler,                      // GPIO Port S
        IntDefaultHandler,                      // PWM 1 Generator 0
        IntDefaultHandler,                      // PWM 1 Generator 1
        IntDefaultHandler,                      // PWM 1 Generator 2
        IntDefaultHandler,                      // PWM 1 Generator 3
        IntDefaultHandler                       // PWM 1 Fault
    };
    
    
    void
    ResetISR(void)
    {
        __iar_program_start();
    }
    
    
    static void
    NmiSR(void)
    {
        //
        // Enter an infinite loop.
        //
        while(1)
        {
        }
    }
    
    
    static void
    FaultISR(void)
    {
        //
        // Enter an infinite loop.
        //
        while(1)
        {
        }
    }
    
    
    static void
    IntDefaultHandler(void)
    {
        //
        // Go into an infinite loop.
        //
        while(1)
        {
        }
    }
    

  • Hello Furkan!

    Perhaps I can be of some help:

    Take a look at these lines:

        SysTickPeriodSet(systemClock/1000);
        SysTickEnable();
        SysTickIntEnable();
    

    And now take a look at these:

    NVIC_ST_CTRL_R = 0;
    NVIC_ST_RELOAD_R = period-1;
    NVIC_ST_CURRENT_R = 0;
    NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF)|0x40000000;           
    NVIC_ST_CTRL_R = 0x07;

    Imagine if you look at them again one year from now. You might have forgotten some of details of the TivaWare API, but which of the two sets of code do you think you will be able to understand and manage? Which will be faster to figure out? Imagine something is not working too well, which one can you trust to be proven? The clarity of the coding is really important when you need to debug, or to grow your projects in the future. The suggestion here is: don't waste your time with obscure register configurations, but rather use the drivers library.

    Now, as for your mysterious hard fault, might it be due to too small a stack? The printf family consumes a lot of stack, and 2K ain't a bad figure to start with...

    Bruno

  • You can be right in some cases, but in my case, i am trying to figure out what is going on at background. To use ready libraries is simple and everybody can do it. As an example, I have never look at a startup file until having this systick problem and now I know what every line is doing in startup file. After make the code working I can create my own library.

    I dont think it is about stack, because when I use printf it works, when I dont use it code doesn't work. I just noticed code is working in debug mode, but when I remove launchpad from computer and supply from external 5v source it doesnt work. This is really weird.
  • Furkan ERMAN said:
    To use ready libraries is simple and everybody can do it

    Hummm... I asked both the waitress from the restaurant across the street, and my lawyer. Both seem to be unable to use the libraries...

    There is a major difference between using a manufacturer's official driver library, and some community-created obscure vooduino downloaded library. Seeing a register bit change from 0 to 1 don't really show you what's going on at background unless you have the complete schematics of the internal circuitry of the IC.

    Cheers

    Bruno

  • This platform is not suitable place to argue such things, I have a problem waiting to be solved, need to focus on it
  • Two comments

    First you still have zeros in your vector table, that is a bad idea.

    Second Bruno is correct you should replace the direct register manipulation with TIVAWare (and yes this is a suitable place to suggest such). It should be your next step in focusing on your problem. To stay with DRM is to remove your focus from your problem.

    Robert
  • Furkan ERMAN said:
    What kind of effect does printf() has on interrups.

    Rules on using stdio in interrupts

    1. Don't use stdio in interrupts
    2. See Rule 1

    Robert

  • Hello again Erman,

    I'm not trying to raise a fight, but rather to suggest good practices. These are much more important than to solve one single problem.

    Furkan ERMAN said:
    This platform is not suitable place to argue such things

    Once again I tried your suggestion: I went to the sports shop down the freeway, and also to the blacksmith. On neither I found people who had a clue what I was talking about, and while being nice and not calling security, they suggested me that "there must be a technical place where to discuss those things"...

    Then I came back to the PC, and googled where such a suitable place would be. Well, I found a place - look what this page says!!!

    Piece!

    Bruno

  • Alright I used driver library as you suggest, but result is the same. I suspect if my custom board has proplem, however it didn't work on Tm4c123gxl launchpad either.

    Main.c

    //*****************************************************************************
    //
    // interrupts.c - Interrupt preemption and tail-chaining example.
    //
    // Copyright (c) 2012-2013 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    // 
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    // 
    // This is part of revision 1.0 of the EK-TM4C123GXL Firmware Package.
    //
    //*****************************************************************************
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    
    
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif
    
    
    
    
    void SysTick_Handler(void){
      GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 1);
    }
    
    
    int
    main(void)
    {
    
        //
        // Set the clocking to run directly from the crystal.
        //
        SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_16MHZ);
    
        //
        // Enable the peripherals used by this example.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
    
    
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 |
                                                   GPIO_PIN_3);
        
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);
    
        //
        // 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.
        //
        SysTickPeriodSet(16000);
        SysTickEnable();
        SysTickIntEnable();
        
    
        //
        // Enable interrupts to the processor.
        //
        IntMasterEnable();
    
        while(1)
        {
          
          
        }
    }
    

    startup.c

    //*****************************************************************************
    //
    // startup.c - Startup code for use with IAR's Embedded Workbench,
    //                   version 5.
    //
    // Copyright (c) 2012-2013 Texas Instruments Incorporated.  All rights reserved.
    // Software License Agreement
    // 
    // Texas Instruments (TI) is supplying this software for use solely and
    // exclusively on TI's microcontroller products. The software is owned by
    // TI and/or its suppliers, and is protected under applicable copyright
    // laws. You may not combine this software with "viral" open-source
    // software in order to form a larger program.
    // 
    // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
    // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
    // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
    // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
    // DAMAGES, FOR ANY REASON WHATSOEVER.
    // 
    // This is part of revision 1.0 of the EK-TM4C123GXL Firmware Package.
    //
    //*****************************************************************************
    
    #include <stdint.h>
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    
    //*****************************************************************************
    //
    // Enable the IAR extensions for this source file.
    //
    //*****************************************************************************
    #pragma language=extended
    
    //*****************************************************************************
    //
    // Forward declaration of the default fault handlers.
    //
    //*****************************************************************************
    void ResetISR(void);
    static void NmiSR(void);
    static void FaultISR(void);
    static void IntDefaultHandler(void);
    
    //*****************************************************************************
    //
    // External declarations for the interrupt handlers used by the application.
    //
    //*****************************************************************************
    
    extern void SysTick_Handler(void);
    
    //*****************************************************************************
    //
    // The entry point for the application startup code.
    //
    //*****************************************************************************
    extern void __iar_program_start(void);
    
    //*****************************************************************************
    //
    // Reserve space for the system stack.
    //
    //*****************************************************************************
    static uint32_t pui32Stack[128] @ ".noinit";
    
    //*****************************************************************************
    //
    // A union that describes the entries of the vector table.  The union is needed
    // since the first entry is the stack pointer and the remainder are function
    // pointers.
    //
    //*****************************************************************************
    typedef union
    {
        void (*pfnHandler)(void);
        uint32_t ui32Ptr;
    }
    uVectorEntry;
    
    //*****************************************************************************
    //
    // The vector table.  Note that the proper constructs must be placed on this to
    // ensure that it ends up at physical address 0x0000.0000.
    //
    //*****************************************************************************
    __root const uVectorEntry __vector_table[] @ ".intvec" =
    {
        { .ui32Ptr = (uint32_t)pui32Stack + sizeof(pui32Stack) },
                                                // The initial stack pointer
        ResetISR,                               // The reset handler
        NmiSR,                                  // The NMI handler
        FaultISR,                               // The hard fault handler
        IntDefaultHandler,                      // The MPU fault handler
        IntDefaultHandler,                      // The bus fault handler
        IntDefaultHandler,                      // The usage fault handler
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // SVCall handler
        IntDefaultHandler,                      // Debug monitor handler
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // The PendSV handler
        SysTick_Handler,                        // The SysTick handler
        IntDefaultHandler,                      // GPIO Port A
        IntDefaultHandler,                      // GPIO Port B
        IntDefaultHandler,                      // GPIO Port C
        IntDefaultHandler,                      // GPIO Port D
        IntDefaultHandler,                      // GPIO Port E
        IntDefaultHandler,                      // UART0 Rx and Tx
        IntDefaultHandler,                      // UART1 Rx and Tx
        IntDefaultHandler,                      // SSI0 Rx and Tx
        IntDefaultHandler,                      // I2C0 Master and Slave
        IntDefaultHandler,                      // PWM Fault
        IntDefaultHandler,                      // PWM Generator 0
        IntDefaultHandler,                      // PWM Generator 1
        IntDefaultHandler,                      // PWM Generator 2
        IntDefaultHandler,                      // Quadrature Encoder 0
        IntDefaultHandler,                      // ADC Sequence 0
        IntDefaultHandler,                      // ADC Sequence 1
        IntDefaultHandler,                      // ADC Sequence 2
        IntDefaultHandler,                      // ADC Sequence 3
        IntDefaultHandler,                      // Watchdog timer
        IntDefaultHandler,                      // Timer 0 subtimer A
        IntDefaultHandler,                      // Timer 0 subtimer B
        IntDefaultHandler,                      // Timer 1 subtimer A
        IntDefaultHandler,                      // Timer 1 subtimer B
        IntDefaultHandler,                      // Timer 2 subtimer A
        IntDefaultHandler,                      // Timer 2 subtimer B
        IntDefaultHandler,                      // Analog Comparator 0
        IntDefaultHandler,                      // Analog Comparator 1
        IntDefaultHandler,                      // Analog Comparator 2
        IntDefaultHandler,                      // System Control (PLL, OSC, BO)
        IntDefaultHandler,                      // FLASH Control
        IntDefaultHandler,                      // GPIO Port F
        IntDefaultHandler,                      // GPIO Port G
        IntDefaultHandler,                      // GPIO Port H
        IntDefaultHandler,                      // UART2 Rx and Tx
        IntDefaultHandler,                      // SSI1 Rx and Tx
        IntDefaultHandler,                      // Timer 3 subtimer A
        IntDefaultHandler,                      // Timer 3 subtimer B
        IntDefaultHandler,                      // I2C1 Master and Slave
        IntDefaultHandler,                      // Quadrature Encoder 1
        IntDefaultHandler,                      // CAN0
        IntDefaultHandler,                      // CAN1
        IntDefaultHandler,                      // CAN2
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // Hibernate
        IntDefaultHandler,                      // USB0
        IntDefaultHandler,                      // PWM Generator 3
        IntDefaultHandler,                      // uDMA Software Transfer
        IntDefaultHandler,                      // uDMA Error
        IntDefaultHandler,                      // ADC1 Sequence 0
        IntDefaultHandler,                      // ADC1 Sequence 1
        IntDefaultHandler,                      // ADC1 Sequence 2
        IntDefaultHandler,                      // ADC1 Sequence 3
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // GPIO Port J
        IntDefaultHandler,                      // GPIO Port K
        IntDefaultHandler,                      // GPIO Port L
        IntDefaultHandler,                      // SSI2 Rx and Tx
        IntDefaultHandler,                      // SSI3 Rx and Tx
        IntDefaultHandler,                      // UART3 Rx and Tx
        IntDefaultHandler,                      // UART4 Rx and Tx
        IntDefaultHandler,                      // UART5 Rx and Tx
        IntDefaultHandler,                      // UART6 Rx and Tx
        IntDefaultHandler,                      // UART7 Rx and Tx
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // I2C2 Master and Slave
        IntDefaultHandler,                      // I2C3 Master and Slave
        IntDefaultHandler,                      // Timer 4 subtimer A
        IntDefaultHandler,                      // Timer 4 subtimer B
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // Timer 5 subtimer A
        IntDefaultHandler,                      // Timer 5 subtimer B
        IntDefaultHandler,                      // Wide Timer 0 subtimer A
        IntDefaultHandler,                      // Wide Timer 0 subtimer B
        IntDefaultHandler,                      // Wide Timer 1 subtimer A
        IntDefaultHandler,                      // Wide Timer 1 subtimer B
        IntDefaultHandler,                      // Wide Timer 2 subtimer A
        IntDefaultHandler,                      // Wide Timer 2 subtimer B
        IntDefaultHandler,                      // Wide Timer 3 subtimer A
        IntDefaultHandler,                      // Wide Timer 3 subtimer B
        IntDefaultHandler,                      // Wide Timer 4 subtimer A
        IntDefaultHandler,                      // Wide Timer 4 subtimer B
        IntDefaultHandler,                      // Wide Timer 5 subtimer A
        IntDefaultHandler,                      // Wide Timer 5 subtimer B
        IntDefaultHandler,                      // FPU
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // I2C4 Master and Slave
        IntDefaultHandler,                      // I2C5 Master and Slave
        IntDefaultHandler,                      // GPIO Port M
        IntDefaultHandler,                      // GPIO Port N
        IntDefaultHandler,                      // Quadrature Encoder 2
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                                      // Reserved
        IntDefaultHandler,                      // GPIO Port P (Summary or P0)
        IntDefaultHandler,                      // GPIO Port P1
        IntDefaultHandler,                      // GPIO Port P2
        IntDefaultHandler,                      // GPIO Port P3
        IntDefaultHandler,                      // GPIO Port P4
        IntDefaultHandler,                      // GPIO Port P5
        IntDefaultHandler,                      // GPIO Port P6
        IntDefaultHandler,                      // GPIO Port P7
        IntDefaultHandler,                      // GPIO Port Q (Summary or Q0)
        IntDefaultHandler,                      // GPIO Port Q1
        IntDefaultHandler,                      // GPIO Port Q2
        IntDefaultHandler,                      // GPIO Port Q3
        IntDefaultHandler,                      // GPIO Port Q4
        IntDefaultHandler,                      // GPIO Port Q5
        IntDefaultHandler,                      // GPIO Port Q6
        IntDefaultHandler,                      // GPIO Port Q7
        IntDefaultHandler,                      // GPIO Port R
        IntDefaultHandler,                      // GPIO Port S
        IntDefaultHandler,                      // PWM 1 Generator 0
        IntDefaultHandler,                      // PWM 1 Generator 1
        IntDefaultHandler,                      // PWM 1 Generator 2
        IntDefaultHandler,                      // PWM 1 Generator 3
        IntDefaultHandler                       // PWM 1 Fault
    };
    
    //*****************************************************************************
    //
    // This is the code that gets called when the processor first starts execution
    // following a reset event.  Only the absolutely necessary set is performed,
    // after which the application supplied entry() routine is called.  Any fancy
    // actions (such as making decisions based on the reset cause register, and
    // resetting the bits in that register) are left solely in the hands of the
    // application.
    //
    //*****************************************************************************
    void
    ResetISR(void)
    {
        //
        // Enable the floating-point unit.  This must be done here to handle the
        // case where main() uses floating-point and the function prologue saves
        // floating-point registers (which will fault if floating-point is not
        // enabled).  Any configuration of the floating-point unit using DriverLib
        // APIs must be done here prior to the floating-point unit being enabled.
        //
        // Note that this does not use DriverLib since it might not be included in
        // this project.
        //
        HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) &
                             ~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) |
                            NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL);
    
        //
        // Call the application's entry point.
        //
        __iar_program_start();
    }
    
    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives a NMI.  This
    // simply enters an infinite loop, preserving the system state for examination
    // by a debugger.
    //
    //*****************************************************************************
    static void
    NmiSR(void)
    {
        //
        // Enter an infinite loop.
        //
        while(1)
        {
        }
    }
    
    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives a fault
    // interrupt.  This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    FaultISR(void)
    {
        //
        // Enter an infinite loop.
        //
        while(1)
        {
        }
    }
    
    //*****************************************************************************
    //
    // This is the code that gets called when the processor receives an unexpected
    // interrupt.  This simply enters an infinite loop, preserving the system state
    // for examination by a debugger.
    //
    //*****************************************************************************
    static void
    IntDefaultHandler(void)
    {
        //
        // Go into an infinite loop.
        //
        while(1)
        {
        }
    }
    

  • Hallo ERMAN,

    Much easier reading (at least for me)!

    1) The systick part is perfect, it should work. If you set a breakpoint inside the Systick ISR, does program get there?

    2) Next line will not turn all pins ON. The third parameter should be a mask containing the pins you want to activate - in this case, the value 1 would mask only to PIN_0:

    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 1);

    3) It's been a while since I studied the system clocks, now we just copy/paste what already works here. In our case, we use PLL, here's the setting for 80MHz:

    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);

    On the subject: I don't see a reason to run the MCU slower than it can (personal opinion). I figure that if the goal is to save energy, it is more efficient to finish the tasks as fast as you can, and then sleep if possible. Note that in that case, you will have to change your SYSTICK parameter to bring it back to 1000Hz.

    Bruno

  • Problem is solved, now I have working systick interrupt. The final code is below if someone wants to use it. Thanks @, @, and @

    #include <stdint.h>
    #include <stdio.h>
    #include <stdbool.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_nvic.h"
    #include "inc/hw_types.h"
    #include "driverlib/debug.h"
    #include "driverlib/fpu.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"
    
    volatile uint32_t count=0;
    
    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif
    
    
    
    
    void SysTick_Handler(void){
      count++;
      
      if(count == 500){
         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 14);
      }
      else if(count == 1000){
         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0); 
         count=0;
      }
    }
    
    
    int
    main(void)
    {
      
          volatile uint32_t ui32Loop;
    
        //
        // Set the clocking to run directly from the crystal.
        //
    //    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
          SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
    
        //
        // Enable the peripherals used by this example.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
    
    
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
        
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);
    
        //
        // 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.
        //
        SysTickPeriodSet(80000);
        SysTickEnable();
        SysTickIntEnable();
        
    
        //
        // Enable interrupts to the processor.
        //
    //    IntMasterEnable();
    
        while(1)
        {
          
        }
    }

  • Thanks for the feedback.
    Just one quic note:
    - For better clarity, it is OK if you just repeat GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 instead of the number 14. It is exactly the same thing after compiled, but in a week from now (or a month or two...), you will look and waste a few precious minutes wondering "what on Earth is that 14???"
    Cheers
    Bruno
  • May some here (especially crack staff) disagree?

    Consider the case of seeking ALL Port Pins ON - staff would "slit their wrists" rather than spend "endless hours" listing GPIO_PIN_INFINITY!      (0xFF works FINE in such case - and the "comment field" may record that value as "bit position founded" - overcoming "wonder!"

    (note too that the comment field is over-run by GPIO_ad_infinitum - is it not?)    

    And - it often happens that other Ports must be similarly treated - use of "GPIO_PIN_ad_infinitum" GETS VERY OLD - VERY FAST!

  • I'm with Bruno on this cb1. If TIVAWare doesn't have a constant for all pins it's easy enough to create one.

    Robert
  • Oh Robert - day earlier you "reveal" hacking secrets - and now you "side w/Bruno!"

    The (expected) blood-trails - from (multiple) slit wrists - sure to mar our ESD-safe, hi-tech (expensive) flooring...

    At least our poster has, "Seen the light" - yet registers (even) stronger by employing Hex Values - for (both) Params: 2 & 3.     (Port bits which yield "1" - after the "And" of Params 2 & 3 - "ON" their outputs.)

    While I'm NO "Conspiracy Advocate" - it must be noted that, "Bruno's list of "Carpal Tunnel Specialists" has (just) added several w/in your neat Ontario location!     (surely incidental - we're sure...)