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.

Enable, Disable and WaitFor Interrupt in gcc



Hello,

I'm on LinuxMint 17.2, using arm-none-eabi-gcc toolchain on a TM4C123G board.

I have been trying, unsuccessfully, to write the EnableInterrupt, DisableInterrupt and WaitForInterrupt functions in order to do a periodic Systick interrupt subsequently. Eg :

void EnableInt(void)
{    __asm("    cpsie   i\n");
}
(see full blinky.c code here)

I am trying not to use other libraries, for educational purposes.

Thanks. Jean

  • Moving this to the TM4 forum.
  • Hi,

    Please download and use TivaWare drivers library - in Tiva/driverlib/cpu.c you will find out the source code for those functions. One note: see these functions are conditionally included/compiled, the tools should be defined - in your predefined symbols section "gcc" should be defined in your case (without " " - if makefile then use -D). 

  • Hi Petrei,

    I did look at cpu.c. Indeed there is a CPUcpsie(void) function, which clears the I bit of the PRIMASK register, but calling this function alone does not seem to produce the right result for my simple blinky.c (ie call the SysTick_Handler() function on regular time interval). Should this function be used in a special way, as opposed to just call it, eg:

    CPUcpsie();

    ?

    Thanks.

  • Hi,

    Did you compiled with -Dgcc to be taken into account? did you included the .h file in yours?

    As you have the code based on direct register addressing, did you used the debugger to see where the problem is? i.e. go step by step and see register modifications and check the corresponding registers.

    Many users of this forum uses the driverlib (which is also in ROM) and there is another function  IntMasterEnable() located in driverlib/interrupt.c file.

  • Hi Petrei,

    I have been using the following compile instructions :

    1) arm-none-eabi-gcc -g -nostartfiles -mcpu=cortex-m4 -mthumb -I/usr/lib/arm-none-eabi/include -L/usr/lib/arm-none-eabi/newlib -T "linkcode.ld" -o blinky.elf blinky.c startup_gcc.c -ldriver

    2) arm-none-eabi-objcopy -O binary blinky.elf blinky.bin

    I didn't know about the -D flag and tried the same as 1) above, this time with -Dgcc instead of -g, as you recommended, but that did not seem to fix the issue.

    I have also tried to use the driverlib/interrupt.c's IntMasterEnable() function, but again the SysTick_Handler() is apparently not being called (the PF2 LED does not toggle...). It could be that my initiation ritual for Systick is not correct but I could not find anything obviously wrong with it (setting the INTEN bit to enable the interrupt). I saved the blinky.c code version with IntMasterEnable() here.

    Thanks for helping. Jean

  • Hello Jean,

    The file path is blocked on TI n/w, so I cannot see the source code. Is the SysTick Handler initialized in the Interrupt Vector Table (startup file)?

    Regards
    Amit
  • Hi Amit,

    Apologies the link seemed to work fine for me. Here it is again :  codepad.org/T57J7YQf (codepad dot org slash T57J7YQf)

    I initialized Systick directly within the blinky.c like this :

    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;                    // clears current
      NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF)|0x40000000;          
      NVIC_ST_CTRL_R = 0x07;                    // enable SysTick with core clock and interrupts
      IntMasterEnable();                        // from interrupt.c
    }

    And the Systick_Handler :

    void SysTick_Handler(void){
      GPIO_PORTF_DATA_R ^= 0x04;                // toggle PF2
    }

    Please let me know if you find anything suspect or very wrong (or indeed a better way to this). Thanks for helping.

    Jean





  • Hello Jean,

    But is the SysTick_Handler mapped to the Interrupt Vector table in the startup file? Also is the GPIO Port F enabled in your code?

    Regards
    Amit
  • Thanks Amit,


    My bad, I was using a default startup_gcc.c and Systick_Handler was pointing to IntDefaultHandler, which I changed to Systick_Handler :

    void (* const g_pfnVectors[])(void) =
    {
        (void (*)(void))((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
    // ...
        SysTick_Handler,                        // The SysTick handler
    // ...

    As for the GPIO Port F, I was using the following initiation :

    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;                    // clears current
      NVIC_SYS_PRI3_R = (NVIC_SYS_PRI3_R&0x00FFFFFF)|0x40000000;          
      NVIC_ST_CTRL_R = 0x07;                    // enable SysTick with core clock and interrupts
      IntMasterEnable();                        // from interrupt.c
    }

    The good news is that now the LED is on (I assume SysTick_Handler is called), but it does not seem to blink yet ; maybe I got something wrong with the RELOAD value and it blinks too fast for me to see it - I'll do more investigation.

    Thanks for your help!

  • Hello Jean,

    Check the value that has been programmed to the LOAD register, It May be blinking too fast. Alternatively, but a Break point in the interrupt handler. This way the BP will slow the action down.

    Regards
    Amit
  • Hi Amit, that was it the LOAD register value was too low.
    Thanks for your help - you saved my day
    Jean
  • All good now - thanks for your help.