Keil RTX5 is quite a feature rich real-time operating system (RTOS). CMSIS and the CMSIS-RTOS2 API makes it very easy to work with.

When setting up the project Run-time environment, the appropriate system initialization code (C Startup) was added.

From there, the RTX5 initialization code is always essentially the same, setting up the SysTick timer with the SystemCoreClockUpdate() function, then initializing and starting the RTOS.

Create main()

Right click on the Source folder under the FVP target, and Add a new item.

Select C file (.c), and create the main.cfile with the contents below:


            #include "RTE_Components.h"
#include  CMSIS_device_header
#include "cmsis_os2.h"

void app_main(void *);

int __attribute__((noreturn)) main (void) {
    SystemCoreClockUpdate();                    // initialize clocks etc

	osKernelInitialize();                       // initialize RTOS

	osThreadNew(app_main, NULL, NULL);          // Create application main thread

	if (osKernelGetState() == osKernelReady)    // If all OK...
		osKernelStart();                        // Start thread execution

	while(1);                                   // If you get to here, something has gone wrong!
Arm Development Studio

Right-click on the project, and select New > Source File from the pop-up menu.

Understanding the code

The function osKernelStart() should never return.

If your code gets to the infinite while() loop, something has gone wrong - most likely with the platform initialization code.

All threads use a prototype of the form:


            void thread(void *);

where the argument is passed as the second parameter of the osThreadNew() function. Use NULL if no argument to pass.

In the above, app_main is used as the main application thread, but this naming is arbitrary. From here, you shall spawn all other threads of the RTOS.