SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: Keil RTX configuration like osFeature flags in cmsis_os.h
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

Keil RTX configuration like osFeature flags in cmsis_os.h

Andrew Irwin
Last updated: September 17, 2023 3:14 am
Andrew Irwin 5 Min Read
Share
SHARE

The osFeature flags in cmsis_os.h allow developers to configure and customize the CMSIS-RTOS API for their specific application requirements. Similarly, Keil RTX provides configuration options to enable or disable certain RTOS features. By setting these configuration options, developers can optimize Keil RTX and reduce memory footprint for resource constrained devices.

Contents
Keil RTX ConfigurationosFeature FlagsOptimizing ConfigurationMemory OptimizationPerformance OptimizationConclusion

Keil RTX Configuration

Keil RTX is configured via a header file called RTX_Config.h. This file contains various macro definitions that control the inclusion of RTX features and modules. Some key configuration options are:

  • osFeature_xxx – Control RTOS feature inclusion
  • osRtxConfig.thread_num – Number of concurrent threads
  • osRtxConfig.timer_num – Number of concurrent timers
  • osRtxConfig.event_num – Number of concurrent events
  • osRtxConfig.mutex_num – Number of concurrent mutexes
  • osRtxConfig.semaphore_num – Number of concurrent semaphores
  • osRtxConfig.memory_pool_num – Number of memory pools
  • osRtxConfig.messagequeue_num – Number of message queues

osFeature Flags

The osFeature flags allow inclusion of specific RTOS services and features in Keil RTX. These are similar to the CMSIS-RTOS osFeature flags. Some common osFeature flags are:

  • osFeature_MainThread – Main thread support
  • osFeature_Pool – Memory pool allocation support
  • osFeature_MailQ – Mail queue support
  • osFeature_MessageQ – Message queue support
  • osFeature_Signals – Signal support
  • osFeature_Semaphore – Semaphore support
  • osFeature_Wait – Wait API support
  • osFeature_SysTick – SysTick timer support

For example, to disable semaphores in Keil RTX: #define osFeature_Semaphore (0)

This removes any code related to semaphores from the RTX library, reducing code size. The developer must ensure no semaphores are used in the application when this option is disabled.

Optimizing Configuration

Proper configuration of Keil RTX allows optimization of the RTOS footprint for each application. Here are some techniques for optimization:

  • Set thread_num, timer_num, event_num etc. to exact values needed, don’t use defaults.
  • Disable any osFeature flags for RTOS services not used by the application.
  • Disable osFeature_SysTick if you have a custom system timer.
  • Disable osFeature_Signals if you are not using signals.
  • Disable xx_num options like messagequeue_num if not using that RTOS object.

As an example, a simple application may only need 2 threads, 1 mutex, and no other objects. The configuration could be: #define osRtxConfig.thread_num 2 #define osRtxConfig.mutex_num 1 #define osFeature_Signals 0 #define osFeature_Semaphore 0 #define osFeature_MessageQ 0

This eliminates all unused components and allocators, reducing RAM usage. The developer must take care not to use any disabled RTOS services in the application code.

Memory Optimization

When memory usage is a critical constraint, additional techniques can optimize Keil RTX memory:

  • Use static memory allocators rather than dynamic memory pools.
  • Place RTX objects in specific memory regions using the SECTION attribute.
  • Reduce thread stack sizes to exactly what is needed.
  • Use the Small Memory Model configuration for limited RAM.

The Small Memory Model configures RTX for constrained devices. It disables dynamic memory allocation and configures static memory with reduced sizes for kernel objects. For example: #define OS_APP_DATA_SIZE 32 #define OS_TASK_CNT 2 #define OS_STACK_SIZE 128

This configures RTX for just 2 threads with small 128 byte stacks. The OS_APP_DATA_SIZE defines kernel object memory.

Performance Optimization

Besides memory usage, Keil RTX can also be optimized for performance:

  • Increase thread_num to allow more concurrent threads.
  • Use larger stacks if threads do more work.
  • Increase osRtxConfig.timer_num for more active timers.
  • Enable round-robin scheduling for shorter thread waits.

However, larger data structures will increase memory usage. A balance must be found between performance and memory constraints.

Advanced optimizations can configure the RTX scheduler and tick interval. But this requires in-depth knowledge of the internals. For most applications, the default scheduler offers a good balance.

Conclusion

Keil RTX provides extensive configuration options to customize the RTOS for your specific application requirements. Optimizing the configurations allows reducing memory usage while still maintaining the required performance. Profiling the application can identify unnecessary components that can be disabled. With prudent configuration, Keil RTX can provide an efficient RTOS even in memory constrained devices.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Differences between osDelay() and osWait() calls in Keil RTX
Next Article LCD Interfacing with ARM Cortex M0+ LPC845
Leave a comment Leave a comment

Leave a Reply Cancel reply

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

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Estimating Stack Memory Needs for Arm Cortex-M Applications

When developing applications for Arm Cortex-M based microcontrollers, properly estimating…

5 Min Read

Is UART the same as serial?

The short answer is yes, UART is generally considered to…

8 Min Read

Does setting a section’s attributes using MPU affect the CPU’s ordering of the specific section?

Setting a section's attributes using the Memory Protection Unit (MPU)…

6 Min Read

Preventing Interrupt Nesting on Cortex-M using BASEPRI

The Cortex-M processor implements a scheme called "priority masking" to…

8 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account