↑ Return to Tutorials

Print this Page

Starting with KEIL MDK5 and first step using CMSIS-RTOS RTX

When everybody wants to start developing applications in embedded systems, referring this time on the firmware developement, they want to start smoothly and have low troubles on setting the environment to start programming.  The things that i look for a good tool are:

  • Cost:  Must be cheap or free because I am not a company dedicated of the revenue of embedded systems.  Most nowadays embedded tools are cheap and have very good size of code limitation (32K limit size as default).
  • A very good compiler:  Compiler time is very important to me because i made a lot of builds between my first application and the last one.
  • A base foundation framework with examples:  This is the most important because this gives you a good start for implementing complex applications.  An embedded enviroment without examples is like the best computer without programs, you can’t do anything even if you know what to do.
  • Capability of integrate Hardware Development Tools with a Real-Time Operative System:  The operative systems on a microcontroller is not really neccessary to start for making applications, but learning about it will make your programming level to grow up and force you to sometimes simplify the application code.
  • Documentation:  Always look on the compiler documentation to make you understand more about the IDE and what to do to perform better tasks or better debug procedures.

There are good compilers and IDEs outside here that are common but i will list here the ones I used and that I consider are the best without regarding the order list.

  • Freescale Codewarrior and Kinetis Desing Studio: using KSDK, i don’t like a little Processor Expert
  • MPLAB: a good tool for MIPS architecture
  • Attolic TrueStudio:  I didn’t use it before but reviews are really good.
  • Keil uVision: for ARM based units this is very popular.

Now I will start talking about the last one, Keil uVision, because is a tool that I consider have a good toolchain, lot of examples, good documentation and is based on the ARM CMSIS standard.

What is CMSIS

CMSISv4_small

The ARM® Cortex® Microcontroller Software Interface Standard (CMSIS) is a vendor-independent hardware abstraction layer for the Cortex-M processor series and specifies debugger interfaces.

As told above, extracted from the ARM page, CMSIS is a standard of software packages for Cortex-M vendors, in this way less problematic to migrate a code from one microcontroller to another.  This also reduces software engineering costs because includes interface to peripherals, RTOS, Middleware.  The graphic below lists in the time the hardware and software costs.

HWvsSWCosts

What is KEIL MDK-ARM

mdkpro_680

The MDK-ARM is a complete software development environment for Cortex-M, Cortex-R4, ARM7 and ARM9 processor-based devices. MDK-ARM is specifically designed for microcontroller applications, it is easy to learn and use, yet powerful enough for the most demanding embedded applications.

This above was extracted from the Keil MDK page.  Yes, Keil is an IDE (Integrated Development Enviroment) for microcontrollers only.  But as you see in the above picture has a lot of advantage for being only an IDE, is a software foundation of libraries that enable you to do interesting and complex applications and has a lot of information, tutorials, application notes and of course source code by hardware specific that you can adapt easily to your microcontroller (remember CMSIS, well, Keil is CMSIS compliant).  One interesting feature of the “software pack” is the RTX RTOS.

What is an RTOS

rtxmain11

There is a lot of information on the web about Real Time Operative Systems, but i will be very fast because i am not an expert nor a genius in this and other themes.

This is a combination of software and hardware requirements to do real time applications.  Like computers that have an Operative System (not RT) it is a built in, non visual real time system.  Depending on the application, the RTOS will be a bless or your doom because the debug and implementation of this types of systems are more complex, but literally it is more efficient and faster to do something in a RTOS layer that a non-RTOS system.

Keil RTX RTOS has a lot of features that everybody wants in an RTOS:

  • Royalty-free, deterministic RTOS with source code
  • Flexible Scheduling: round-robin, pre-emptive, and collaborative
  • High-Speed real-time operation with low interrupt latency
  • Small footprint for resource constrained systems
  • Unlimited number of tasks each with 254 priority levels
  • Unlimited number of mailboxes, semaphores, mutex, and timers
  • Support for multithreading and thread-safe operation
  • Kernel aware debug support in MDK-ARM
  • Dialog-based setup using µVision Configuration Wizard

Lets explain more of the RTOS, a brief explanation.  All RTOS have resources to assign to a Thread/Task.  These resources could be external or internal (hardware or pheriperals). A shared resource is a resource that can be accessed by another task; the mechanism of prevent this not to happen is called mutual exclusion.  Again, to be a operative system it must perform multitasking, also called multithreading, that is the process where, in this case, the MCU can switch between tasks (and there are the problems and begins the strategy).

But, how do i switch between tasks?, well, it is done by itself, and that’s the beauty of this.  An also it handles the process of switch the content of the registers between tasks to be non-affected by the kernel.  A kernel is the part of the OS that manage the communication and do the major labor and space of the OS.  Determine which task will run, depends of the scheduler and priority assigned, the higger number in the priority of the task means it has a low priority, i.e. Task 1 has priority 10 and Task 2 has priority 5; Task 2 will execute first and maybe more times than Task 1.

What happens if two or more tasks have the same priority?.  An interesting situation occurs, this is called the round robin scheduling, the current task is executed in a time and have to whatever it has to do in an amount of time and finish or the kernel will pass to the other task.

When Keil means their RTOS is preemtive (and that’s a good thing) they are giving more importance for system execution responsiveness, its deterministic and you can know which task has the control in the time.  The interrupt always is attended by the kernel and must be with low interrupt latency, that is the time where the RTOS has its interrupts disabled.

RTX also support mailboxes, semaphores and mutex.  These are intertask communications and are the way the tasks exchange data efficiently and secure even when you use interrupt subroutines.

You can read more about RTOS advantages on the Keil page.

A little more about threads

Thread

Also called a Task, is a program that has all the resources by its own.  Its an infinite loop and has this states listed above:  Ready, Waiting, Running, Inactive (also called Dormant state).  Some books also list a fifth state, the ISR (Interrupt Subroutine Request) as a state because it affect the code excecution, and they are right.

  • Inactive/Dormant:  Resides in memory but not assigned to the RTOS to execute.
  • Ready:  It can run, but by depending of its priority have to wait or not.
  • Running:  The thread at a time that has the CPU to itself, it only can be one at a time.
  • Waiting:  Threads that are waiting a flag or an event operation to occur.
  • ISR:  Interruption of the excecution of the main code to attend the event.

Now we will end with the core name of this tutorial, using MDK5 for starting a project from the scratch and interfacing with the RTX Real-Time Operative System.

Making a RTOS application using Keil MDK-ARM

This video will explain the basics as fast as possible to start developing a real-time operative system on the FRDM-K64F board.

If you want the project, you can download here directly from my github.

Permanent link to this article: http://cerescontrols.com/tutorials-3/starting-with-keil-mdk5-and-first-step-using-cmsis-rtos-rtx/

1 ping

  1. Adding a RTOS (Real Time Operative System) To Your Project with Keil MDK5 » Ceres Controls

    […] Starting with KEIL MDK5 and first step using CMSIS-RTOS RTX […]

Leave a Reply

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