Add Machine Learning to a New or Existing Project#

This guide shows how to add a machine learning model to a Simplicity Studio project using the ML Model (ml_model) component. You will enable the AI/ML SDK extension, install the component, point it at a .tflite file in an .mlconf file, and confirm the generated headers.

The steps below use an Empty C++ project as the starting point. To add a model to an existing project, skip Step 1 and open your project's .slcp file instead.

Application code that calls the model APIs must be written in C++. If you are starting with a predominantly C application, see Interfacing with C Code.

For inference code after the model is in the project, see Machine Learning on Silicon Labs Devices from Scratch. For more than one model, see Multiple-Model Support.

Prerequisites#

  • Simplicity Studio installed (screenshots from Studio 2234)

  • Simplicity SDK Suite installed (e.g., v2026.6.0)

  • A target board or platform selected in your workspace

  • A .tflite model file on your local machine

  • The AI/ML extension enabled in your workspace

Procedure#

Step 1: Create an Empty C++ Project#

  1. Open Simplicity Studio and go to the PROJECTS view.

  2. Open the Example Projects & Demos tab.

  3. Search for empty_cpp.

  4. Select Platform - Empty C++ Example and click CREATE.

The empty C++ template is a good starting point when you want to add components yourself.

Empty C++ project creationEmpty C++ project creation


Step 2: Open the Software Components Tab#

  1. In Project Explorer, open your project (for example empty_cpp).

  2. Open the project .slcp file.

  3. Switch to the SOFTWARE COMPONENTS tab.

From here you can browse and install components, including the Silicon Labs AI/ML stack.

Open Software Components tabOpen Software Components tab


Step 3: Enable the AI/ML SDK Extension#

  1. Search for ml_model.

  2. Click on Silicon Labs AI/ML v3.x.x and then click on Enable Extension to enable Silicon Labs AI/ML extension.

Enable AI/ML SDK extensionEnable AI/ML SDK extension


Step 4: Install the ML Model Component#

  1. With ml_model still in the search bar, Expand Silicon Labs AI/MLMachine Learning and select ML Model

  2. Click on Install to install the ML Model component and Create A Component Instance dialog pops up.

Install ML Model componentInstall ML Model component


Step 5: Name the Component Instance#

When you click Install, Studio prompts you to create an instance:

  1. Enter a name in INSTANCE NAME (for example keyword_spotting or blink). Use only valid C/POSIX filename characters — this name ends up in generated #define macros and handle names such as sl_ml_keyword_spotting_model_handle.

  2. Click Done. ML Model component is now installed and and a new instance is created.

Create ML Model component instanceCreate ML Model component instance

NOTE: Each .tflite model requires its own ML Model component instance. After the ML Model component is installed, add another instance with a different name (for example kws and blink) and repeat Steps 5–7 for each additional model. For initialization and runtime behavior with multiple models, see Multiple-Model Support.


Step 6: Dismiss the Initial Generation Error#

Studio should confirm the component was added. You may also see a generation error like this:

Failed to generate setup apack_aiml.mvp-compiler

ERROR:root:compile: pass a .tflite path as the model argument, or set "model" in your YAML/mlconf config.

This error is expected because the project has not yet been configured with a .tflite file path. Dismiss the dialog and proceed to the next step.

Ignore generation error and proceedIgnore generation error and proceed


Step 7: Configure the .mlconf File#

  1. In Project Explorer, open config/tflite/ and double-click your .mlconf file (for example keyword_spotting.mlconf).

  2. Set model: to the absolute path of your .tflite file:

    model: C:\Users\<username>\Desktop\keyword_spotting_on_off_v2.tflite
  3. Save the file. Studio regenerates the project automatically.

Configure mlconf file with tflite model pathConfigure mlconf file with tflite model path

NOTE: A project with more than one model has one .mlconf file per instance under config/tflite/ (for example keyword_spotting.mlconf and blink.mlconf). Set model: in each file to the .tflite path for that instance.


Step 8: Verify Generated Files#

After generation finishes:

  1. Expand the autogen/ folder in Project Explorer.

  2. Check for new headers named after your model, for example:

    • keyword_spotting_on_off_v2_generated.hpp

    • sl_ml_model_keyword_spotting_on_off_v2.h

  3. On the SOFTWARE COMPONENTS tab, confirm your ML Model instance shows a green checkmark.

Generated files after mlconf configurationGenerated files after mlconf configuration

At project generation, Simplicity Studio runs the MVP Compiler on each model and produces embedded artifacts in autogen/, including:

File

Purpose

sl_ml_model_<instance>.h

Pre-built handle for the model (for example sl_ml_blink_model_handle)

<instance>_generated.hpp

Model flatbuffer, opcode resolver, and statically allocated tensor buffers

<instance>_generated_parameters.h

Model-specific parameters when enabled in .mlconf (used by audio models — see Feature Generators)

The ML Model component includes the TensorFlow Lite Micro runtime. No automatic model initialization runs at system startup — the application loads the model when it is ready to run inference.

For microphone-based models, also add the Audio Feature Generator (fe_audio) component. See Feature Generators.

NOTE: With multiple model instances, autogen/ contains a separate generated header and handle for each instance (for example sl_ml_model_kws.h and sl_ml_model_blink.h).


Summary#

Step

Action

1

Create a Platform - Empty C++ Example project (skip for existing projects)

2

Open SOFTWARE COMPONENTS via the project .slcp file

3

Enable the Silicon Labs AI/ML SDK extension

4

Install the ML Model component

5

Name the component instance (for example keyword_spotting); repeat Steps 5–7 for each additional model

6

Dismiss the generation error (no .tflite yet)

7

Set model: in the .mlconf file under config/tflite/

8

Confirm generated headers in autogen/

Additional Software Components and C++ Build Settings#

Note: Skip this section for Series 2 devices. It applies to SiWx917 projects only.

  1. Ensure the following components are installed in your project.

    • WiseConnect SDK > Device > Si91X > MCU > Service > Power Manager > Sleep Timer for Si91x

    • Platform > Peripheral > Common Headers

    Add Sleep Timer ComponentAdd Sleep Timer Component

    Add Common Headers ComponentAdd Common Headers Component

  2. Update your C++ build settings as follows:

    • In the C preprocessor defines, add: SUPPORT_CPLUSPLUS.

    • In GNU ARM C++ Compiler > Miscellaneous settings, add: -mfp16-format=ieee.

    Update C++ Build SettingsUpdate C++ Build Settings GNU ARM C++ Compiler Miscellaneous SettingsGNU ARM C++ Compiler Miscellaneous Settings

    Alternate method:

    You can also add these settings directly to your project's .slcp file:

    • Open the .slcp file in a text editor.

    • Add SUPPORT_CPLUSPLUS to the define section for C preprocessor defines. For example:

      define:
        - name: SUPPORT_CPLUSPLUS
          value: 1
    • Add -mfp16-format=ieee to the toolchain_settings section for C++ compiler flags, for example:

      toolchain_settings:
        - option: gcc_compiler_option
          value: -mfp16-format=ieee
    • Save the file and regenerate your project to apply the changes.

Troubleshooting#

Issue

What to try

Failed to generate setup apack_aiml.mvp-compiler

Set model: in .mlconf to a valid .tflite absolute path, then regenerate.

ml_model not found in search

Enable the AI/ML SDK extension (Step 3).

Invalid instance name

Use letters, numbers, and underscores only.

Nothing new in autogen/

Double-check the .tflite path is absolute and saved. Look at Notifications for errors.

Next Steps#

Include the generated headers in your application and follow Machine Learning on Silicon Labs Devices from Scratch to initialize the model and run inference.

Addendum: Interfacing with C Code#

If your project is written in C rather than C++, place the code interfacing with the model APIs into a separate file that exports a C API through an interface header. For this example, a filename app_ml.cpp is assumed that implements the function ml_process_action() with the same content as in the from-scratch guide.

app_ml.h

#ifdef __cplusplus
extern "C" {
#endif

void ml_process_action(void);

#ifdef __cplusplus
}
#endif

app_ml.cpp#

#include "app_ml.h"
#include "sl_ml_model_blink.h"
#include "sl_ml_tflite_micro_model.h"

extern "C" void ml_process_action(void)
{
    /* Call sl_ml_model_run() as shown in the from-scratch guide.
       Call sl_ml_model_init() from app_init(). */
}

app.c#

#include "app_ml.h"
// ...
void app_process_action(void)
{
    ml_process_action();
}

Addendum: Series 2 to SiWx917 (and vice versa) App Conversion#

If you need to port an application between Series 2 and SiWx917, follow the Additional Software Components and C++ Build Settings section for SiWx917 when required. The ML Model (ml_model) component and sl_ml_model_init() / sl_ml_model_run() workflow is the same on supported boards. Regenerate the project after changing the target device.