AnsweredAssumed Answered

Cortex M4 check and clear instruction?

Question asked by Mikk Leini on Jul 7, 2015
Latest reply on Jul 12, 2015 by Mikk Leini
I'm using FreeRTOS on STM32F4 with ARM-GCC and i need to do some interrupt/task protection for a simple flag checking and clearing function. Here's an example:

int flag;
// Some code sets flag to 1 sometimes
int checkFlagOnce(void)
  int status = 0;
  if (osMutexWait(Mutex, osWaitForever) == osOK)
    status = flag;
    flag = 0;
  return status;

However the mutex code seems to be bit of an overkill. So i was thinking if the Cortex M4 has some special instruction (and ARM-GCC has a intrinsic function) which reads/checks and clears memory atomically?

I checked the instruction set at ARM site but i couldn't find anything like that so i'm double checking.

Or does somebody have a  better idea how this could be done fast and simple?
...except global interrupts disabling/enabling.