cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 H7755ZI- FREE RTOS- Task notification from ISR

STork.1
Associate III

Hello

I created a task that is needed to be executed from ISR. previously I did for ESP32 but using the same manner, I could not do it.

Based on my search, I found 2 ways which I tried but could not have my task run.

first manner:

Inside the ISR:

BaseType_t checkIfYeildRequired;
 
checkIfYeildRequired=xTaskResumeFromISR(ADXL_HandlerHandle);
 
portYIELD_FROM_ISR(checkIfYeildRequired);

Then first line of my task in for loop:

 vTaskSuspend(NULL);

Second Manner:

BaseType_t pxHigherPriorityTaskWoken = pdFALSE;
 
vTaskNotifyGiveFromISR(ADXL_HandlerHandle , &pxHigherPriorityTaskWoken);
 
if ( pxHigherPriorityTaskWoken == pdTRUE) {
 
portYIELD_FROM_ISR(pxHigherPriorityTaskWoken);

Then first line of my task in for loop:

ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

How I created the task outside of the main function as a global variable:

/

* Definitions for ADXL_Handler */
 
osThreadId_t ADXL_HandlerHandle;
 
const osThreadAttr_t ADXL_Handler_attributes = {
 
 .name = "ADXL_Handler",
 
 .priority = (osPriority_t) osPriorityNormal,
 
 .stack_size = 1024 * 4
 
};
 
/* Definitions for Clock_Task */
 
osThreadId_t Clock_TaskHandle;
 
const osThreadAttr_t Clock_Task_attributes = {
 
 .name = "Clock_Task",
 
 .priority = (osPriority_t) osPriorityNormal,
 
 .stack_size = 256 * 4
 
};
 
 

then inside main function:

/* creation of ADXL_Handler */
 
 ADXL_HandlerHandle = osThreadNew(ADXL_Handler_TaskFun, NULL, &ADXL_Handler_attributes);
 
 
 
 /* creation of Clock_Task */
 
 Clock_TaskHandle = osThreadNew(Clock_Task_Fun, NULL, &Clock_Task_attributes);
 
 
 
 osKernelStart();

Could you please tell me What I am supposed to ?

11 REPLIES 11
Piranha
Chief II

Apparently your search didn't include the official FreeRTOS documentation, where it specifically says that the first method is broken and points to a correct one:

https://www.freertos.org/taskresumefromisr.html

Also on Stack Overflow:

https://stackoverflow.com/questions/39015586/freertos-task-not-resuming

And no - that's not specific to FreeRTOS. Such a method is principally broken.

If you are using the CMSIS-RTOS v2 wrapper, then use the appropriate methods from it:

https://www.keil.com/pack/doc/CMSIS/RTOS2/html/group__CMSIS__RTOS__ThreadFlagsMgmt.html

STork.1
Associate III

Thanks for answer. I am new to this stuff. was a a bit confusing... . If I write a code like similar to the example 1 on this page:

https://www.freertos.org/RTOS_Task_Notification_As_Counting_Semaphore.html

in this line no more event is undefined.

 if( xEvent != NO_MORE_EVENTS )

and also these terms are not defined:

prvClearInterruptSource();

vCheckForErrorConditions();

xQueryPeripheral();

pdMS_TO_TICS

Where are they defined ?

Include files, configuration... If you cannot solve such basics, that means you have to learn the software development with C programming language in general. Dealing with RTOS and other non-trivial things, is not for beginners.

And read ALL of my previous post...

STork.1
Associate III

although your first reply was really helpful, please reconsider what you wrote as the second reply, nothing can be learned from it.

if you would like to help please address the problems strait forward.

from where I have to include files? what kind of configs you talk about?

I know enough about C/C++ to work with RTOS.

I use Nucleo development board and usually all the stuff should be downloaded.... or I think wrong...

here is the community, I think made to learn , not discouraging others.

If you do understand C, then the respective files can be found with a simple search tool, which can search in the file contents. For example, Notepad++ can do it easily. But, that is not the real problem here. I'll repeat again - read ALL of my first post, not only some part of it. If you would have done that, you wouldn't have a problem with undefined names in the first place.

I'm not discouraging, I'm encouraging - to read more and carefully!

By the way, there is a nice test, which shows if one understands multi-threading:

https://deadlockempire.github.io

Pavel A.
Evangelist III

@STork.1​ Indeed examples on the FreeRTOS site may be difficult to understand for beginners.

Some hints: they use prefixes for functions and variables, get to learn their meaning.

"prv" means private. As we are not expected to call private functions in the RTOS itself, this is a strong hint that prvClearInterruptSource is a user's own private function. This is why you cannot find it in the API reference. Other functions that you could not find are user's own functions as well, they are up to the user to implement.

Finally, pdMS_TO_TICS is just a silly typo. Should be pdMS_TO_TICKS.

Holy... Indeed, except for the tick macro, those are not a real functions, but just a placeholders for the example.

Thanks, I created a task and it works properly. scheduler works. when I wanna enable task notification the task does not work and based on RTOS DOCS I did all the required thing as far as I know do you have any hints ?

Please post a small example.