Hello! I’m working on a project that requires several MCUs each with a different firmware and in order to save space I want to use a shared instance of the Mbed OS 6 library. Although I couldn’t find it anywhere in the online documentation apparently Mbed CLI 2 (mbed-tools) also has the option to use a shared copy of Mbed OS when the --mbed-os-path
option is added to the compile
or configure
commands.
To test that feature I first imported Mbed OS (v6.9):
C:\Users\Dani\Documents> mbed-tools import mbed-os
Then I created a new project without mbed-os adding the --create-only
option.
C:\Users\Dani\Documents> mbed-tools new --create-only .\test
Next I tried compiling the project with:
C:\Users\Dani\Documents\test> mbed-tools compile -t GCC_ARM -m NUCLEO_F103RB --mbed-os-path "C:/Users/Dani/Documents/mbed-os"
And got the following error:
CMake Error at CMakeLists.txt:10 (include):
include could not find requested file:
C:/Users/Dani/Documents/test/mbed-os/tools/cmake/app.cmake
Which of course makes sense because that file path is wrong, nevertheless I was expecting the --mbed-os-path
to change that automatically.
Next I edited the CMakeLists.txt
file in the root of the test
project, replacing this line:
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
With:
set(MBED_PATH "C:/Users/Dani/Documents/mbed-os" CACHE INTERNAL "")
Trying again the same command to compile I got a new error:
CMake Error at CMakeLists.txt:12 (add_subdirectory):
add_subdirectory not given a binary directory but the given source
directory "C:/Users/Dani/Documents/mbed-os" is not a subdirectory of
"C:/Users/Dani/Documents/test". When specifying an out-of-tree source a
binary directory must be explicitly specified.
So I provided a build directory to add_subdirectory( ):
add_subdirectory(${MBED_PATH} "C:/Users/Dani/Documents/mbed-os/build")
Only this way I managed to compile successfully the project.
Next I tried to call:
C:\Users\Dani\Documents\test> mbed-tools compile -t GCC_ARM -m NUCLEO_F103RB
And got:
ERROR: Mbed OS was not found due to the following error: The mbed-os directory does not exist.
Very weird, because the argument of --mbed-os-path
seems to be ignored and I was overwriting the file anyway, however if not indicated the compiler complains about the missing library.
I tried to configure the project with an apparent success:
C:\Users\Dani\Documents\test> mbed-tools configure -t GCC_ARM -m NUCLEO_F103RB -- mbed-os-path "C:/Users/Dani/Documents/mbed-os"
mbed_config.cmake has been generated and written to 'C:\Users\Dani\Documents\test\cmake_build\NUCLEO_F103RB\develop\GCC_ARM\mbed_config.cmake'
However typing:
mbed-tools compile
Outputs:
Error: Both --toolchain and --mbed-target arguments are required when using the compile subcommand.
So to sum up, I only managed to compile the project referencing an external copy of mbed-os
by overwriting the CMakeLists.txt
file. The configure
command seems to do nothing (not even in a simple sketch with a local copy of mbed-os
). I want to know how to properly configure my project so I can reference an external copy of mbed-os
, ideally placing all the compilation objects in the build directory of the project I’m compiling, leaving the mbed-os
directory untouched so it can be referenced by other projects.
Thanks in advance.