Download and build the sample application

Install Arm toolchain and Mbed CLI

  1. Download Arm cross compilation toolchain. Select the correct toolchain for the OS that your computer is running. For Windows users, if you have already set up the Linux virtual environment, install the toolchain there.

  2. To build and deploy the application, we will use the Mbed CLI. We recommend that you install Mbed CLI with our installer. If you need more customization, you can perform a manual install. Although this is not recommended.

    If you do not already have Mbed CLI installed, download the installer:

    Mac installer

  3. After Mbed CLI is installed, tell Mbed where to find the Arm embedded toolchain.

    mbed config -G GCC_ARM_PATH <path_to_your_arm_toolchain>/bin
    Important: We recommend running the following commands from inside the Mbed CLI terminal that gets launched with the Mbed CLI Application. This is because it will be much quicker to set up, because it resolves all your environment dependencies automatically.

    Mbed CLI chip image

Build and compile micro speech example

Navigate to the directory where you keep code projects. Run the following command to download TensorFlow Lite source code.

git clone

While you wait for the project to download, let’s explore the project files on GitHub and learn how this TensorFlow Lite for Microcontrollers example works.

The code samples audio from the microphone on the STM32F7. The audio is run through a Fast Fourier transform to create a spectrogram. The spectrogram is then fed into a pre-trained machine learning model. The model uses a convolutional neural network to identify whether the sample represents either the command “yes” or “no”, silence, or an unknown input. We will explore how this works in more detail later in the guide.

Here are descriptions of some interesting source files:

After the project has downloaded, you can run the following commands to navigate into the project directory and build it:

cd tensorflow
make -f tensorflow/lite/micro/tools/make/Makefile TARGET=mbed TAGS="disco_f746ng" generate_micro_speech_mbed_project 

This will create a folder in tensorflow/lite/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed that contains the source and header files, Mbed driver files, and a README. 

cd tensorflow/lite/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed
mbed config root .
mbed deploy

TensorFlow requires C++ 11, so you will need to update your profiles to reflect this. Here is a short Python command that does that. Run it from the command line:

python -c 'import fileinput, glob;
for filename in glob.glob("mbed-os/tools/profiles/*.json"):
  for line in fileinput.input(filename, inplace=True):
    print line.replace("\"-std=gnu++98\"","\"-std=c++11\", \"-fpermissive\"")'

After that setting is updated, you can compile:

mbed compile -m DISCO_F746NG -t GCC_ARM
Previous Next