Runtime Lifecycle
From a runtime perspective, BMGR enforces a fixed sequence: which peripherals are initialized first, which devices are initialized next, and how to obtain the corresponding handles and configurations.
The main entry point is esp_board_manager_init(). Looking at the source implementation, this function first calls esp_board_periph_init_all(), then esp_board_device_init_all(). If device initialization fails, it rolls back and attempts to release any peripherals already initialized. Correspondingly, esp_board_manager_deinit() deinitializes all devices first, then all peripherals.
Key Behaviors
Peripherals initialize first, devices initialize second: Devices typically require a peripheral handle to create an instance. When
esp_board_manager_init()is called, BMGR always executes in peripheral-first, device-second order.Overall traversal order follows YAML declaration order:
esp_board_device_init_all()traverses devices in the order they appear inboard_devices.yaml. Devices withdepends_ondeclarations recursively initialize their dependencies first, regardless of declaration order in YAML.depends_ondeclares initialization dependencies between devices: When a device is configured withdepends_on,esp_board_device_init()recursively initializes the listed dependencies before initializing that device, without requiring manual ordering inboard_devices.yaml. If a dependency has already been initialized through another path (ref_count > 0), it is not re-created. A device may declare multiple dependencies of any type.Deinitialization converges by reference count: Both devices and peripherals maintain an internal reference count (
ref_count). Reinitializing the same object does not create a new instance; it increments the reference count. The resource is only actually released when the count drops to zero.init_skipskips automatic initialization: A device withinit_skipstill appears in the board description and generated output, butesp_board_manager_init()will not initialize it automatically; this is suitable for devices that need to be created at a specific application-determined time.power_ctrl_devicecontrols device power-on sequencing: When a device declarespower_ctrl_device, BMGR triggers a power-on action through the correspondingpower_ctrldevice before initializing this device; a power-off action is triggered during deinitialization.power_ctrl_deviceis a device-to-device reference specifically for power supply control; the referenced device must be of typepower_ctrl. Compared todepends_on,power_ctrl_deviceadditionally triggers power-on and power-off actions and provides the runtime power control APIesp_board_device_power_ctrl(), so its effect is not limited to ensuring initialization order.Using
depends_onandpower_ctrl_devicetogether ensures that even when a device is initialized individually viaesp_board_manager_init_device_by_name(), initialization will not fail due to power supply or other dependency issues.
BMGR’s runtime model does not compress all initialization logic into a single init() call; instead, it organizes the initialization order according to the board description, while preserving runtime behaviors such as reference counting, deferred initialization, inter-device dependencies, and power control.