Skip to content

MbedOS configuration

JohnK1987 edited this page Feb 9, 2024 · 15 revisions

Configuration via .json and .json5 files

Is good for...

//TODO

(Note: Legacy Mbed configs have a .json extension. Mbed CE moved to .json5 mainly for comment support)

Configuration via .cmake files

In top level CMakeLists.txt there has to be the line

target_link_libraries(YourApplication mbed-os)

via this line you can switch between full profile mbed-os to mbed-baremetal profile or add components what are not part of that profile in default. For example USB is component what is not included in full MbedOS profile so you have to add it like this

target_link_libraries(YourApplication mbed-os mbed-usb)

Another example is block devices. These were split out from the main Mbed library, and have to be linked separately. For example, if you need FlashIAPBlockDevice.h, you have to link mbed-storage-flashiap, like this:

target_link_libraries(YourApplication mbed-os mbed-storage-flashiap)

Mbed Libraries

USB capability:

  • mbed-usb contains majority of USB functionality (can be also manually enabled in baremetal profile)
  • mbed-usb-msd provides USBMSD.h (USB Mass Storage Device support)
  • mbed-usb-cdc-ecm provides USBCDC_ECM.h (Simulated USB Ethernet adapter support) (RTOS required, not compatible with baremetal)

Network capability (TCP/IP, UDP):

  • mbed-netsocket will pull in the default network stack and socket libraries. Refer to this doc page for more information about Mbed's network stack options.

Storage capability:

  • mbed-storage (can be also manually enabled in baremetal profile)
  • mbed-storage-blockdevice provides non-driver-related block device headers
  • mbed-storage-dataflash provides DataFlashBlockDevice.h (Block device for DataFlash interface SPI flashes)
  • mbed-storage-flashiap provides FlashIAPBlockDevice.h (Block device which uses MCU flash as storage)
  • mbed-storage-i2cee provides I2CEEBlockDevice.h (Block device for I2C EEPROMs)
  • mbed-storage-ospif provides OSPIFBlockDevice.h (Block device for octal SPI SFDP flashes)
  • mbed-storage-qspif provides QSPIFBlockDevice.h (Block device for quad SPI SFDP flashes)
  • mbed-storage-spif provides SPIFBlockDevice.h (Block device for regular SPI SFDP flashes)
  • mbed-storage-sd provides SDBlockDevice.h (Block device for (micro)SD/SDHC cards). Now supports asynchronous (DMA) SPI in Mbed CE!
  • mbed-storage-spinand provides SPINANDBlockDevice.h (block device for QSPI NAND flashes).

*Note: Currently, all of the driver block devices require their matching COMPONENT to be enabled for your target. Out of the box, this will only be true if the chip's dev board actually has that component; e.g. only dev boards with an SD card slot will enable COMPONENT_SD and make the mbed-storage-sd target available.

To change this, you will need to add a line like the following to your target_overrides in mbed_app.json:

"target.components_add" : ["DATAFLASH", "FLASHIAP", "SD"],

This will enable the component and activate the matching library.

TODO: file system block devices, KVStore

MbedTLS capability:

mbed-mbedtls

//TODO

Libraries In Your Application

If you need to make a library within your own code, you can use CMake's add_library() command. This library can then be linked to multiple different applications, and the code inside only gets compiled once.

Example:

add_library(SomeLibrary STATIC LibSource1.cpp LibSource2.cpp)
target_include_directories(SomeLibrary INTERFACE .)
target_link_libraries(SomeLibrary PUBLIC mbed-core-flags) # This is needed so that the library can access Mbed includes


add_executable(MyMbedOSExe)
target_link_libraries(MyMbedOSExe SomeLibrary mbed-os)
mbed_set_post_build(MyMbedOSExe)

# another alternative for bare metal profile
add_executable(MyMbedBaremetalExe)
target_link_libraries(MyMbedBaremetalExee SomeLibrary mbed-baremetal)
mbed_set_post_build(MyMbedBaremetalExe)

Note that the library is linked to mbed-core-flags, not mbed-os. This is a limitation of CMake object libraries; only the executable should be linked to mbed-os, NOT the libraries. Note that if the library needs to use RTOS features, it should like to mbed-rtos-flags as well to get access to the RTOS.