0
\$\begingroup\$

Today is my first day on FreeRTOS. I want to use it in STM32F103 for simple task handling as reading data from analog sensor and sending remotely using GSM module.

I want to know what are the do's and don'ts of writing a good task in FreeRTOS? Specifically is it allowed to write a blocking code, for() loop while() loop, inside a task?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You should read a book on RTOS usage. \$\endgroup\$
    – Jeroen3
    May 30, 2019 at 8:58
  • 2
    \$\begingroup\$ See this FreeRTOS article on tasks. You basicly should always write your tasks as infinite loops. \$\endgroup\$
    – olltsu
    May 30, 2019 at 9:25
  • \$\begingroup\$ Judging by this and your other question, i'm not sure you know what a task is, or what an OS is useful for. \$\endgroup\$
    – brhans
    May 30, 2019 at 11:16

1 Answer 1

3
\$\begingroup\$

It depends a little bit on what you're implementing but as mentioned in the comments as tasks usually handle/emit reocurring events they all should contain an infinit loop so this is not a don't.

What you should keep in mind when introducing multiple tasks is the required processing time and the fact that a context switch requires resources and processing time as well. To reduce unecessary context switching you shouldn't use normal wait loops in your tasks as you might would do in a normal single threaded application, use the delay functions provided by the FreeRTOS instead to set the task asleep.

Further, as you cannot control when a context switch happens, don't forget to protect any shared resources with mutexes.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.