Skip to content

Project Configuration

Jamie Smith edited this page Jul 15, 2020 · 12 revisions

Initial 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.

  1. Install the dependencies for MBed OS's build system. You should be able to do this with python3 -m pip install --user mbed-src/requirements.txt, though this may not work on all Python versions. If it doesn't work, you can will need to open the file and read the list of dependencies and install them manually.
  2. Set up your mbedignore by editing 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!
  3. Configure MBed OS's preferences by editing mbed-src/mbed_app.json. Info about these settings can be found here.
  4. 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.
  5. Configure mbed-cmake by running python3 configure_for_target.py <target name>. This will activate MBed OS's build system and generate the configuration files needed by CMake.
  6. 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 use mingw32-make in place of make in all commands.
  7. 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.

Subsequent Setup

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).

Rerunning Configuration

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.

Clone this wiki locally