Arm Mbed OS support forum

CMake is now part of Mbed OS

Since we introduced the new Mbed Tools in August, we made progress with CMake to decrease building time of Mbed OS. CMake is part of Mbed OS master branch for all of you to try and provide feedback.

CMake and the new Mbed Tools are under active development. We will be adding additional targets and features to our CMake support in the following weeks.

We recommend using the latest Mbed Tools and CMake as they contain important bugfixes.

Mbed OS libraries

Application project executables can be linked with one of two main libraries mbed-os or mbed-baremetal and optional mbed- prefixed libraries depending on the additional features required by an application.

Targets supported

  • DISCO_L475VG_IOT01A
  • K64F
  • K66F
  • NRF52840_DK
  • NUCLEO_F303K8
  • NUCLEO_F401RE
  • WIO_3G

Toolchains supported

GCC Arm and ARMClang are supported.

Examples supported

Supported examples can be identified by the presence of a top level CMakeLists.txt input source file on the example’s development branch.

Additional details

For more details, please read the CMake support README and Mbed Tools how-to README.

We will add detailed public documentation soon.

12 Likes

That’s great news, thanks @Kojto for sharing that!

Quick question: what about bootloader and Pelion compatibility?

This is one of our upcoming tasks to look at the bootloader.

2 Likes

Good to hear! Thanks :slight_smile:

Hi,
I am trying to play with the new build system, but I can’t make it work.

I have installed mbed-tools From a python (3.8) virtual environment and cloned the blinky examples:

(mbed) $ mbedtools --version
3.5.0
(mbed) $ mbedtools clone mbed-os-example-blinky blinky
[...]
(mbed) $ cd blinky/mbed-os
(mbed) blinky/mbed-os$ git describe
mbed-os-6.5.0
(mbed) blinky/mbed-os$ cd ..
(mbed) blinky$ mbedtools build -t GCC_ARM -m NUCLEO_F303K8
Configuring project and generating build system...
-- Configuring done
CMake Error at CMakeLists.txt:14 (add_executable):
  Cannot find source file:

    /home/ddouard/perso/mbed/examples/blinky/mbed-os/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303x8/TARGET_NUCLEO_F303K8/system_clock.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .ispc


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
ERROR: CMake invocation failed!

More information may be available by using the command line option '-v'.

I’ve tested with several other nucleo targets an I get similar results (not always the same file that cannot be found however).

The cloned version of the blinky example is at revision 2a95fcd8 (aka tagged version for mbed 6.5.0) and I’m using cmake 3.19.1 (downloaded from cmake.org) on a Debian bullseye machine, with arm-none-eabi-gcc from debian, aka version 8.3.1.

Did I miss something?

Ok the list of supported targets is a bit confusing. According to the top level message, the NUCLEO_F303K8 is expected to be supported, but the doc (https://os.mbed.com/docs/mbed-os/v6.5/build-tools/use.html) only lists 3 supported boards ( K64F , DISCO_L475VG_IOT01A and NRF52840_DK ).

And indeed the compilation work perfectly with the K64F target (and as expected is waaaay faster than the cli v1 build system).

STM targets are now available in master, but not in 6.5.0.

Cool. Seems there is a bug in targets/TARGET_STM/TARGET_STM32F3/CMakeLists.txt:

 mbedtools build -t GCC_ARM -m NUCLEO_F303K8
Configuring project and generating build system...
CMake Error at mbed-os/targets/TARGET_STM/TARGET_STM32F3/CMakeLists.txt:7 (add_subdirectory):
  add_subdirectory given source "TARGET_TARGET_STM32F303x8" which is not an
  existing directory.

(using mbed-os g6d89500dfe)

and sure enough:

head -n 10 mbed-os/targets/TARGET_STM/TARGET_STM32F3/CMakeLists.txt 
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

if("STM32F302x8" IN_LIST MBED_TARGET_LABELS)
    add_subdirectory(TARGET_STM32F302x8)
elseif("STM32F303x8" IN_LIST MBED_TARGET_LABELS)
    add_subdirectory(TARGET_TARGET_STM32F303x8)
elseif("STM32F303xC" IN_LIST MBED_TARGET_LABELS)
    add_subdirectory(TARGET_STM32F303xC)
elseif("STM32F303xE" IN_LIST MBED_TARGET_LABELS)

seems a bit “odd” :slight_smile:

Ahh much better (with a fixed TARGET_STM32F3/CMakeLists.txt):

mbedtools build -t GCC_ARM -m NUCLEO_F303K8
Configuring project and generating build system...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ddouard/perso/mbed/examples/blinky/cmake_build
Building Mbed project...
[228/228] Linking CXX executable mbed-os-example-blinky
-- built: /home/ddouard/perso/mbed/examples/blinky/cmake_build/mbed-os-example-blinky.bin
-- built: /home/ddouard/perso/mbed/examples/blinky/cmake_build/mbed-os-example-blinky.hex
| Module           |         .text |     .data |        .bss |
|------------------|---------------|-----------|-------------|
| [fill]           |       48(+48) |     0(+0) |     15(+15) |
| [lib]/c_nano.a   |   3724(+3724) | 100(+100) |     12(+12) |
| [lib]/gcc.a      |     772(+772) |     0(+0) |       0(+0) |
| [lib]/misc       |     248(+248) |     4(+4) |     28(+28) |
| main.cpp.obj     |       48(+48) |     0(+0) |       0(+0) |
| mbed-os/cmsis    |   6580(+6580) | 168(+168) | 5953(+5953) |
| mbed-os/drivers  |       70(+70) |     0(+0) |       0(+0) |
| mbed-os/hal      |   1348(+1348) |     4(+4) |     66(+66) |
| mbed-os/platform |   4274(+4274) | 260(+260) |   348(+348) |
| mbed-os/rtos     |       28(+28) |     0(+0) |       0(+0) |
| mbed-os/targets  |   6832(+6832) |     8(+8) |   522(+522) |
| Subtotals        | 23972(+23972) | 544(+544) | 6944(+6944) |
Total Static RAM memory (data + bss): 7488(+7488) bytes
Total Flash memory (text + data): 24516(+24516) bytes

If the issue is present in master on mbed-os, you can raise an issue on github or make a PR with a fix, the team will greatly appreciate it :slight_smile:

ok ok, here it is https://github.com/ARMmbed/mbed-os/pull/13958 :slight_smile:

3 Likes

Thanks @douardda. We will integrate the fix asap. If you find anything else, create an issue or pull request (much appreciated).