Skip to main content
autukuri
Associate II
July 29, 2008
Question

Enable\Disable Interrupts

  • July 29, 2008
  • 3 replies
  • 1421 views
Posted on July 29, 2008 at 19:01

Enable\Disable Interrupts

    This topic has been closed for replies.

    3 replies

    autukuri
    autukuriAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:40

    Is there a quick way to temporarily disable and enble the interrupts on the Cortex? I have a critical timing loop which varies in time due to USB, DMA, and other interrupts. Is there a way to suspend interrupts for a few microseconds? I have worked with other ST parts (like the ST7) that had assembly instructions to perform this task. I am unable to find this info in the datasheet.

    Thanks in advance.

    joseph239955
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 12:40

    You can use the PRIMASK register. When it is set to 1, it disable all

    exception except hard fault exception and NMI exception.

    To do this, you can use assembler instruction

    CPSID I

    or

    MOVS r0, #1

    MSR PRIMASK, r0 ; move R0 into PRIMASK

    To re-enable interrupt, you can use

    CPSIE I

    or

    MOVS r0, #0

    MSR PRIMASK, r0

    If you use RealView Compiler, or KEIL RealView Microcontroller Development Kit, you can use C functions

    __disable_irq();

    and

    __enable_irq();

    (http://www.keil.com/support/man/docs/armccref/armccref_cjafbcbb.htm)

    Or if you are using the ST firmware library, you can use the functions defined in cortexm3_macros.h

    void __SETPRIMASK(void); // disable interrupts

    void __RESETPRIMASK(void); // enable interrupts

    or functions in stm32f10x_nvic.h

    void NVIC_SETPRIMASK(void); // disable interrupts

    void NVIC_RESETPRIMASK(void); // enable interrupts

    which I believe has the same functions.

    disirio
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 12:40

    ''cpsid i'' disables interrupts, ''cpsie i'' re-enables them. Another option is to modify the BASEPRI register.

    regards,

    Giovanni

    ---

    ChibiOS/RT

    http://chibios.sourceforge.net