Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Follow+Star Public Account Number, don’t miss wonderful content
Choosing Between µCOS and FreeRTOS: A Comprehensive Guide
Author | strongerHuang
WeChat Public Account | strongerHuang
Recently, some friends have been asking: When learning RTOS, should I choose µCOS or FreeRTOS?
In fact, similar questions are often asked by colleagues, and there is no unified answer. Generally speaking, once you learn one RTOS, learning other RTOS becomes relatively easy.
At present, both µCOS and FreeRTOS are relatively suitable for beginners. µCOS’s source code is relatively standardized and easier to understand. FreeRTOS has a higher market share and more learning materials available.
Of course, they each have their own characteristics. Today, I will share with you the coding standards of these two RTOS, taking uC/OS-III V3.08.02 and FreeRTOS V10.5.1 as examples.

Coding Standards

uC/OS and FreeRTOS both follow the MISRA C coding standard and support PC-Lint static checking. Both official documents explain this.

Tip:

The MISRA C standard refers to the automotive C language development standard. You can refer to the article shared earlier: What is the MISRA C: 2012 Standard?

1. uC/OS

The uC/OS article clearly states that it follows the MISRA C:2012 standard and also supports PC-Lint’s static checking.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

2. FreeRTOS

FreeRTOS also clearly states that it adopts the MISRA C coding standard, but does not support standards after C99, and supports PC-Lint static checking.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

FreeRTOS has a lot of explanations (comments) in its source code that may cause exceptions in PC-Lint static checking, which is not present in uC/OS source code.

For example:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Configuration Files

The configuration files (also known as “trimming” files) for both RTOS have somewhat similar content and are categorized.

However, uC/OS’s classification and comments are more user-friendly and easier for beginners to understand.

1. uC/OS

The configuration file for uC/OS is usually: os_cfg.h

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

2. FreeRTOS

FreeRTOS configuration file is usually: FreeRTOSConfig.h

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Headers

The content of the headers for both RTOS is somewhat similar, just one is centered and the other is left-aligned.

1. uC/OS

Includes RTOS version, copyright statement, open-source protocol statement, etc.:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

2. FreeRTOS

Includes RTOS version, copyright statement, open-source protocol statement, website, etc., similar to uC/OS.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Naming

The naming rules for both RTOS differ significantly, but both conform to conventional code naming rules.

1. File Names

uC/OS uses the format 【os_system_file】, which appears more standardized (reflecting modularity).

FreeRTOS is more straightforward, which may be due to a lack of long-term planning during naming, and has continued to be used for compatibility. (This is more likely to cause file name conflicts)

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

2. Macros

Both have similarities: underscores separate uppercase letters, but prefixes differ.

For example, for the “configuration file: uC/OS starts with【OS_CFG_】, while FreeRTOS starts with【config】.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

3. Data Types

uC/OS-defined data types are relatively more common and more suitable for beginners.

FreeRTOS-defined data types are more “systematic,” suitable for experienced users, and relatively less friendly for beginners.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

4. Function Names

Both are somewhat similar, differing prefixes, and are distinguished by 【uppercase letters at the beginning】.

For example, the function name for creating tasks:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

FreeRTOS’s prefixes are described officially as follows:

  • Static (static) functions are prefixed with prv, for example: prvIdleTask function.

  • API functions are prefixed with their return type, with void types prefixed with v as a suffix. For example: vTaskDelete function.

Comments

// /* */ are the two most common ways to comment, but these two RTOS mainly use 【/* */】 comments.

The position of comments is also important, usually one line above the code or at the end of the code line (after the code).

Here, it is important to note that FreeRTOS does not have reliable comment functions for parameters, return values, etc.

Taking the “create task function as an example:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Of course, the function comment information for FreeRTOS is described in detail in the manual.

Indentation

Both RTOS use the same indentation method, which is 4 spaces:

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Here, it is important to remember not to mix tabs and spaces, otherwise the code will be a mess. (This often occurs in many beginners or junior engineers, and the code is simply unbearable to look at

Word Abbreviations

Different fields have different abbreviations. There are also some common abbreviations in RTOS, such as:

Abbreviation Meaning
Addr Address
Blk Block
Chk Check
Clr Clear
Cnt Count
Ctr Counter
Ctx Context
Cur Current
Del Delete
Dly Delay
Err Error
OS Operating System
CPU Central Processing Unit

That’s all for this article. The above only lists some typical coding styles; for more details, you can take some time to study on your own.

———— END ————

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

● Column “Embedded Tools

● Column “Embedded Development”

● Column “Keil Tutorial”

● Selected Tutorials from Embedded Column

Follow the public account reply “Join Group” to join the technical exchange group according to the rules, reply “1024” to see more content.

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Choosing Between µCOS and FreeRTOS: A Comprehensive Guide

Click “Read the Original” to see more shares.

Leave a Comment

Your email address will not be published. Required fields are marked *