Building offline with Qt Creator IDE

This page provides step by step instructions how to create, build and debug MBED applications offline using the QtCreator IDE and the GNU Arm Embedded Toolchain.
/media/uploads/hudakz/qtcreator_demo.png

Main features
  • Mbed CLI is used as the backend engine and QtCreator is the GUI making our life easier.
  • No makefiles shall be edited.
  • Enables to build Mbed 2 (aka Mbed Classic) or Mbed 5 (aka Mbed OS) applications.
  • Works on Linux and MS Windows (hints/instructions how to modify the Linux configuration for Mac are welcome).
  • A common repository is shared rather than having a separate instance of Mbed OS (or Mbed) library for each project .
Usage

Once installed and configured, creating a new MBED project becomes as easy as

  • Launch the QtCreator and then click on the + New Project button. /media/uploads/hudakz/qtcreator_newproject.png
  • Choose the MBED project template.
    /media/uploads/hudakz/qtcreator_projtemplate.png
  • Give it a name (for example Blinky-os ) and select a repository to create in.
    /media/uploads/hudakz/qtcreator_projlocation.png
  • The main.cpp will be opened for editing /media/uploads/hudakz/qtcreator_main01.png
  • In the left-hand toolbar select Projects and for Build & Run you can choose from four available options:
mbed debug > BuildMbed 2 (aka Mbed classic) with debug information included
mbed release > BuildMbed 2 (aka Mbed classic) optimized for size
mbed-os debug > BuildMbed 5 (aka Mbed OS) with debug information included
mbed-os release > BuildMbed 5 (aka Mbed OS) optimized for size

/media/uploads/hudakz/qtcreator_proj_mbed-os_debug.png

  • In Build Steps open Details and type the name of your target board into the Make arguments edit box.

Tip

To list all the supported boards keep the Make arguments edit box empty and start compilation. Open the Compile Output pane (on bottom toolbar). Search for your target board and then copy & paste it to the Make arguments edit box.

  • If you don't want your program to be automatically downloaded to the connected board's flash then deselect the all checkbox.
  • If you want a clean compilation (delete existing object files) then select the clean checkbox.
  • To launch compilation, in the left-hand toolbar select Edit and click on the Build Project button (Hammer) or press Ctrl+B /media/uploads/hudakz/qtcreator_proj_build01.png

Tip

You can follow up a symbol in your code by holding down the Ctrl key and left-cliking on it in the Editor.


Happy coding :)

Download and installation

Download and install the following software to your PC:

On Linux (Ubuntu)
  • In your home directory create a new src/arm/mbed folder and open it in terminal.
  • Issue the following commands:

~/src/arm/mbed >

mbed import mbed-os
cd mbed-os
mbed update master
mbed config -G toochain GCC_ARM
  • Because at the present it's impossible to import the Mbed 2 library using Mbed CLI
    • Download the .gz (.zip is incomplete) repository from mbed-dev to your local drive and unpack it to the ~/src/arm/mbed folder.
    • Rename the unpacked f392fc9709a3 folder to mbed (then you should have two sub-folders in the mbed folder: mbed and mbed-os).
    • Open the ~/src/arm/mbed/mbed/cmsis folder and delete the BUILD subfolder.
    • Copy & paste the tools folder from the mbed-os to the mbed folder.
  • In your home directory create a new src/arm/app folder (optional).
  • In your home directory create a new src/arm/lib folder and copy & paste (collect) the folders with your library sources there (optional).
  • Install the QtCreator IDE.

.

Since MBED pages do not allow to upload files with zip extension, png is used instead. To download the MBED Application Wizard right-click on the link and select Save link as.... Once saved to your local drive, change the extension from png to zip and unzip to the ~/.config/QtProject/qtcreator/templates/wizards folder. Make sure that an mbed folder is then located in that folder.

.

Since MBED pages do not allow to upload files with zip extension, png is used instead. To download MBED build scripts right-click on the link and select Save link as.... Once saved to your local drive, change the extension from png to zip and unzip to the ~/.local/bin folder.

Make sure that new executable batch files mbed_debug, mbed_release, mbed-os_debug and mbed-os_release are then located in that folder. To make them executable open a terminal in that folder and execute:

~/.local/bin >

chmod +x mbed_debug
chmod +x mbed_release
chmod +x mbed-os_debug
chmod +x mbed-os_release
On MS Windows
  • In your user directory create a new src\arm\mbed folder and open a command prompt there.
  • Execute the following commands:

C:\Users\[YourUserName]\src\arm\mbed >

mbed import mbed-os
cd mbed-os
mbed update master
mbed config -G toochain GCC_ARM
  • Because at the present it's impossible to import the Mbed 2 library using Mbed CLI
    • Download the .gz (.zip is incomplete) repository from mbed-dev to your local drive and unpack it to the src\arm\mbed folder.
    • Rename the unpacked f392fc9709a3 folder to mbed (then you should have two sub-folders in the mbed folder: mbed and mbed-os).
    • Open the src\arm\mbed\mbed\cmsis folder and delete the BUILD subfolder.
    • Copy & paste the tools folder from the mbed-os to the mbed folder.
  • In your user directory create a new src\arm\app folder (optional).
  • In your user directory create a new src\arm\lib folder and copy & paste (collect) the folders with your library sources there (optional).
  • Install the Open source Qt cross-platform application framework to the default folder.
    You will need only the QtCreator but you can install more components if you like so.

.

Since MBED pages do not allow to upload files with zip extension, png is used instead. To download the MBED Application Wizard right-click on the link and select Save link as.... Once saved to your local drive, change the extension from png to zip and unzip to the C:\Qt\Tools\QtCreator\share\qtcreator\templates\wizards folder. Make sure that an mbed folder is then located in that folder.

.

Since MBED pages do not allow to upload files with zip extension, png is used instead. To download MBED build scripts right-click on the link and select Save link as.... Once saved to your local drive, change the extension from png to zip and unzip to the C:\Python27\Scripts folder. Then make sure that new mbed_debug.bat, mbed_release.bat, mbed-os_debug.bat and mbed-os_release.bat files are then located in that folder.

Configuration

When the installation is complete launch the Qt Creator and in the Help menu select About Plugins ...
Make sure that the BareMetal (experimental) plugin is checked.
/media/uploads/hudakz/qtcreator_plugins.png


  • Close the dialog box and restart the QtCreator.
  • In Tools menu select Options ...
  • Proceed to Build & Run and add new Custom C++ and Custom C compilers. Provide the actual paths according to your system.
    /media/uploads/hudakz/qtcreator_compilers_mbed-os_debug_cpp_01.png /media/uploads/hudakz/qtcreator_compilers_mbed-os_release_cpp_01.png /media/uploads/hudakz/qtcreator_compilers_mbed_debug_cpp_01.png /media/uploads/hudakz/qtcreator_compilers_mbed_release_cpp_01.png /media/uploads/hudakz/qtcreator_compilers_mbed-os_debug_c_01.png /media/uploads/hudakz/qtcreator_compilers_mbed-os_release_c_01.png /media/uploads/hudakz/qtcreator_compilers_mbed_debug_c_01.png /media/uploads/hudakz/qtcreator_compilers_mbed_release_c_01.png


For each new mbed Custom C++ and Custom C compiler change the Custom Parser Settings ...:

  • Copy & paste the following text into the Error message capture pattern edit box:

\[*Error] (.*)@(\d+),(.*)

/media/uploads/hudakz/qtcreator_compilers_error_parsing.png

  • Copy & paste the following text into the Warning message capture pattern edit box:

\[*Warning] (.*)@(\d+),(.*)

/media/uploads/hudakz/qtcreator_compilers_warning_parsing.png


This will assure capturing error and warning messages during compilation and quick navigation to the related line. /media/uploads/hudakz/qtcreator_compile_issues.png


  • Add a new arm-gdb debugger. Make sure you select the arm-none-eabi-gdb-py (arm-none-eabi-gdb won't work)
    /media/uploads/hudakz/qtcreator_debugger.png


  • Proceed to the Devices and click on the Add ... button.
    /media/uploads/hudakz/qtcreator_devices.png


  • Select the Bare Metal Device and click on the Start Wizard button.
    /media/uploads/hudakz/qtcreator_devices_new_baremetal.png


  • In Devices proceed to the Bare Metal tab. Click on the Add button and select OpenOCD.
    /media/uploads/hudakz/qtcreator_devices_baremetal.png


  • Go back to the Devices tab and select OpenOCD as the GDB server provider.
    /media/uploads/hudakz/qtcreator_devices.png


  • Select Build & Run and proceed to the Kits tab. Click on the Add button and add the following new kits.
    /media/uploads/hudakz/qtcreator_kits_mbed_debug.png /media/uploads/hudakz/qtcreator_kits_mbed_release.png /media/uploads/hudakz/qtcreator_kits_mbed-os_debug.png /media/uploads/hudakz/qtcreator_kits_mbed-os_release.png

NOTE: The CMake Tool is not used. Keep it empty if not installed on your system.

User libraries

One option is to copy & paste a folder containing library files to the project folder using your favorite file manager utility.
Notice that when you then open the project in QtCreator you won't see the library folder yet. /media/uploads/hudakz/qtcreator_lib_copy.png

You have to launch the compilation to get the folder added to the Projects pane.


/media/uploads/hudakz/qtcreator_lib_copy_build.png

Another alternative is to import a library into your local project from its URL repository

  • In the Projects pane right-click on the main.cpp file and select Open terminal here (on Linux) or Open command prompt here (on Windows)
  • Use the mbed add command followed by the library's URL repository to import the library. For example: /media/uploads/hudakz/qtcreator_lib_add.png
  • Close the terminal (command prompt) window and return to the QtCreator.
  • Launch compilation and the new library will appear in the Projects pane.
Creating a new library
  • Launch the Qt Creator and open your project (or create a new one).
  • In the Projects pane right click on your project name and select Add new ....
  • Choose the C++ template and C++ Class then click on the Choose... button.
  • In the Class Name edit box provide a name for your new class (for example MyLcdDriver).
  • Click on the Browse button and create a new folder (e.g. MyLcdDriver) in your Project folder and then click on the Next button. /media/uploads/hudakz/qtcreator_lib_class.png


  • Choose <None> for Add to version control and click on the Finish button. /media/uploads/hudakz/qtcreator_lib_versionctrl.png


  • Edit your library files as needed and then compile the project. /media/uploads/hudakz/qtcreator_lib_edit.png

Importing projects from online repository

One way is to export the program from the online compiler for the QtCreator toolchain
  • Right-click on the project in the online compiler and export for the QtCreator toolchain.
  • Once saved to the local drive, unzip the file and open the project's folder in a file manager.
  • Delete all files and folders (mbed and mbed-os included) except user library folders, the .creator project file, source and header files (like main.cpp) and .json files.
  • Open the .creator project file in QtCreator.
  • Select the target system and board and compile.
Another method is to use Mbed CLI for import
  • Open a terminal (on Linux) or command prompt (on Windows) in your mbed projects repository.
  • Use the mbed import command followed by the programs's URL repository to import the program.
    For example:

mbed import https://github.com/ARMmbed/mbed-os-example-blinky
  • When finished, open the folder and delete all files and folders (mbed and mbed-os included) except user library folders, source and header files (like main.cpp) and .json files.
  • In the project's folder create an empty PROJECT_NAME.creator file (substitute PROJECT_NAME with your project name).
  • Open the .creator project file in QtCreator.
  • Select the target system and board and compile.

Custom targets

We can build projects also for custom targets. To accomplish that we have to add a custom_targets.json file to the project. An example is given below in "Debugging on boards equipped with CMSIS-DAP interface'' where a custom LPC1768A is the target board. Actually, it's an LPC1768 dummy custom board with semihosting disabled:
First, a cutom_targets.json was created in the project's root directory. Then LPC1768's json specification was copy & pasted from the mbed-os/targets/targets.json file to the cutom_targets.json file. Finaly, "SEMIHOST" was deleted from the "device_has" section in the cutom_targets.json file to disable semihosting.

Debugging

Setting up debug tools
  • In the Menu select Tools > Options ... > Debugger and proceed to the GDB tab.
  • Copy & Paste the following text into the Additional Attach Commands edit pane:

monitor reset halt
load
monitor reset halt

/media/uploads/hudakz/qtcreator_debugger_gdb_general.png

  • Click on the OK button to save the changes.

  • In the Tools menu select External > Configure ...
    /media/uploads/hudakz/debug02.png

  • Click on the Add button and select Add Category.
    /media/uploads/hudakz/debug03.png

  • Name it MBED.
  • Select MBED, click on the Add button and select Add Tool.
  • Change its name to pyOCD and provide Description, Executable, Arguments and Working directory according to the path selected when you installed pyOCD to your system.
    /media/uploads/hudakz/debug04.png

  • Start your favorit text editor and in the OpenOCD installation folder (D:\mcu\arm\OpenOCD) create a new .bat file for each group of boards you'd like to debug. For example NUCLEO-F103.bat, NUCLEO-F4XX.bat, NUCLEO-F7XX.bat
  • Type or paste the following text into the NUCLEO-F103.bat file:

cmd /k openocd.exe -s D:\mcu\arm\OpenOCD\scripts -f D:\mcu\arm\OpenOCD\scripts\board\st_nucleo_f103rb.cfg

  • Type or paste the following text into the NUCLEO-F4XX.bat file:

cmd /k openocd.exe -s D:\mcu\arm\OpenOCD\scripts -f D:\mcu\arm\OpenOCD\scripts\board\st_nucleo_f4.cfg

  • Type or paste the following text into the NUCLEO-F7XX.bat file:

cmd /k openocd.exe -s D:\mcu\arm\OpenOCD\scripts -f D:\mcu\arm\OpenOCD\scripts\board\st_nucleo_f7.cfg

  • NOTE: Modify the path to the OpenOCD folder in the scripts above according to the actual path on your system.
  • Finally save and close all .bat files.

  • Return to the Qt Creator and in the Tools menu select External > Configure ...
    /media/uploads/hudakz/debug02.png

  • Select MBED, click on the Add button and select Add Tool.
  • Change its name to OpenOCD NUCLEO-F103 and provide Description, Executable and Arguments as flolows.
    /media/uploads/hudakz/debug11.png
    NOTE: Modify the path to the OpenOCD folder according the actual path on your system.

  • Select MBED, click on the Add button and select Add Tool.
  • Change its name to OpenOCD NUCLEO-F4XX and provide Description, Executable and Arguments as flolows.
    /media/uploads/hudakz/debug12.png
    NOTE: Modify the path to the OpenOCD folder according the actual path on your system.

  • Select MBED, click on the Add button and select Add Tool.
  • Change its name to OpenOCD NUCLEO-F7XX and provide Description, Executable and Arguments as flolows.
    /media/uploads/hudakz/debug13.png
    NOTE: Modify the path to the OpenOCD folder according to the actual path on your system.
  • Click on the OK button to save the changes and close the dialog box.
Debugging on boards equipped with CMSIS-DAP interface

We'll use pyOCD GDB server to debug on boards equqipped with CMSIS-DAP interface (e.g. mbed LPC1768).

  • Launch the Qt Creator.
  • Open for example the Blinky-os project for the LPC1768 target (or create a new one) and open main.cpp for editing. /media/uploads/hudakz/qtcreator_main01.png

  • Connect your mbed LPC1768 board over a USB cable to the PC.
  • In the Tools menu select External > MBED > pyOCD.
    /media/uploads/hudakz/debug06.png

  • That will launch a pyOCD GDB server.
    /media/uploads/hudakz/debug07.png

  • Return to the Qt Creator and in the left-hand toolbar select Projects and for Build & Run select mbed-os debug > Build (Mbed OS 5 with debug information included).

For some unknown reason when semihosting is enabled debugging for LPC1768 boards fails. A workaround is to compile for a custom (dummy) LPC1768 target board with semihosting disabled. We can call it for example LPC1768A:

  • Add a custom_targets.json file to the project as follows:
    • In the Project pane right-click on the project's name and in the local menu select Add New ...
    • Choose the General template and select Empty File.
    • Type custom_targets.json into the Name edit box.
    • Copy & paste the following text to the text editor and save the file:

{
    "LPC1768A": {
        "inherits": ["LPCTarget"],
        "core": "Cortex-M3",
        "extra_labels": ["NXP", "LPC176X", "MBED_LPC1768", "NXP_EMAC"],
        "supported_toolchains": ["ARM", "uARM", "GCC_ARM", "IAR"],
        "detect_code": ["1010"],
        "device_has": [
            "RTC",
            "USTICKER",
            "ANALOGIN",
            "ANALOGOUT",
            "CAN",
            "DEBUG_AWARENESS",
            "EMAC",
            "ETHERNET",
            "I2C",
            "I2CSLAVE",
            "INTERRUPTIN",
            "PORTIN",
            "PORTINOUT",
            "PORTOUT",
            "PWMOUT",
            "SERIAL",
            "SERIAL_FC",
            "SLEEP",
            "SPI",
            "SPISLAVE",
            "STDIO_MESSAGES",
            "FLASH",
            "MPU"
        ],
        "release_versions": ["2", "5"],
        "device_name": "LPC1768",
        "bootloader_supported": true,
        "config": {
            "us-ticker-timer": {
                "help": "Chooses which timer (0-3) to use for us_ticker.c",
                "value": 3
            }
        },
        "overrides": {
            "network-default-interface-type": "ETHERNET"
        }
    }    
}

/media/uploads/hudakz/qtcreator_proj_mbed-os_debug01.png

  • Build the project for the dummy LPC1768A custom target board (don't forget to change the target name in the Make aguments edit box to LPC1768A before clicking on the 'Hammer' button).
  • Setup a break point by clicking in front of a source line.
  • In Menu select Debug > Start Debugging > Attach to Running Debug Server.
  • For Local executable click on the Browse ... button and select the Blinky-os/BUILD/LPC1768/GCC_ARM-DEBUG/Blinky-os.elf file. /media/uploads/hudakz/qtcreator_debugger_startdebugger.png

Debugging on boards equipped with ST-Link or J-Link interface

We'll use OpenOCD GDB server to debug on boards equqipped with ST-Link or J-Link interface (e.g. STM NUCLEO boards).

  • Launch the Qt Creator.
  • Open for example the Blinky-os project for a target board e.g. NUCLEO-F446RE or create a new one and open main.cpp for editing.
  • Connect your MBED board NUCLEO-F446RE over a USB cable to the PC.
  • In the Tools menu select External > MBED > OpenOCD NUCLEO-F4XX.
    /media/uploads/hudakz/debug17.png

  • That will launch an OpenOCD GDB server for the selected group of boards.
    /media/uploads/hudakz/debug18.png

  • Return to the Qt Creator and in the left-hand toolbar select Projects and for Build & Run select mbed-os debug > Build (Mbed OS 5 with debug information included) /media/uploads/hudakz/qtcreator_build_nucleo-f446re.png


  • Build the project.
  • Setup a break point by clicking in front of a source line.
  • In the Menu select Debug > Start Debugging > Attach to Running Debug Server.
  • For Local executable click on the Browse ... button and select the Blinky-os/BUILD/NUCLEO_F446RE/GCC_ARM-DEBUG/Blinky-os.elf file. /media/uploads/hudakz/qtcreator_debugger_nucleo-f446_blinky-os.png


15 comments on Building offline with Qt Creator IDE:

09 May 2018

Very detailed and amazing article! But I have a question. Is there a similar option to make a wizard for qt creator on mac os? Thanks.

09 May 2018

I found a solution. According to the documentation(http://doc.qt.io/qtcreator/creator-project-wizards.html) the paths in mac os are somewhat different (Qt Creator.app/Contents/Resources/templates / wizards). And also it's need to correct all references in all *.qbs files. After editing it all started. Thank you very much for your article!

07 Jun 2018

Innokentiy Zoobarkin wrote:

I found a solution. According to the documentation(http://doc.qt.io/qtcreator/creator-project-wizards.html) the paths in mac os are somewhat different (Qt Creator.app/Contents/Resources/templates / wizards). And also it's need to correct all references in all *.qbs files. After editing it all started. Thank you very much for your article!

Did you use it successfully for mac? Thank you

15 Nov 2018

Yes, it's works!

11 Dec 2018

Great write-up! This helped me a lot after struggling with MCUXpresso for a four days and finally moving over to QtCreator. I wanted to explain a few things that diverged from your walk-thru (I am on CentOS7 with Python3 and a FRDM-K66F board, btw):

1. You're link for the application wizard did not work for me, but I didn't seem to need it anywhere. I started with an export for QtCreator from ide.mbed.com which seems to have everything I need in its "mbed" directory.

2. I added a custom executable after building which is simply "cp" with the arguments including my binary file and the MCU's drive, that way I don't have to manually copy it every time.

With debugging, I ended up with a completely different solution (I'm not sure how pushing the green debug arrow works for you without specifying an executable):

3. I required root privileges for pyOCD to find my board, so I had to change my default terminal to "/usr/bin/gnome-terminal -x sudo" and then I added it as my run executable (pyocd-gdbserver) to make it easier to start.

4. Then to connect to the server, I clicked debug -> attach to running debug server. With the kit setup as you described, the executable is set to my .elf file, and "override server channel" is set to localhost:3333.

5. The last thing is that the makefile that is exported by ide.mbed.com is not made correctly to include debug info. I changed C_FLAGS += -g3 and CXX_FLAGS += -g3, both from -g1, in order to analyse local variables & expressions.

15 Dec 2018

Hello Zoltan,

thank you for this great job.

I hang on tuto at "qbs_mbed_5.10.4.zip" the link doesn't works : https://os.mbed.com/media/uploads/hudakz/qbs_mbed_5.10.4.png

Installing the MBED Application wizard Download the qbs_mbed_5.10.4.zip file into the C:\Qt\Qt5.10.0\Tools\QtCreator\share\qtcreator\templates\wizards folder and unzip.

Kind regards

23 Dec 2018

Thanks for reporting the broken link. I use Internet Explorer and it seems to work fine. When using Chrome:

  • Right click on the link and select Save link as...
  • Save the file to your local hard drive (since MBED pages did not allow me to upload files with zip extension I decided to use png).
  • Change the extension from png to zip and then unzip the file.
29 Jan 2019

Hello,

I have installed Qt 5.12 with the online installer.

In "Installing the MBED Application wizard" step there is a missing step.

You need to change the "C:/Qt/Qt5.10.0/Tools/QtCreator/share/qtcreator/templates/wizards/qbs_mbed" paths in the MbedApplication.qbs and Project.qbs to the correct path where you have copied qbs_mbed

If you install Qt using the online installer, QtCreator usually gets installed to C:\Qt\Tools\QtCreator so the correct path would be "C:\Qt\Tools\QtCreator\share\qtcreator\templates\wizards\qbs_mbed"

29 Jan 2019

GCC compiler version needs to be >= 6.0.0 and < 7.0.0

As explained in https://os.mbed.com/questions/84008/Errors-barm-none-eabi-objcopy-applicatio/ , officially Mbed supports gcc v6.

The v6 2017 Q2 update of GNU Arm Embedded Toolchain compiles fine the example of "Creating a new MBED project offline" section of the tutorial, but newer versions produce the following error:

"... 64-bit address 0x.... out of range for Intel Hex File"

It seems that mBed requires the compiler version to be >= 6.0.0 and < 7.0.0

29 Jan 2019

Thanks for all comments and suggestions. I'll try to update the tutorial accordingly.

11 Apr 2019

Is this works for free version of QT? Since i cant see the mbed project in project creation step ?

11 Apr 2019

Ok..Compilers were moved to kits tab in Tools->options

06 Jun 2019

Hi, thanks for the great tutorial.

19 Sep 2019

I'm having the same problem as Kamil M. there is no MBED project template after selecting New Project in qtcreator. mbed-cli is installed.

20 Sep 2019

Make sure the QtCreator MBED Application Wizard is installed as described in Download and installation:

On MS Windows

Since MBED pages do not allow to upload files with zip extension, png is used instead. To download the MBED Application Wizard right-click on the link and select Save link as.... Once saved to your local drive, change the extension from png to zip and unzip to the C:\Qt\Tools\QtCreator\share\qtcreator\templates\wizards folder. Make sure that an mbed folder is then located in that folder.

On Linux (Ubuntu)

Since MBED pages do not allow to upload files with zip extension, png is used instead. To download the MBED Application Wizard right-click on the link and select Save link as.... Once saved to your local drive, change the extension from png to zip and unzip to the ~/.config/QtProject/qtcreator/templates/wizards folder. Make sure that an mbed folder is then located in that folder.

Please log in to post comments.