Skip to main content
abeowitz
Explorer
Dec 9, 2020 12:12 AM UTC
Question

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

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.

10 replies

kronikary
Associate II
Jan 27, 2021 12:45 AM UTC

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.

HPope.1
Visitor II
Jan 4, 2022 10:39 PM UTC

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.

Piranha
Principal III
Jan 9, 2022 8:09 PM UTC
bba.1
Visitor II
Jun 1, 2023 8:04 PM UTC

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
Jul 12, 2023 8:28 PM UTC

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.

Associate II
Sep 7, 2023 7:29 PM UTC

Hi there!
Same problem as everyone:grinning_face_with_sweat:

Visitor II
Jan 6, 2024 3:28 AM UTC

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.

Associate
Jan 17, 2024 5:11 PM UTC

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
Feb 9, 2024 1:35 PM UTC

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

Associate
Oct 6, 2025 2:19 PM UTC

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?