Skip to main content
Explorer
December 9, 2020
Question

osEventFlagsSet/Get not working in ISR? What am I doing wrong?

  • December 9, 2020
  • 8 replies
  • 6292 views

STM32F407VET6 + STM32CubeIDE + CMSIS_OS2

Latest IDE, w/ FreeRTOS 10.2.1, CMSIS-RTOS 2.00

Touch LCD IRQ on PC_5.

EXTI line[9:5] enabled, code gen enabled, and Call HAL Handler checked.

Event defined. Fails with both dynamic and static Allocation.

Include Param: xEventGroupSetBitFromISR enabled (doesn't work disabled either)

I want to set a flag when the touch interrupt is triggered, then resume a handler thread waiting with osEventFlagsWait().

Anyway, IRQ call succeeds.

but (see comments) 

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
 
if (GPIO_Pin == Touch_INT_Pin)
 {
 uint32_t flags = 0x00;
 extern osEventFlagsId_t touchEventHandle;
 
 flags = osEventFlagsSet(touchEventHandle, 0x01);
 // ^ returns 0x01, as expected.
 
 flags = osEventFlagsGet(touchEventHandle);
 // ^ returns 0x00, but should be 0x01
 
  }
 
. . .
 
 }

debug tracing shows touchEventHandle points to the same heap location as FreeRTOS set up.

Those Set/Get routines work fine within a thread.

I've traced through debug, but am unable to discern why it's not working as I expect. The Set routine dives deep into queue related code, so do Event bits use queues? The Get routine seems simpler and doesn't.

Thanks,

-Abe

    This topic has been closed for replies.

    8 replies

    Visitor II
    January 27, 2021

    Did you manage to solve the problem? I have the same issue with STM32l4 CMSIS v2. Setting flags works outside the interrupts.

    EDIT: I guess the workaround of this problem is to use osThreadFlag (which works in ISR) that will start a thread, and in this thread you can set EventFlags.

    Visitor II
    January 4, 2022

    I'm having the same issue, if either of y'all figured it out, I would love an update.

    kronikary thanks for your EDIT, I'll try it out as a work-around, but would love to be able to set flags.

    Graduate II
    January 9, 2022
    Visitor II
    June 1, 2023

    Bumping this thread.

    I have the same problem, even though the NVIC priorities are configured seemingly properly.

    If there are two tasks: A and B.

    A's priority is higher than B's.

    A is waiting for the eventflags and B is running. The bits in the event flag are set in an IRQ, but the xHigherPriorityTaskWoken flag is false, even though task A is blocked because of this.

    If I put an osDelay() into task B, then everything works correctly, but it doesn't make sense as B's priority is already lower and preemption is enabled. 

    Explorer II
    July 12, 2023

    Hello there !

    Same problem here the osEventFlagSet do not work calling from an ISR, but it worked with osThreadFlagSet.

    Any advice on this ? 

    the documentation say that it is possible to use it inside an ISR.

    Graduate
    September 7, 2023

    Hi there!
    Same problem as everyone:grinning_face_with_sweat:

    Visitor II
    January 6, 2024

    For me, the osEventFlagsSet was failing because the timer queue was full.

    Within the IOC file's freertos config parmameters, I made the TIMER_QUEUE_LENGTH larger and it fixed the problem.

    Explorer II
    January 17, 2024

    I have the same problem. I read a post on the ARM community forum with the same problem and no solution was given. It seems CMSIS OS events do not work as expected. I will use osThreadFlags, but ST developers shall report this bug so we do not waste hours of time on a not-working library.

     

    Leo

    Visitor II
    February 9, 2024

    This thread helped me and solved my problem that EventFlags sometimes have not been set.

    Cheers,

    Robert

    Why "xEventGroupSetBitsFromISR" sometimes can not set Event? - Kernel - FreeRTOS Community Forums

    Explorer
    October 6, 2025

    I had also the same issue with using osEventFlagsSet() in ISR. The link above helped resolve the issue. It's indeed necessary to change default value ( = 2) of TIMER_TASK_PRIORITY to value:

    #define configTIMER_TASK_PRIORITY configMAX_PRIORITIES - 1

    Why CubeMX generate a default value "2" instead of "MAX_PRIORITIES - 1" ?

    Any comments from ST people?