More and more functionality is expected from embedded systems for smart products. This can be easily achieved with Linux, which offers software for every case you wish. But the Linux requires rather large hardware resources, most notably memory, so the target platform will typically be rather expensive and have high power consumption. On the other hand, modern microcontrollers (MCUs) have a lot of resources that are enough for many smart tasks. Using a real-time operating system (RTOS) such as Embox RTOS, which allows use of Linux software everywhere including MCUs, developers can more easily develop smart devices that are less expensive and consume less power.
In this article, we discuss launching a basic Qt application on an embedded MCU running the Embox RTOS. We use two single-core Cortex-M7 based boards (216MHz): STM32F746g-Discovery and STM32F769i-Discovery, which have touchscreens with 480×272 and 800×480 screen resolution, respectively.
Some time ago we managed to launch a standard Qt example ‘moveblocks’ on STM32F746-Discovery [Note 1]. However we wanted to go further and launch an example with a touchscreen.We choose another standard example, ‘animatedtiles’. It is a rather nice example which looks cool even on desktops. It is interactive therefore we can use a touchscreen and also it looks like 3D animation.
We wanted to learn whether the STM32 MCU can provide enough performance. We were not sure if the CPU’s speed would be enough for that rendering scene to be smooth, since as we found out, even screen refreshing for an 800×480 display is an expensive operation [Note 2].
First of all, let’s build our application as a part of Embox. The simplest way to do this is to build the application for QEMU, which is an open source emulator. Using QEMU means that we do not need to take care of memory consumption in this case. This will help us to make sure that all the necessary components are available. When ‘animatedtiles’ had started on QEMU, we easily added necessary components to config files for the STM32.
First launch on the target board
We successfully started ‘animatedtiles‘ on our target board STM32F746G-Discovery, but we noticed that only the top half of the screen was drawn. Of course, we could try to solve the trouble through debugging immediately on the board but there is an easier way: We can start and debug the example in the Linux environment first.
Debugging on host
To run this example and debug your application, you need the Qt library itself as well as QVFB, which is a Qt application providing a virtual screen. You can build QVFB as described in the official documentation.
Then you can launch QVFB with required screen resolutions (480×272 for STM32F746G-Discovery):
./qvfb -width 480 -height 272 -nocursor
You also should build Qt library with an embedded profile, namely with ‘-embedded’ option. This option is designed to run Qt without X11 or existing graphical environments, QWS (Qt Windowing System) will be used instead. Also we disabled some other unnecessary options and modules. The resulting configuration line was the following:
We got the same picture in the top half of the screen. We found in the source code (examples/animation/animatedtiles/main.cpp) that the application starts with “view->show()”, that means not in the full-screen mode. After that, we were entirely convinced that the only top half of the screen was used to display the application. We modified the code of ‘animatedtiles’ a little, adding the ‘-fullscreen’ option.
Launching on STM32F746-discovery
We built our modified application in Embox and checked that it successfully ran on QEMU. But when we were launching the application on the target board we received the “Out Of Memory” error. It means that the size of the heap in our config is not enough for the application. We decided to use rich development tools in Linux to solve the trouble i.e. estimate required heap size.
We had started our application with valgrind. Valgrind is a tool for memory debugging and profiling, Massif is a heap profiler (it’s a part of Valgrind).
And found out that the application needed a heap size of about 2.7 MB heap size.
We set up the heap size to 3 MB in Embox config and started our demo again. It was successfully running in the fullscreen mode.
Launching on STM32F769I-Discovery.
We also wanted to try the example on a similar board but with a bigger display. This example used the STM32F769I-Discovery with 800×480 display resolutions. In this case, it requires almost 1MB only for the framebuffer in 16bits colour mode (800x480x2=768000), but there is enough (16MB) external SDRAM on this board. So we only have to estimate the size of the heap.
We started QVFb with the new resolutions (800×480):
Anton Bondarev is the founder of Embox RTOS. Anton graduated from Saint Petersburg Electrotechnical University (LETI) in 2003 with a master degree in electrical engineering and attended postgraduate courses in Saint-Petersburg State University specializing in software engineering. He has over 20 years in embedded and system programming.
Alexander Kalmuk is the cofounder of Embox RTOS. Alexander graduated from Saint-Petersburg State University in 2014 with a master degree in mathematics and software engineering and attended postgraduate courses in Saint-Petersburg State University specializing in control theory. He has over 10 years in embedded systems programming.