Skip to main content
harry anders
Associate III
May 13, 2018
Solved

How to find global interrupt state of STM32 MCU?

  • May 13, 2018
  • 7 replies
  • 3439 views
Posted on May 13, 2018 at 11:22

Hi,

I'm working on a fairly complex code written by other employees at our company where interrupts are globally disabled and enabled in multiple places using:

__enable_irq();

and

__disable_irq();

Sometimes it is not clear whether interrupts are currently enabled or disabled and I need to know the status of the global interrupt flag. How can I find the status and is it stored in a register that is accessible from user code or the HAL libraries?

I am working on 2 MCUs:

STM32f429 and STM32f777

Best regards

    This topic has been closed for replies.
    Best answer by waclawek.jan
    Posted on May 13, 2018 at 12:18

    __get_PRIMASK()

    The global interrupt flag is bit 0 of PRIMASK (which is a register of the processor).

    Read PM0253/PM0214 and Core registers and CMSIS intrinsic functions chapters.

    JW

    7 replies

    AVI-crak
    Senior
    May 13, 2018
    Posted on May 13, 2018 at 12:17

    Run away from this company, and do not look back.

    The program code in which global interrupts are prohibited is one huge crutch. This means that at the very beginning they could not read the documentation, and later could not stop.

    On the issue of how to determine:

    If your code is executed, then interrupts are prohibited. Otherwise, an interrupt will occur, in which there are already two or three missed goals.
    waclawek.jan
    Super User
    May 13, 2018
    Posted on May 13, 2018 at 12:27

    Run away from this company, and do not look back.

    You are right, but with this approach you might find yourself mining coal pretty soon ;)

    There are sins in every larger programming projects. You can chose to educate your colleagues but to do that you'll have to become an accepted expert within that company; and you can't do that by running away.

    I've learned at least as much by trying to repair failed programs as by reading the good ones.

    JW

    waclawek.jan
    waclawek.janBest answer
    Super User
    May 13, 2018
    Posted on May 13, 2018 at 12:18

    __get_PRIMASK()

    The global interrupt flag is bit 0 of PRIMASK (which is a register of the processor).

    Read PM0253/PM0214 and Core registers and CMSIS intrinsic functions chapters.

    JW

    harry anders
    Associate III
    May 13, 2018
    Posted on May 13, 2018 at 12:36

    Thank you. That is exactly what I was looking for. You saved me from a great hassle.

    AVI-crak
    Senior
    May 13, 2018
    Posted on May 13, 2018 at 13:13

    This is not a solution, it is a reprieve before execution.

    A normal solution is considered to be different levels of interrupt priorities, the transfer of bold program code from interrupts to the task area, and a competent prioritization of the tasks themselves.

    Most likely your project requires a very fast response to external influences. In this case, the classical os crowding out is not suitable for you. You need streaming wasps, where there is no displacement of tasks. Each active task is certainly performed according to the general queue. The time of its active work is the analog of priority, and can have a value from 1% to 100% of the time interval selected for the standard (almost always 1ms). Under such conditions, the response to an external event can be less than 1 ms, and the processing of the event itself is instantaneous and unconditional.

    https://community.st.com/external-link.jspa?url=https%3A%2F%2Fwww.segger.com

    or my option

    https://community.st.com/external-link.jspa?url=https%3A%2F%2Fbitbucket.org%2FAVI-crak%2Frtos-cortex-m3-gcc%2Fsrc%2Fdefault%2F

    .