It takes two to tango: Simplifying Linux/WinCE real-time applications development using 8- and 32-bit low-cost microcontrollers

by Eric Gregori , TechOnline India - February 23, 2011

An article on simplifying Linux/WinCE real-time applications development using 8- and 32-bit low-cost microcontrollers

Seeing the terms 'Linux/WinCE' in the same sentence as '8-bit probably comes as a surprise to most people. As the title, 'It takes two to tango' suggests, 8-bit microcontroller units (MCUs) can actually make Linux and WinCE software application development easier. The trick is to divide and conquer the job. First, you have a high-performance microprocessor, such as a Freescale i.MX or Power Architecture host processor, which executes a powerful OS. Next, you have the real-time bare metal code execute on an 8- or 32-bit MCU. The overall system, while more complex, is actually easier for developing and maintaining software.

The key to simplifying a design by adding an MCU is synergy. The MCU must add to the solution, enough to offset the additional cost of the silicon. If the problem is looked at from a purely hardware point of view, it’s hard to see an advantage. It’s only when the software is taken into consideration that the benefits of having the additional silicon is revealed. The software benefits are most apparent when the design calls for real-time I/O or lots of general-purpose I/O.

The addition of Freescale ports of Linux, Android, or WinCE to your system design are many. These operating systems offer great graphical interfaces, media playback capability, and powerful communications stacks. The list goes on and on. To read more about using Android in the industrial space, check out this blog. Although debatable, what Linux and WinCE lack is true real-time support. For the sake of this discussion, when I say real-time, I mean that the latency in response to hardware events is in microseconds.

Real-time is exactly what MCUs excel at. Equipped with peripherals dedicated to do as much real-time processing as possible in hardware, modern MCUs are the perfect solution for the hard timing requirements of most electromechanical systems. Motor control and motion sensing are common design requirements for industrial systems. These design requirements are also perfect examples of where MCUs can significantly simplify the software design.

When working with multiple processors, managing the communications between them is a critical design challenge. Modern application processors have tackled this problem by integrating multiple communication peripherals on-chip, including advanced communication peripherals like Ethernet and USB. Of-course the prerequisite peripherals such as the UART, I2C, and SPI are present. The free public source Linux, Android, and WinCE BSP’s from Freescale include drivers for I2C, SPI. USB host and device profiles are also available. Using these drivers makes communicating with the MCUs easy via a user space application. On the MCU side, Freescale provides free communication stacks for Ethernet and USB peripherals.

Simplifying software development

Let’s consider how the extra silicon can simplify software development.The 3-axis accelerometer has become a popular industrial sensor. Often used for vibration detection and orientation, now it’s even possible to use them for user input. The algorithms for vibration detection and tap detection are great examples of real-time algorithms that are difficult to implement under an OS. See the Freescale application note: AN3751-Frequency Analysis in the Industrial Market  for more information. For example, suppose you want to implement these algorithms under a Linux system.

You have to write a custom driver to capture the raw 3-axis from the sensor via a timer interrupt at a rate of about 350 Hz, and store the data in a buffer. Then a buffer full signal triggers a user space application that grabs the data from the buffer and implements the appropriate algorithms (FFT, filtering, pulse detection). This is the point where a comparison of software development costs must be honestly evaluated. Does your software team have Linux driver development experience? If so, how much time will the development and testing of the driver take away from your actual application development time?

Now let’s take a look at doing the same thing, but off-loading the real-time to a separate MCU. The Freescale MMA9550L is an intelligent 3-axis accelerometer embedded with a 32-bit MCU. The MCU includes built-in algorithms for many common 3-axis accelerometer tasks: tap/double tap detection, filtering, threshold detection, and a FIFO queue. Out of the box, the FIFO can be used to replace a custom driver. In addition, the microcontroller/sensor allows the user to develop his/her own algorithms, and run them within the MMA9550’s flash.

The AN3751 application note discusses how to implement a FFT algorithm directly on the MCU embedded with the sensor. Using this sensor with an embedded microcontroller, you can completely off-load your 3-axis accelerometer real-time requirements from your processor’s operating system, and simply read the preprocessed data via the I2C interface. In addition, the MMA9550L can be used as a sensor hub that routes and processes data from other sensors in your system.


Fig 1: MMA9500L block diagram


General-purpose I/O pins

Every industrial project needs general-purpose I/O pins. In addition, many projects need the ability to read or generate precision pulses. These are requirements that application processors can do, but not nearly as well as MCUs.  Application processors only have so many pins, and by the time you add all the external interfaces, general-purpose I/O pins (GPIO) can be hard to find. Again, it’s the MCU to the rescue.

The Freescale S08JM is a full speed USB device-enabled 8-bit MCU that includes up to 51 GPIO pins, a 12-bit analog to digital converter (ADC), and eight timers. Using this device, you could be generating four PWM signals reading four PWM signals, and reading up to 12 channels of 12-bit analog signals all at the same time. Then you can preprocess the data in the MCU and send the results to application processor’s OS with the USB interface. Using the free JM boot loader available from Freescale, you could even program the JM part from the application processor. Think of the JM series of USB-enabled MCUs as I/O extensions to the i.MX family of application processors. The free USB device firmware for the S08JM includes a USB bootloader, USB HID stack, generic USB endpoint stack, and a USB CDC stack for supporting virtual serial devices. Using LibUSB you can develop HID and generic interfaces in Linux or Android to communicate with the JM from a user space application. With the CDC serial stack, any modern Linux kernel can communicate with the JM over a virtual serial port.


Fig2: S08JM family block diagram.

Fig 3: USB stack with PHDC support.


Heavy silicon

Finally, there is heavy silicon in the Freescale MCU world, the ColdFire MCF5225x family. This 80 MHz 32-bit part includes: USB host and device, Ethernet, up to 512 KB of flash, and 64 KB of RAM. For I/O, it has 96 GPIO pins, and even a CAN interface. This MCU is powerful enough that it could run many industrial applications stand-alone. The OS on the application processor would simply be required to provide GUI services. Using the USB port, the MCF5225x can be connected directly to an i.MX or PowerPC system. Or, using Ethernet, multiple MCF5225x’s can be connected to an i.MX or PowerPC system.


Fig 4: MCF5225x block diagram


To demonstrate the synergy of application processors and microcontrollers, I have created two demos that use the Freescale ColdFire MCF5225x Tower Mechatronic Board. If you are not familiar with the Freescale Tower System, it’s an expandable microcontroller development system. You can find out more here: The Tower Mechatronic board has a ColdFire MCF5225x microcontroller, 3-axes accelerometer, and 12 channel touch sensor. In addition, it has 8 PWM ports for controlling external PWM controlled servo motors.

You can find a video of the first demo here: This demo shows how to control four servo motors from a Chumby One via USB. The Tower Mechatronic board looks like a CDC serial USB device to the Chumby One. The Linux usbserial driver (drivers/usb/serial/usb-serial.c) provides generic USB to serial support. This driver has been part of the kernel since 2000. When loading the usbserial module, you provide the VIN and PID of the USB device you are connecting to. When the device is plugged in, it’s enumerated and assigned a /dev/ttyUSBx node. To communicate with the USB CDC serial device, simply open /dev/ttyUSBx just like any serial port. All the software for the demo was done is user space, with no kernel modifications were required. (I used the stock kernel shipped with the Chumby).


Fig 5: Mechatronics - a system that combines sensors, actuators and intelligence - using i.MX233 based Chumby.


The second demo extends the Chumby One demo by adding video analytics, replacing the 454 MHz i.MX233 Chumby One with an i.MX51 and the i.MX51EVK. A pan and tilt mechanism controlled by the ColdFire MCF5225x Tower Mechatronics Board connects to the i.MX51EVK via USB. The web camera mounted on the pan and tilt mechanism also connects to the i.MX51EVK via USB. The i.MX51 running a OpenCV face detection algorithm tracks faces with the web camera.


Fig 6: Diagram of devices

Fig 7: Build smarter robots


About the author:

Eric Gregori is Senior Firmware Applications Engineer at Freescale and this article appeared on the company's Software Meets Silicon blog pages:


About Author


blog comments powered by Disqus