Developing uCOS applications for Kinetis devices

This tutorial shows how to use the uCOS III operating system that comes with the Kinetis KSDK to develop applications for the Kinetis devices. Before you begin, install VisualGDB and try creating a basic project for your board to ensure that you can build and debug it.

In this example we will create a basic application consisting of 2 threads: one thread will blink the LED and the other thread will control the first one via the event object. We will show how to use the Kinetis OS abstraction layer API to seamlessly switch from uCOS to FreeRTOS.

  1. Start Visual Studio and launch the VisualGDB Embedded Project Wizard:01-rtosdemo
  2. Proceed with the default setting of creating a new embedded binary:02-prjtype
  3. On the next page select your device. In this tutorial we will use the FRDM-KL25Z board, so we select the MK25Z128VLH4 device:03-device
  4. Select the LED port on your board. The default PTB18 setting corresponds to the red channel of the RGB LED on the FRDM-KL25Z:04-ledblink
  5. Select the debug method that works with your device. We will use the on-board OpenSDA with the firmware from Segger and hence will use the J-Link software. See this tutorial for instructions on downloading the Segger firmware into OpenSDA:05-jlink
  6. Press Finish to generate your project. Build it with pressing Ctrl-Shift-B:06-build
  7. Now we will modify the code to create 2 threads instead of 1:
    • The first thread will wait for an event object by calling the OSA_EventWait() function
    • The second thread will periodically set and clear the event object by calling OSA_EventSet() and OSA_EventClear()

    Replace the contents of the main source file with the following:

    Then press F5 to build and debug you project. Observe how the LEDs blinks in series of short impulses.

  8. Set a breakpoint on the line calling OSA_EventSet() and step into the function. See how the Kinetis OS Abstraction layer calls the OSFlagPost() function that is a part of uCOS: 07-flagpost
  9. Now we will replace uCOS with FreeRTOS. Open VisualGDB Project Properties, go to the Embedded Frameworks page, uncheck the “Kinetis uCOS III” one and check “Kinetis FreeRTOS”:08-rtos
  10. Press “OK”. If you try building your project now, Visual Studio will complain that the FreerTOSConfig.h file is missing and the os_app_hooks.c file won’t build due to uCOS-specific code. Copy the FreeRTOSConfig.h file from a FreeRTOS project to the project directory and remove os_app_hook.c from the project. Now you can press F5 to build and start debugging the project. Note how now the OSA_EventSet() function calls xEventGroupSetBits() that is a part of FreeRTOS:09-setbits

The RTOS abstraction layer provided by Kinetis KSDK allows switching between RTOSes without changing the code of the application as long as you don’t call any RTOS-specific APIs. This allows easily comparing the performance and memory footprint of different RTOSes and picking the optimal one for your task.