Mbed support for QtCreator IDE. Visit https://os.mbed.com/users/hudakz/notebook/building-offline-with-qt-creator/ for more info.

Building and debugging offline on Linux with QtCreator IDE

This page provides step by step instructions how to create, build and debug MBED applications offline using

Main features

  • Mbed CLI is used as the backend engine and QtCreator IDE is the GUI making life easier.
  • No makefiles shall be edited.
  • Enables to build Mbed OS 2 (aka Mbed Classic) or Mbed OS 6 (aka Mbed OS) applications.
  • Supports custom targets.
  • Works on Linux. (MS Windows is not supported anymore.)
  • A common repository is shared rather than having a separate instance of Mbed OS and user libraries for each project.

How does it work

A bash script is run to parse and execute commands typed into the QtCreator's Make arguments edit box (located in the Build Steps Details). The commands are stored along with the project file. The bash script is stored in the ~/.local/bin/mbed.bat file of your linux machine and you are free to adapt it to your needs.
In comparison to mbed-cli compile it accepts a few additional options :

  • The -os option can be used to build for Mbed OS 2. For example:

-m LPC1768 -os 2
  • Libraries can be added with the -l option. For example:

-m LPC1768 -l TextLCD -l DS1820

See below the User libraries section for more details.

  • The -r or --release option can be used to build with release profile.

-m NUCLEO_F446RE -r
  • The -D or --macro option can be used to define macros. For example:

-m NUCLEO_F103RB -macro MY_MACRO -l DS1820

Once the compilation is complete it can also flash the selected target MCU/board. At the present it is using pyOCD, OpenOCD and lpc21isp for flashing. You can use any programmer supported by these tools (e.g. a serial port, DAP link or ST-link programmer/debugger).

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
  • Select the mbed kit https://os.mbed.com/media/uploads/hudakz/qtcreator_select_kit.png
  • Finish the new project
  • The main.cpp will be opened for editing /media/uploads/hudakz/qtcreator_main02.png
  • In the left-hand toolbar select Projects and for Build & Run select mbed
  • In Build Steps open Details and type -m followed by a space and the name of your target board into the Make arguments edit box. For example:

-m LPC1768

https://os.mbed.com/media/uploads/hudakz/qtcreator_proj_build.png

  • 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_compile.png
    Happy coding :)

Installation

Install the following software to your PC

GNU Arm Embedded Toolchain

  • Version 9-2019-q4-major for Mbed OS 6
  • If you'd like to build Mbed OS 2 programs install also version 6-2017-q2-update (see below Juan Pedro's comments for more details).

Mbed CLI

pyOCD

OpenOCD

QtCreator IDE (usually part of a Linux distribution)

Mbed OS

  • In your home directory, create a new src/arm/sys folder and open it in terminal
  • Issue the following commands

~/src/arm/sys >

mbed import mbed-os
cd mbed-os
mbed update master
mbed config -G toochain GCC_ARM

Mbed support for QtCreator

  • Import the Mbed support for QtCreator project into the online compiler. Type QtCreator_Support into the Import Name edit box and save the project.
  • Right-click on the mbed.bat file and select Export File ...
  • Save the file to the ~/.local/bin folder. (NOTE: In Linux ~ is a shortcut (alias name) for your home directory.)

~/.local/bin/mbed.bat
  • To make the script (text file) executable open a terminal in the ~/.local/bin directory and execute:chmod +x mbed.bat

ubuntu:~/.local/bin$  chmod +x mbed.bat
  • Click on the mbed_wizard_linux_zip folder
  • Right-click on the mbed_wizard_linux.zip file and select Export File...
  • Save the file to the ~/.config/QtProject/qtcreator/templates/wizards folder and unzip. The result should be as below:

~/.config/QtProject
          └── qtcreator
		      └── templates
		          └── wizards
		              └── mbed
		                  ├── ARMmbedLogo.png
		                  ├── main.cpp
		                  ├── mbed_app.json
		                  ├── project.config
		                  ├── project.creator
		                  ├── project.files
		                  ├── project.includes
		                  └── wizard.json
  • Right-click on the custom_targets folder and select Export Folder ...
  • Save the file to the ~/src/arm/sys folder and unzip:

~/src/arm/sys
          ├── custom_targets
          └── mbed-os
  • In your home directory create a new ~/src/arm/app folder:

~/src/arm
      ├── app
      └── sys
  • In your home directory create a new ~/src/arm/lib folder and copy & paste (collect) the folders with your library sources there:

~/src/arm
      ├── app
      ├── lib
      └── sys

Optional: For building Mbed OS 2 programs

~/src/arm/sys
          ├── custom_targets
          ├── mbed
          └── mbed-os
  • Copy & paste the tools folder from the mbed-os to the mbed 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 mbedCustom C and mbed Custom C++ compilers. Provide the actual paths according to your system.
    https://os.mbed.com/media/uploads/hudakz/qtcreator_compiler_c.png https://os.mbed.com/media/uploads/hudakz/qtcreator_compiler_cpp.png


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

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

^.*[Ee][Rr][Rr][Oo][Rr][^.c][ \]]*([^@:,]*)[@:,]([0-9]*)(.*)

/media/uploads/hudakz/qtcreator_compilers_error_parsing.png

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

^.*[Ww][Aa][Rr][Nn][Ii][Nn][Gg][ \]]*([^@:,]*)[@:,]([0-9]*)(.*)

/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 kit.
    https://os.mbed.com/media/uploads/hudakz/qtcreator_mbed_kit.png


User libraries

User libraries can be shared among all the projects. Such approach requres less disk space and makes sure all programs use the same version of a library. If you keep your libraries in the recommended repository ( ~/src/arm/lib) then just add the directory name of your library (the relative path inside the library repository) into the Make arguments edit box prepended with -l . For example if you have a TextLCD and DS1820 library stored in the ~/src/arm/lib repository as below:

~/src/arm/lib
          └── Display
		      └── TextLCD
          └── TempSensor
		      └── DS1820

Then you can add them to your project as:

-m LPC1768 -l Display/TextLCD -l TempSensor/DS1820  

Another option is to copy & paste a folder containing library files to the project folder using your favorite file manager utility. However, in this case the library is not shared with other projects. Any modification to the library will affect only the given project.
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

As an alternative you can 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
  • Once you are happy with it move the library folder to your library repository so you can easily share it with other projects.

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

It is possible to build projects also for custom targets. Read Adding and configuring targets and have a look at the provided custom targets. I'm sure you'll be able to extend them by your favorite ones.

Once a custom target is added you compile for it by simply using its name. For example, to build for the BLUEPILL target type

-m BLUEPILL

into the Make arguments edit box in the Build Steps Details.

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

  • In ~/.local/bin create a new text file for each group of boards you'd like to debug. For example PyOCD, NUCLEO-F103, NUCLEO-F4XX, NUCLEO-F7XX
  • Type or paste the following text into the PyOCD file:

#!/bin/bash
~/.local/bin/pyocd-gdbserver
  • Type or paste the following text into the NUCLEO-F103 file:

!/bin/bash
openocd -s /usr/local/share/openocd/scripts -f /usr/local/share/openocd/scripts/board/st_nucleo_f103rb.cfg
  • Type or paste the following text into the NUCLEO-F4XX.bat file:

#/bin/bash
openocd -s /usr/local/share/openocd/scripts -f /usr/local/share/openocd/scripts/board/st_nucleo_f4.cfg
  • Type or paste the following text into the NUCLEO-F7XX.bat file:

#!/bin/bash
openocd -s /usr/local/share/openocd/scripts -f /usr/local/share/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 files and make them executable with the following commnad:

chmod +x file_name


Enter gnome-terminal as Executable and the path to the associated batch file prepended with -- as Arguments.
For example:

-- ~/.local/bin/OpenOCD_F103
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.
  • 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 > Build.

For some unknown reason when local file system and semihosting is enabled debugging for LPC1768 boards fails. A workaround is to compile for a custom (dummy) LPC1768 target board with local file system and semihosting disabled. That's why a custom target LPC1768DBG is provided. Have a look at the ~/src/arm/sys/custom_targets/mbed-os/custom_targets.json configuration file.

  • Build the project for the dummy LPC1768DBG custom target board:
    • Type -m LPC1768DBG to the Make aguments edit box and click 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/LPC1768DBG/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 and build the project
  • 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 > Build
  • Build the project for the NUCLEO-F446RE target:
    • Type -m NUCLEO_FF446RE to the Make aguments edit box and click on the 'Hammer' button.
  • 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

Committer:
hudakz
Date:
Sun Sep 27 13:57:00 2020 +0000
Revision:
7:b567983e76f4
Parent:
6:f3529afba368
Child:
8:66aa32957926
Mbed tool for the QtCreator IDE.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 5:ace99c9d0e4e 1 #!/bin/bash
hudakz 5:ace99c9d0e4e 2
hudakz 7:b567983e76f4 3 # Mbed tool for the QtCreator IDE.
hudakz 5:ace99c9d0e4e 4
hudakz 7:b567983e76f4 5 # default settings
hudakz 5:ace99c9d0e4e 6 MBED_SYS_PATH=~/src/arm/sys
hudakz 5:ace99c9d0e4e 7 LIB_PATH=~/src/arm/lib
hudakz 5:ace99c9d0e4e 8 OS=6
hudakz 7:b567983e76f4 9 PROFILE=DEBUG
hudakz 5:ace99c9d0e4e 10 PROJ_NAME=${PWD##*/}
hudakz 5:ace99c9d0e4e 11 PORT=/dev/ttyACM0
hudakz 5:ace99c9d0e4e 12
hudakz 7:b567983e76f4 13 # Mbed command parser. Sets bash variables based on the selected Mbed CLI options.
hudakz 7:b567983e76f4 14 # Ones parsing is complete the options and arguments can be passed to Mbec CLI.
hudakz 5:ace99c9d0e4e 15 MACROS=()
hudakz 5:ace99c9d0e4e 16 SRC_LIB_PATH=()
hudakz 5:ace99c9d0e4e 17 while [[ $# -gt 0 ]]
hudakz 5:ace99c9d0e4e 18 do
hudakz 7:b567983e76f4 19 # Get first token
hudakz 7:b567983e76f4 20 key="$1"
hudakz 7:b567983e76f4 21
hudakz 7:b567983e76f4 22 case $key in
hudakz 7:b567983e76f4 23 # Flashes target with binary.
hudakz 7:b567983e76f4 24 all|-f)
hudakz 7:b567983e76f4 25 FLASH='-f'
hudakz 7:b567983e76f4 26 shift # past argument
hudakz 7:b567983e76f4 27 ;;
hudakz 7:b567983e76f4 28
hudakz 7:b567983e76f4 29 # Cleans files before building.
hudakz 7:b567983e76f4 30 -c|clean)
hudakz 7:b567983e76f4 31 CLEAN='-c'
hudakz 7:b567983e76f4 32 shift # past argument
hudakz 7:b567983e76f4 33 ;;
hudakz 7:b567983e76f4 34
hudakz 7:b567983e76f4 35 # Adds macro.
hudakz 7:b567983e76f4 36 -D|--macro)
hudakz 7:b567983e76f4 37 MACROS+=('-D '$2)
hudakz 7:b567983e76f4 38 shift # past argument
hudakz 7:b567983e76f4 39 shift # past value
hudakz 7:b567983e76f4 40 ;;
hudakz 7:b567983e76f4 41
hudakz 7:b567983e76f4 42 # Adds library with relative path.
hudakz 7:b567983e76f4 43 -l)
hudakz 7:b567983e76f4 44 SRC_LIB_PATH+=' --source '${LIB_PATH}/$2
hudakz 7:b567983e76f4 45 shift # past argument
hudakz 7:b567983e76f4 46 shift # past value
hudakz 7:b567983e76f4 47 ;;
hudakz 5:ace99c9d0e4e 48
hudakz 7:b567983e76f4 49 # Defines target Micro-Controller Unit (MCU).
hudakz 7:b567983e76f4 50 -m)
hudakz 7:b567983e76f4 51 MCU="$2"
hudakz 7:b567983e76f4 52 shift # past argument
hudakz 7:b567983e76f4 53 shift # past value
hudakz 7:b567983e76f4 54 ;;
hudakz 7:b567983e76f4 55
hudakz 7:b567983e76f4 56 # Selects Mbed Operating System (2 or other).
hudakz 7:b567983e76f4 57 -os)
hudakz 7:b567983e76f4 58 OS="$2"
hudakz 7:b567983e76f4 59 shift # past argument
hudakz 7:b567983e76f4 60 shift # past value
hudakz 7:b567983e76f4 61 ;;
hudakz 7:b567983e76f4 62
hudakz 7:b567983e76f4 63 # Selects serial port.
hudakz 7:b567983e76f4 64 -p|--port)
hudakz 7:b567983e76f4 65 PORT="$2"
hudakz 7:b567983e76f4 66 shift # past argument
hudakz 7:b567983e76f4 67 shift # past value
hudakz 7:b567983e76f4 68 ;;
hudakz 7:b567983e76f4 69
hudakz 7:b567983e76f4 70 # Sets build profile (debug or release)
hudakz 7:b567983e76f4 71 -r|--release)
hudakz 7:b567983e76f4 72 PROFILE=RELEASE
hudakz 7:b567983e76f4 73 shift # past argument
hudakz 7:b567983e76f4 74 ;;
hudakz 7:b567983e76f4 75
hudakz 7:b567983e76f4 76 # Takes additional options and passes them to Mbed CLI.
hudakz 7:b567983e76f4 77 *) # additional make and Mbed CLI args
hudakz 7:b567983e76f4 78 ARGS+=("$key ")
hudakz 7:b567983e76f4 79 shift # past argument
hudakz 7:b567983e76f4 80 ;;
hudakz 7:b567983e76f4 81 esac
hudakz 5:ace99c9d0e4e 82 done
hudakz 0:e5c84595673c 83
hudakz 7:b567983e76f4 84 # Sets path to the selected Mbed OS tools and profile.
hudakz 5:ace99c9d0e4e 85 if [ ${OS} == 2 ]
hudakz 5:ace99c9d0e4e 86 then
hudakz 5:ace99c9d0e4e 87 GCC_ARM_PATH=/opt/gcc-arm-none-eabi-6-2017-q2-update
hudakz 5:ace99c9d0e4e 88 MBED_OS_PATH=${MBED_SYS_PATH}/mbed
hudakz 5:ace99c9d0e4e 89 CUSTOM_TARGETS_PATH=${MBED_SYS_PATH}/custom_targets/mbed
hudakz 7:b567983e76f4 90 PROF=debug
hudakz 7:b567983e76f4 91 if [ ${PROFILE} == RELEASE ]
hudakz 5:ace99c9d0e4e 92 then
hudakz 7:b567983e76f4 93 PROF=release
hudakz 5:ace99c9d0e4e 94 fi
hudakz 5:ace99c9d0e4e 95 else
hudakz 5:ace99c9d0e4e 96 GCC_ARM_PATH=/opt/gcc-arm-none-eabi-9-2019-q4-major
hudakz 5:ace99c9d0e4e 97 MBED_OS_PATH=${MBED_SYS_PATH}/mbed-os
hudakz 5:ace99c9d0e4e 98 CUSTOM_TARGETS_PATH=${MBED_SYS_PATH}/custom_targets/mbed-os
hudakz 7:b567983e76f4 99 PROF=${MBED_SYS_PATH}/mbed-os/tools/profiles/debug.json
hudakz 7:b567983e76f4 100 if [ ${PROFILE} == RELEASE ]
hudakz 5:ace99c9d0e4e 101 then
hudakz 7:b567983e76f4 102 PROF=${MBED_SYS_PATH}/mbed-os/tools/profiles/release.json
hudakz 5:ace99c9d0e4e 103 fi
hudakz 5:ace99c9d0e4e 104 fi
hudakz 5:ace99c9d0e4e 105
hudakz 7:b567983e76f4 106 # Calls Mbed CLI "config" command to set path to the toolchain (GCC ARM) and Mbed OS (2 or other)
hudakz 5:ace99c9d0e4e 107 mbed config -G GCC_ARM_PATH ${GCC_ARM_PATH}/bin
hudakz 5:ace99c9d0e4e 108 mbed config -G MBED_OS_DIR ${MBED_OS_PATH}
hudakz 7:b567983e76f4 109
hudakz 7:b567983e76f4 110 # Creates a new project if no such exists yet.
hudakz 5:ace99c9d0e4e 111 if ! [ -f ./.mbed ]
hudakz 5:ace99c9d0e4e 112 then
hudakz 5:ace99c9d0e4e 113 mbed new .
hudakz 5:ace99c9d0e4e 114 fi
hudakz 7:b567983e76f4 115
hudakz 7:b567983e76f4 116 # Executes Mbed CLI "export" command using the selected options.
hudakz 5:ace99c9d0e4e 117 mbed export -i qtcreator -m ${MCU} --source . --source ${CUSTOM_TARGETS_PATH} --source ${MBED_OS_PATH} --source ${GCC_ARM_PATH}/arm-none-eabi/include ${SRC_LIB_PATH}
hudakz 7:b567983e76f4 118
hudakz 7:b567983e76f4 119 # Adds files to the project to be available in the QtCreator IDE for editing.
hudakz 7:b567983e76f4 120 find ~/.local/bin -name "mbed.bat" >> ${PROJ_NAME}.files
hudakz 7:b567983e76f4 121 find . -name "*.json" >> ${PROJ_NAME}.files
hudakz 7:b567983e76f4 122 find . -name "*.mbedignore" >> ${PROJ_NAME}.files
hudakz 5:ace99c9d0e4e 123
hudakz 7:b567983e76f4 124 # Executes Mbed CLI "compile" command using the selected options.
hudakz 7:b567983e76f4 125 mbed compile -t GCC_ARM -m ${MCU} -j2 ${ARGS} --source . --source ${CUSTOM_TARGETS_PATH} --source ${MBED_OS_PATH} ${SRC_LIB_PATH} $CLEAN --profile ${PROF} |tee ./BUILD/compile_output.txt
hudakz 5:ace99c9d0e4e 126
hudakz 7:b567983e76f4 127 # Checks for a binary built by Mbed CLI.
hudakz 7:b567983e76f4 128 RESULT=$(grep "Elf2Bin" ./BUILD/compile_output.txt)
hudakz 7:b567983e76f4 129
hudakz 7:b567983e76f4 130 # If the compilation succeeded (a binary exists) flash the target MCU with the resulted binary file.
hudakz 7:b567983e76f4 131 if [ "${RESULT}" != "" ]
hudakz 5:ace99c9d0e4e 132 then
hudakz 7:b567983e76f4 133 # Uncomment the following lines if you want to build a "hex" file for Flash Magic.
hudakz 7:b567983e76f4 134 #if [ "${MCU}" == "LPC1768DBG" ]
hudakz 7:b567983e76f4 135 #then
hudakz 7:b567983e76f4 136 # ${GCC_ARM_PATH}/bin/arm-none-eabi-objcopy -I binary -O ihex ./BUILD/${MCU}/GCC_ARM-${PROFILE}/${PROJ_NAME}.bin ./BUILD/${MCU}/GCC_ARM-${PROFILE}/${PROJ_NAME}.hex
hudakz 7:b567983e76f4 137 #fi
hudakz 7:b567983e76f4 138
hudakz 7:b567983e76f4 139 # If the "all" or "-f" option was selected choose the right tool and configuration.
hudakz 7:b567983e76f4 140 if [ "${FLASH}" == "-f" ]
hudakz 5:ace99c9d0e4e 141 then
hudakz 7:b567983e76f4 142 case ${MCU} in
hudakz 7:b567983e76f4 143 # Targets supported by pyOCD
hudakz 7:b567983e76f4 144 LPC1768|LPC1768DBG)
hudakz 7:b567983e76f4 145 MCU_CFG="pyOCD"
hudakz 7:b567983e76f4 146 ;;
hudakz 7:b567983e76f4 147 # Targets supported by OpenOCD.
hudakz 7:b567983e76f4 148 # Configure OpenOCD according to the selected target.
hudakz 7:b567983e76f4 149 BLUEPILL|MAPLE_MINI|NUCLEO_F103RB|STM32F103RC|STM32F103VE)
hudakz 7:b567983e76f4 150 MCU_CFG="/usr/local/share/openocd/scripts/board/st_nucleo_f103rb.cfg"
hudakz 7:b567983e76f4 151 ;;
hudakz 7:b567983e76f4 152 NUCLEO_F411RE|NUCLEO_F446RE|STM32F407VE)
hudakz 7:b567983e76f4 153 MCU_CFG="/usr/local/share/openocd/scripts/board/st_nucleo_f4.cfg"
hudakz 7:b567983e76f4 154 ;;
hudakz 7:b567983e76f4 155 NUCLEO_F767ZI)
hudakz 7:b567983e76f4 156 MCU_CFG="/usr/local/share/openocd/scripts/board/stm32f7discovery.cfg"
hudakz 7:b567983e76f4 157 ;;
hudakz 7:b567983e76f4 158 # Warn when flashing of selected target MCU is not supported.
hudakz 5:ace99c9d0e4e 159 *)
hudakz 7:b567983e76f4 160 MCU_CFG="not_supported"
hudakz 7:b567983e76f4 161 echo "No support to flash "${MCU}
hudakz 7:b567983e76f4 162 ;;
hudakz 7:b567983e76f4 163 esac
hudakz 7:b567983e76f4 164
hudakz 7:b567983e76f4 165 # When the target MCU is supported flash the target MCU with the binary code.
hudakz 7:b567983e76f4 166 if [ "$MCU_CFG" != "not_supported" ]
hudakz 7:b567983e76f4 167 then
hudakz 7:b567983e76f4 168 echo "Flashing the "${MCU}" ..."
hudakz 7:b567983e76f4 169 case ${MCU_CFG} in
hudakz 7:b567983e76f4 170 # Use pyOCD to flash the target when port was specified.
hudakz 7:b567983e76f4 171 pyOCD)
hudakz 7:b567983e76f4 172 if [ "$PORT" == "/dev/ttyACM0" ]
hudakz 7:b567983e76f4 173 then
hudakz 7:b567983e76f4 174 # Use pyOCD to flash the target when port was specified.
hudakz 7:b567983e76f4 175 ~/.local/bin/pyocd-flashtool -t lpc1768 ./BUILD/${MCU}/GCC_ARM-${PROFILE}/${PROJ_NAME}.bin
hudakz 7:b567983e76f4 176 else
hudakz 7:b567983e76f4 177 # Use "lpc2isp" otherwise.
hudakz 7:b567983e76f4 178 lpc21isp -bin ./BUILD/${MCU}/GCC_ARM-${PROFILE}/${PROJ_NAME}.bin ${PORT} 115200 96000
hudakz 7:b567983e76f4 179 fi
hudakz 7:b567983e76f4 180 ;;
hudakz 7:b567983e76f4 181 # Use OpenOCD to flash the target MCU
hudakz 7:b567983e76f4 182 *)
hudakz 7:b567983e76f4 183 openocd -f ${MCU_CFG} -c """program ./BUILD/${MCU}/GCC_ARM-${PROFILE}/${PROJ_NAME}.elf verify reset exit"""
hudakz 7:b567983e76f4 184 ;;
hudakz 7:b567983e76f4 185 esac
hudakz 7:b567983e76f4 186 echo "Done."
hudakz 7:b567983e76f4 187 fi
hudakz 7:b567983e76f4 188 fi
hudakz 5:ace99c9d0e4e 189 fi