Hitchhiker's Guide to Printf in Mbed 6

For those who don’t work with Mbed frequently it could take some effort and time (linked with frustration) to figure out which parameters can be configured and what to put into the “mbed_app.json”.

The configuration system is documented at The configuration system - Program setup | Mbed OS 6 Documentation but the info below might help.

  1. Search the actual “mbed-os” (including subfolders) for “mbed_lib.json” files (189 in Mbed OS 6.9.0).

  2. Filter out those related to “test” (139 remain in Mbed OS 6.9.0).

  3. If you are looking for something very specific (target, device etc.) you can easily narrow the list.

  4. For “common options” it’s worth to check:

    mbed-os/drivers/mbed_lib.json
    mbed-os/events/mbed_lib.json
    mbed-os/platform/mbed_lib.json

  5. To set a parameter listed in a “mbed_lib.json” file it is important to know also the name of the associated library. That’s indicated as first field in the “mbed_lib.json” file. In your “mbed_app.json” file first put the library’s name followed by a dot and the parameter’s name. The new value you’d like to use goes after a colon.

    For example, to set the “uart-serial-txbuf-size” which is listed in the “mbed-os/drivers/mbed_lib.json”
    and the “stdio-baud-rate” listed in the “mbed-os/platform/mbed_lib.json” file
    put the following into your “mbed_app.json” file located in the root directory of your project:

{
    "target_overrides": {
        "*": {
            "drivers.uart-serial-txbuf-size": 128,
            "platform.stdio-baud-rate": 115200
        }
    }
}

You can add any number of parameters. The order doesn’t matter. However, make sure they are separated by a comma.
There is also indicated a “help” field for each parameter in the “mbed_lib.json” which provides a description and a “value” showing it’s default value.

You can verify your settings after compilation by checking the “mbed_config.h” file. It is automatically generated and saved to the root directory of your project. Parameters are defined as upper case macros preceded by “MBED_CONF_”.

3 Likes