People often ask us about if it's possible to use Qt for software development on microcontrollers (MCU), and if Qt can run without an operating system ("bare metal"). Today we will answer these questions and show you some concrete examples and demonstrations.
MCUs are small computers on a single integrated circuit. They're similar to systems on a chip (SoC), albeit less sophisticated. Microcontrollers are used in automatically controlled products and devices, such as car engine control systems, implantable medical devices, wearables, remote controls, office machines, appliances, power tools, toys, and other embedded systems. The main advantage of using MCUs is their small size and comparatively very low cost – especially for large volumes of production.
So, we can already see the main features of MCUs from the definition: small size, low power consumption and, naturally, low price per unit. Thus, we can say that the main point of using MCU is a natural desire to save cost.
Low computing power applies certain restrictions to the choice of software development tools, especially if we talk about the GUI, e.g. in regards to firmware size, runtime memory usage and how "fancy" the GUI can be.
Today we do not have a universal GUI library for MCUs. Sure, there are some that could solve some part of the task for this or that particular MCU model, but that is not enough. And quite rarely (or actually never) those libraries are created with "cross-platform-ability" in mind.
Although some commercial toolkits are actually pretty good, in most cases they have a closed source code. So you're buying a "black box" and risk to find yourself vendor-locked.
Now imagine how great it would be if we could use the Qt framework: cross-platform and comprehensive library of classes (including GUI), with excellent documentation and lots of examples, and with a fantastic Open Source community.
Unfortunately, up to this moment, due to the mentioned hardware restrictions, embedded development with Qt (Qt for Device Creation) was officially supported only on devices of Cortex-A level, mostly under Linux and some commercial RTOSes (INTEGRITY, QNX, and VxWorks).
But today, this situation has changed.
So, we got ourselves a research: investigate the possibilities of running Qt on MCU hardware.
Let's be clear from the beginning on what microcontrollers we're talking about exactly because some might start to dream about MCUs with a 12 Mhz CPU and 128 bytes of RAM. That would be quite a gap because Qt's current hardware requirements are:
Definitely not the microcontroller level, because those have a far smaller footprint.
And the boards we selected for the research are:
STM32F469 - ARM Cortex-M4, FPU unit single precision
STM32F746 - ARM Cortex-M7, FPU unit single precision, L1 Cache (Data/Instruction)
STM32F769 - ARM Cortex-M7, FPU unit double precision, L1 Cache (Data/Instruction)
As you can see from specifications, their hardware resources are way lower than what Qt "officially" requires.
Regarding OpenGL support, thanks to Qt Quick 2D Renderer it is not a strict requirement, because we can render our graphics using raster paint engine.
We started with porting the following Qt modules:
How do you port Qt to different target platforms? Well, first we need to understand what exactly is required for Qt to function. And in general, there are two main requirements you need to meet:
Let's start with C++11 requirement. With version 5.7, Qt started to require platforms to support C++11 because we aim to provide a powerful and modern C++ framework. However, if your platform can only support C++98 at best, then you can of course try to do it with Qt 5.6 (or older), but then considering the fact that new configuration system (so-called Qt Lite) was introduced only with Qt 5.8, it will be a tough task for you to "squeeze" Qt into an MCU environment.
Now regarding POSIX - Portable Operating System Interface. That actually answers the question why Qt does not work on "bare metal" out of the box. Inside Qt we are using a lot of POSIX functions (pthreads, mmap,
open and others), so if we want to run Qt on bare metal, we need to create your own implementation of POSIX – basically implement your own operating system. Fortunately, that isn't the case in our research.
We decided to use an Open Source RTOS and we chose RTEMS for its most notable features:
The process of porting Qt to RTEMS consists of the following steps:
Porting Qt itself can be presented in the following illustration:
We won't describe the whole process in detail (from configuring the board till the creation of a new QPA) just yet, even though that's probably the most interesting part of the research. But this article was aiming only to tell you about the research and not to provide a step-by-step manual. If you are interested in conduction a pilot project, please contact us and submit your request.
To demonstrate the results, we created three firmwares for each board with different demo applications.
Firmware size: 6.6 MB.
RAM required: 3.4 MB.
As we can see, Qt Widgets runs just fine.
Firmware size: 9 MB.
RAM required: 5 MB.
It's easy to see that Qt QML's dragging animation is somewhat slow on STM32F4/F746, but the clocks work rather well. Such behavior is an excellent example of lacking JIT compilation because those MCUs don't support double-precision floating-point. However, STM32F769 does support it, thus the dragging animation looks much nicer on this board.
We decided not to stop on simple demos and for the third firmware, we tried to run something more interesting. For instance - our recent e-bike demo.
Firmware size: 13 MB.
RAM required: 10 MB.
And even this demo works fine too. By the way, thanks to the cross-platform nature of Qt, we didn't have to change a single line of code to compile it for RTEMS (the original target was running on Linux).
We can conclude that our research was successful. Sure, it is not a ready out-of-the-box solution right now, but we will continue to work on it.
Current tasks include the following:
So, what does this research mean for you and your projects? The source code of the new QPA and other modifications to the Qt code base should be available in Open Source (most probably under GPLv3), and of course in commercial license too, so you'll be able to try it out yourself.
And we plan to provide consultancy services for preparing a system image and porting Qt to your MCU-based platform. We'll have more information about that very soon, so stay tuned!
In the meantime, make sure to sign up for the Qt on MCUs webinar where we tell you more about the topic, show you some demos and answer your questions!
Stay up to date with the latest marketing, sales and service tips and news.
Download the latest release here: www.qt.io/download.
Qt 5.12 was developed with a strong focus on quality and is a long-term-supported (LTS) release that will be supported for 3 years.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu