-
Notifications
You must be signed in to change notification settings - Fork 9
Project Configuration
Here's how to initially set up mbed-cmake for your processor and compile a hello world. You only need to do this once when you initially create a project!
Before doing this, follow the first steps of the Getting Started guide, then follow the steps on the Toolchain Setup page to install the GNU Arm toolchain on your machine.
- Install the dependencies for MBed OS's build system. You should be able to do this with
python3 -m pip install -r mbed-cmake/mbed-src/requirements.txt
, though this may not work on all Python versions (On Windows you will need to replacepython3
withpython
). If it doesn't work, you can will need to open the requirements file and read the list of dependencies and install them manually. - If you need, set up your mbedignore by editing
mbed-cmake/mbed-src/.mbedignore
. Info about how to use this file can be found here.- A template mbedignore has been provided for you, you can edit this or create a completely new one.
- It is highly recommended to add files and directories that you don't need to your mbedignore as this speeds up the build significantly. You can always unignore them later!
- If you need, configure MBed OS's preferences by editing
mbed-src/mbed_app.json
. Info about these settings can be found here. - Find the correct MBed name for your target board or processor. How to do this varies somewhat -- if you have an MBed board you can find your board here and look in the top right for the target name. If you are using an MBed-enabled processor on your own board, you will usually want to use the name of the dev board for that processor, though sometimes the processor name itself will work.
- Configure mbed-cmake by running
python3 mbed-cmake/configure_for_target.py <target name>
. This will activate MBed OS's build system and generate the configuration files needed by CMake. - Create a build directory (don't build in the source code!) and cd into it. Then run CMake for the initial configuration:
cmake <path/to/source/dir>
. As long as your toolchain is installed properly, CMake will configure the project for building.- On Windows, if using mingw32-make use
cmake "-GMinGW32 Makefiles <path/to/source/dir>"
as your initial CMake command, and then usemingw32-make
in place ofmake
in all commands.
- On Windows, if using mingw32-make use
- We've included a hello world program in the project as-is. You can compile it (and MBed OS itself) with:
make -j2 hello_world
.
Done! Your hello world program should build as a .bin file in your source dir. To set up automatic uploading, refer to the Upload Methods section for instructions on how to configure this feature.
Once a project has been initially configured following the steps above, setup on new other is much easier. All that you need to do after cloning the project is install the toolchain and run the CMake configuration (see Step 6 above).
If you change your MBed ignore or config files, or if you want to switch to a different MBed target, then you will need to rerun the initial configuration process. First, follow the initial configuration guide through step 6 to regenerate the config files. Then, you need to delete and recreate your CMake build directory. This is very important, if you don't do this it can lead to your code being built with the wrong flags for your processor. Finally, you can create a new CMake build directory and compile your code.