Graphical Modeling and Automatic Code Generation

Large parts of the QP example qp_dpp have been automatically generated by the QM (QP Modeler) tool, which is a free, cross-platform, graphical UML modeling tool for designing and implementing real-time embedded applications based on the QP frameworks. QM provides best-in-class, intuitive state machine diagramming and generates very compact C or C++ code that is 100% traceable from your design. QM is available for Windows, Linux, and Mac OS X. The steps of obtaining the free QM tool and generating the code are described in the QL Notebook page "Graphical Modeling and Automatic Code Generation ".

The UML state machine diagrams below correspond to the Table state machine and Philosopher state machine in the Dining Philosopher Problem (DPP) model.

/media/uploads/QL/dpp_hsm.png

Downloading and Installing QM

The QM tool is available for a free download, without the need for registration or relinquishing any personal information from state-machine.com/downloads. Please select the download for your platform (Windows, Linux, and Mac OS X are supported). The installation on any platform is trivial and does not require any third party software (no Java, Eclipse, etc.). The provided setup installs the QM application, creates a desktop icon, and associates the QM model files (*.qm) with the QM application. QM is very easy to uninstall with the provided uninstaller.

Downloading the DPP Model

Unfortunately, the DPP model could not be included in the qp_dpp example program, where it belongs, because the mbed archive accepts only .h and .cpp source files. Therefore, you need to download the DPP model file separately, as described in the box below.

Downloading the QM model

Please right-click on the link below and and select "Save link as..." option to save the dpp.qm model file to your computer.

/media/uploads/QL/dpp.qm

To view the model, assuming that you have installed the QM tool, you can just double-click on the dpp.qm model file, or you can launch the QM tool first and then open the model from the File|Open menu command. Please note that the QM user interface is highly customizable, so your screen might look a little differently than the screen shot below. But you can always re-arrange the docking windows to suit best your particular taste and the tool will remember your layout for the future.

DPP model in QM (click to enlarge)

Generating the Code

Code generation is literally accomplished by pressing a single toolbar button or the F7 keyboard shortcut (the "Code Generation" button in the Tools toolbar). The steps of code generation are show in the Log window. This particular model is setup to generate the code in the same directory as the dpp.qm model file.

Executing the Code

Once the code is generated, you simply import the code as a program to the mbed compiler. The code should compile cleanly. You execute the synthesized program just as any hand-crafted mbed program.

More Information

Please visit state-machine.com/qm for more information.


8 comments on Graphical Modeling and Automatic Code Generation:

31 May 2011

mbed compiler produces error

"Cannot open source input file "qp_port.h": No such file or directory

In every qp, related project I imported.

The same with code (7 files but missing qp_port.h) for Pelican project I created form QM as described above

Please advise.

SOLVED, Have to import qm library to all qm projects. It is not mentioned above..

Nikos Chalikias

25 Sep 2011

The pelican.qm model file has been updated for the latest QM version 2.0.00.

QL

30 Oct 2011

HELP!

I have a QM program that uses multiple files. If I want to import the files into the online mbed compiler I have to manually click and select each file after manually deleting the individual old files that are in the mbed directory first. This is REALLY cumbersome, each QM compile-MBED compile-upload-run iteration costs me like 10 minutes. For me programming means a lot of iterations, so I can't work like this....

Does anyone know a solution? Otherwise I'm forced to ditch the mbed platform and pick something else...

31 Oct 2011

I really don't see an easy way of integrating QM with the online mbed compiler. The whole idea of the online compiler is that everything stays "in the cloud". This philosophy works fine for traditional coding, but does not take into account automatic generation of the source code. As soon as the source needs to be created outside "the cloud", you lose the whole advantage and, in fact, your life gets quite miserable.

The only solution I could see is if there were a method to *automatically* upload the source code to the mbed "cloud" and to obtain the executable image back.

31 Oct 2011

Otherwise I'm forced to ditch the mbed platform

using an off-line compiler comes to mind.

31 Oct 2011

maybe you can export the whole mbed project to your pc where it is stored as a zip file, unzip on the pc, overwrite the generated QM files (assuming they have the same names), zip the project again, rename the new zip file (eg by adding a number) and import that file as a new project in mbed.

BTW You can probably just drag the new QM files to the zip file in your windows explorer. No need to explicitly unzip/zip.

02 Jan 2012

Hi, is it possible to have a blinky example for mbed. been trying to test out the state machine with the blinky example, but there were many error. Thank you

19 Dec 2014

hi i am trying blinky project using msp430g2553 . i have seen the example video of aurdino for blinky . please provide the video for using msp430 . Thanks .

Please log in to post comments.