cancel
Showing results for 
Search instead for 
Did you mean: 

Only allow ONE type of interrupt to interrupt critical functions in my code?

arnold_w
Senior

I am working with the STM32L4 and STM32F4 microcontrollers and compiling with CubeIDE and System Workbench. I use no realtime operating system, I have no semaphores/mutexes, but I'm allowed to write code in C++. Every once in a while I want to execute some critical functions almost uninterruptedly, only one type of very high priority timer interrupt is allowed to interrupt the critical function. What's a clever way to accomplish this? I can't disable all other interrupt enable bits (would be a huge waste of instructions/time) and I can't use __disable_irq() because that disables the important timer interrupt as well. I could create a function a called executeInInterrupt(functionPtr_t functionPtr) that I pass my critical function myCriticalFunction() to and only the important timer interrupt would be assigned more important priority than the interrupt used by the executeInInterrupt()-function. But what if myCriticalFunction takes arguments, myCriticalFunction(uint32_t myArg1, const char* myArg2)? The only solution to that I can think is to have static volatile copies of all the arguments, but then the arguments needs to be first be copied before executeInInterrupt(myCriticalFunction) can be called. Can anybody think of a better solution? Can I maybe somehow cast a pointer to the arguments on the stack into some type of struct pointer that the interrupt routing can use to get the arguments?

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

You can mask interrupts by priority by setting the BASEPRI field. If your high priority interrupt is priority 1, then set BASEPRI=2 to mask everything else.

__set_BASEPRI/__get_BASEPRI

0693W00000HrSQuQAN.png

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

You can mask interrupts by priority by setting the BASEPRI field. If your high priority interrupt is priority 1, then set BASEPRI=2 to mask everything else.

__set_BASEPRI/__get_BASEPRI

0693W00000HrSQuQAN.png

If you feel a post has answered your question, please click "Accept as Solution".
arnold_w
Senior

Perfect, thank you!