Compiling your application
mbed compile command to compile your code:
$ mbed compile -t ARM -m K64F Building project mbed-os-program (K64F, GCC_ARM) Compile: aesni.c Compile: blowfish.c Compile: main.cpp ... [SNIP] ... Compile: configuration_store.c Link: mbed-os-program Elf2Bin: mbed-os-program +----------------------------+-------+-------+------+ | Module | .text | .data | .bss | +----------------------------+-------+-------+------+ | Fill | 170 | 0 | 2294 | | Misc | 36282 | 2220 | 2152 | | core/hal | 15396 | 16 | 568 | | core/rtos | 6751 | 24 | 2662 | | features/FEATURE_IPV4 | 96 | 0 | 48 | | frameworks/greentea-client | 912 | 28 | 44 | | frameworks/utest | 3079 | 0 | 732 | | Subtotals | 62686 | 2288 | 8500 | +----------------------------+-------+-------+------+ Allocated Heap: 65540 bytes Allocated Stack: 32768 bytes Total Static RAM memory (data + bss): 10788 bytes Total RAM memory (data + bss + heap + stack): 109096 bytes Total Flash memory (text + data + misc): 66014 bytes Image: BUILD/K64F/GCC_ARM/mbed-os-program.bin
The arguments for compile are:
-m <MCU>selects a target. If
autoparameter is passed to
-m, then Mbed CLI detects the connected target.
-t <TOOLCHAIN>selects a toolchain (of those defined in
mbed_settings.py, see above). The value can be
ARM(Arm Compiler 5),
GCC_ARM(GNU Arm Embedded) or
IAR(IAR Embedded Workbench for Arm).
--source <SOURCE>selects the source directory. The default is
.(the current directory). You can specify multiple source locations, even outside the program tree.
--build <BUILD>selects the build directory. Default:
BUILD/inside your program root. Note:
mbed compileignores the current build directory; creating multiple build directories leads to errors.
--profile <PATH_TO_BUILD_PROFILE>selects a path to a build profile configuration file. Example:
--librarycompiles the code as a static
--no-archivesuppresses the creation of
.a/.arfiles created by
--library, producing many
.ofiles instead. Note: This option does nothing without
--configinspects the runtime compile configuration (see below).
--supportedshows a matrix of the supported targets and toolchains.
--flashflashes/programs a connected target after successful compile.
-cbuilds from scratch, a clean build or rebuild.
-j <jobs>controls the compile processes on your machine. The default value is 0, which infers the number of processes from the number of cores on your machine. You can use
-j 1to trigger a sequential compile of source code.
--verboseshows verbose diagnostic output.
--very_verboseshows very verbose diagnostic output.
You can find the compiled binary, ELF image, memory usage and link statistics in the
BUILD subdirectory of your program.
Compiling static libraries
You can build a static library of your code by adding the
--library argument to
mbed compile. Static libraries are useful when you want to build multiple applications from the same Mbed OS codebase without having to recompile for every application. To achieve this:
- Build a static library for
- Compile multiple applications or tests against the static library:
$ mbed compile -t ARM -m K64F --library --no-archive --source=mbed-os --build=../mbed-os-build Building library mbed-os (K64F, ARM) [...] Completed in: (47.4)s $ mbed compile -t ARM -m K64F --source=mbed-os/TESTS/integration/basic --source=../mbed-os-build --build=../basic-out Building project basic (K64F, ARM) Compile: main.cpp Link: basic Elf2Bin: basic Image: ../basic-out/basic.bin $ mbed compile -t ARM -m K64F --source=mbed-os/TESTS/integration/threaded_blinky --source=../mbed-os-build --build=..\/hreaded_blinky-out Building project threaded_blinky (K64F, ARM) Compile: main.cpp Link: threaded_blinky Elf2Bin: threaded_blinky Image: ../threaded_blinky-out/threaded_blinky.bin
The compile configuration system
The compile configuration system provides a flexible mechanism for configuring the Mbed program, its libraries and the build target.
Inspecting the configuration
You can use
mbed compile --config to view the configuration:
$ mbed compile --config -t GCC_ARM -m K64F
To display more verbose information about the configuration parameters, use
$ mbed compile --config -t GCC_ARM -m K64F -v
It's possible to filter the output of
mbed compile --config by specifying one or more prefixes for the configuration parameters that Mbed CLI displays. For example, to display only the configuration defined by the targets:
$ mbed compile --config -t GCC_ARM -m K64F --prefix target
You may use
--prefix more than once. To display only the application and target configuration, use two
$ mbed compile --config -t GCC_ARM -m K64F --prefix target --prefix app
You can specify macros in your command-line using the -D option. For example:
$ mbed compile -t GCC_ARM -m K64F -c -DUVISOR_PRESENT
Compile in debug mode
To compile in debug mode (as opposed to the default develop mode), use
--profile mbed-os/tools/profiles/debug.json in the compile command-line:
$ mbed compile -t GCC_ARM -m K64F --profile mbed-os/tools/profiles/debug.json
Tip: If you have files that you want to compile only in debug mode, put them in a directory called
TARGET_DEBUG at any level of your tree (then use
--profile as explained above).
Automate toolchain and target selection
mbed target <target> and
mbed toolchain <toolchain>, you can set the default target and toolchain for your program. You won't have to specify these every time you compile or generate IDE project files.
You can also use
mbed target detect, which detects the connected target board and uses it as a parameter to every subsequent compile and export.
Update programs and libraries
You can update programs and libraries on your local machine so that they pull in changes from the remote sources (Git or Mercurial).
As with any Mbed CLI command,
mbed update uses the current directory as a working context. Before calling
mbed update, you should change your working directory to the one you want to update. For example, if you're updating
cd mbed-os before you begin updating.
Tip: Synchronizing library references: Before triggering an update, you may want to synchronize any changes that you've made to the program structure by running
mbed sync, which updates the necessary library references and removes the invalid ones.
Protect against overwriting local changes
The update command fails if there are changes in your program or library that
mbed update could overwrite. This is by design. Mbed CLI does not run operations that would result in overwriting uncommitted local changes. If you get an error, take care of your local changes (commit or use one of the options below), and then rerun