Search by Tags

Colibri VF61 Real-Time Demo (XY Pen Plotter)

 
Applicable for

Tags
Qt

Article updated at 12 May 2020
Compare with Revision




eCos

This article shows how to build all required elements to run the Colibri VF61 real-time demo using an XY pen plotter. The demo shows the real-time capabilities of the Toradex​ Colibri VF61 computer on module on a real-world problem. The NXP/Freescale Vybrid based module has two cores, an ARM Cortex A5 along with a Cortex M4. The XY pen plotter is controlled by a custom eCos® RTOS based firmware on the Cortex M4 core. The user interface is created using Qt® running on Linux.

The hardware is from Makeblock with some improvements on the mechanic's side for better reliability. Instead of using Arduino, the plotter is connected to our Colibri VF61 via an Iris carrier board. For easier handling of the whole demo setup, we developed a custom connector board. You can refer to the schematics of that board when attempting to connect such a printer to the Iris carrier board.

To run this demo no hardware (apart from a Colibri VF61 module and its accompanying carrier board) is required. Of course, you won't get anything plotted but for studying/understanding the whole setup it is usually good enough. The firmware and the user interface work even without any hardware connected since the stepper motors are controlled by stepwise GPIO impulses without any feedback loop. The only feedback we get from the hardware is the two limiting switches used for reference at start-up. However, the referencing times out after about 10 seconds and the firmware subsequently behaves as if the referencing actually succeeded.

There are multiple options on how to communicate and run the firmware. By default, we use the MultiCore Communication (MCC) library and the firmware is running from DRAM.

Building Linux Image with Qt

The Linux image is a custom image which can be built using the OpenEmbedded core build system. The image contains Qt 4.8 libraries as well as utilities to load the firmware into the Cortex M4 core. The additional "meta-xypenplotter" layer adds the additionally needed recipes for software packages and the image.

First, one needs to create an OpenEmbedded core-based default Toradex image build environment: OpenEmbedded (core)

Before building the image, some modifications need to be done. First, switch to the stuff folder and get the additional meta-xypenplotter layer from GitHub:

$ cd ~/oe-core/stuff
$ git clone https://github.com/toradex/meta-xypenplotter.git
$ cd ~/oe-core/build

Then, this additional layer needs to be included in your local conf/bblayers.conf. Extend the BSPLAYERS variable:

BSPLAYERS ?= " \
  ${TOPDIR}/../stuff/meta-toradex \
  ${TOPDIR}/../stuff/meta-xypenplotter \
"

Next, the image can be built using this command:

$ MACHINE=colibri-vf bitbake qt4e-xyplotter-image

The resulting image can be flashed via TFTP or an SD-Card using the update.sh script (also refer to the release notes of our standard image).

When starting up for the first time, some configuration in the boot loader needs to be done. Connect to the serial console at UART A and interrupt the boot process. Then enter the following settings:

set vidargs video=dcufb:1024x600
set memargs mem=240M
save

Once started, one needs to make sure the MCC kernel module gets loaded properly:

# echo mcc > /etc/modules-load.d/mcc.conf
# modprobe mcc

Building the Qt User Interface

Once the Linux image is deployed, it is time to deploy the Qt application itself. Our demo requires a Qt development environment to build and deploy the UI. For a real project, to gain better reproducibility and easier deployment of the root file system including the Qt application, it is recommended to create an OpenEmbedded core recipe that would build the Qt based user interface and include it into the image directly.

Prepare Qt SDK

To compile the SDK and setup Qt Creator, refer to this article:

How to set up QT Creator to cross-compile for embedded Linux

Building the Qt User Interface

Once this is set up, one can get the XYPenPlotter demo from GitHub as well.

$ cd ~/QtProjects/
$ git clone https://github.com/toradex/XYPenPlotter

Import the project and compile it. You might see this error when compiling with libmcc support:

error: linux/mvf_sema4.h: No such file or directory

Currently, not all Kernel headers are copied to usr/include/linux of the sysroot. As a work-around, copy the file from the Kernel version specific header location:

$ sudo cp /usr/local/oecore-x86_64/sysroots/armv7ahf-vfp-neon-angstrom-linux-gnueabi/usr/src/linux-3.0.15/include/linux/mvf_sema4.h /usr/local/oecore-x86_64/sysroots/armv7ahf-vfp-neon-angstrom-linux-gnueabi/usr/include/linux/mvf_sema4.h

The touchscreen uses tslib, which needs to be configured explicitly for Qt Embedded using an environment variable on the target. In order to make touchscreen work when running the application out of QtCreator, the "Run Environment" needs to be configured in the Project settings:

QWS_MOUSE_PROTO: tslib:/dev/input/touchscreen0

Furthermore, add the argument "-qws" in the "Run" section in order to run directly on the Framebuffer device.

At this point, you should see the Qt user interface on the target.

A close look at the output shows that loading the firmware to the Cortex M4 currently fails. This is to be expected since the firmware is not deployed yet:

Loading firmware...
mqxboot: returned 1

By default, the UI is deployed to /opt/xypenplotter/. The the pre-installed start scripts from the meta-xypenplotter layer will start the user interface on next startup.

Building the eCos® Firmware

This step builds the firmware running on the Cortex M4 which controls the printer hardware (limiting switches, magnetics and stepper motor). As the first step, the pre-requisites to build eCos applications or kernels need to be prepared. Refer to the main eCos article (eCos on Colibri VF61 Cortex M4) or directly to the documentation provided in the eCos distribution on git.toradex.com (PDF format from our doc server).

Instead of building the firmware, one can also download a pre-built version (using MCC and running from DRAM): plotter.bin. Copy the firmware into the /var/cache/xyplotter/plotter.bin folder of your target.

Building the eCos® Kernel (Optional)

For this step please refer to the eCos article.

eCos on Colibri VF61 Cortex M4

After preparing the ecos.ecc file, just before building the eCos Kernel, the MCC package needs to be added:

ecosconfig add mcc

Also, edit the ecos.ecc file and change the default startup location to DRAM:

...
cdl_option CYG_HAL_STARTUP_PLF {                                                 
    # Flavor: data                                                               
    user_value DRAM
...

Building the eCos® Application

The XY Pen Plotter firmware is available from Github as well. eCos provides two options as startup location (DRAM/OCRAM), both are fine for the XY Pen Plotter firmware. However, the Qt user interface loads the binary by default into the OCRAM (which is also the default location of eCos).

$ git clone https://github.com/antmicro/ecos-colibri-vf61-xypenplotter.git
$ cd ecos-colibri-vf61-xypenplotter/src/

At this point you need to alter the make.sh script and add the cross compiler to the PATH. If one wants to use the self built eCos Kernel, the BTPATH needs to point to the build-tree directory of the pre-built eCos Kernel.

$ ./make.sh

Create the destination folder on the target

$ mkdir /var/cache/xyplotter/

Then, copy the firmware from your development host to the target:

$ scp plotter.bin root@192.168.10.166:/var/cache/xyplotter/plotter.bin

Get SVG images

Plotable images transferred to the firmware are in a binary format, while the image shown on the UI are SVG images. The readme of the Plotter firmware describes how to create the binary format from a SVG file XY Pen Plotter firmware. In the next development phase, one would include this converting process in the user interface. However, due to resource/time limitations, we omitted that step.

The UI expects the SVG files to be in the folder /var/cache/xyplotter and to be named starting from image0.svg to image3.svg. The binary representation of those vector graphics have the same name but with the .bin ending.

Instead of using your own SVG files you can also get a set of SVG files and the converted binaries from our server:

$ wget http://developer.toradex.com/files/toradex-dev/uploads/media/Colibri/Linux/Samples/xypenplotter-images.tar.bz2
$ mkdir /var/cache/xyplotter/
$ tar xvjf xypenplotter-images.tar.bz2 -C /var/cache/xyplotter/

Run the Demo

Even without hardware, it is possible to run the demo. The Qt user interface will be started by the init script provided by meta-xypenplotter. The user interface then loads the firmware and starts to communicate. The user interface also shows the four SVG files placed under /var/cache/xyplotter. When starting to plot an image, the user interface downloads a respective binary representation of that image, starts plotting it (digital IO's on Pin 15 through 20 will be used to instruct the stepper motors) and report back its progress. The progress bar on the user interface will reflect the plotting progress.